@vx/gradient

Inspired by: https://dribbble.com/shots/3380672-Sketch-Gradients-Freebie

Example

import { AreaClosed } from '@vx/shape';
import { GradientPinkBlue } from '@vx/gradient';

const GradientArea = () => {
  return (
    <svg>
      <GradientPinkBlue id="gradient" />
      <AreaClosed fill="url('#gradient')" />
    </svg>
  );
};

The Definition Caveat

Like patterns, gradients are "defined." When you render <GradientPinkBlue />, it's rendering a <linearGradient/> element inside a <def> in the SVG.

It's often better to think of these as variable definitions rather than true DOM elements. When you use fill="url('#gradient')" you're referencing the gradient's id: gradient.

Make your own!

In addition to the preset linear gradients, you can make any linear or radial gradient like so:

import { LinearGradient, RadialGradient } from '@vx/gradient';

<LinearGradient from="#a18cd1" to="#fbc2eb" />;
<RadialGradient from="#a18cd1" to="#fbc2eb" />;

Installation

npm install --save @vx/gradient

Examples

Components

APIs

#<LinearGradient />

# LinearGradient.idstringrequired

Unique id for the gradient. Should be unique across all page elements.

# LinearGradient.childrenReactNodeoptional

Override of linearGradient children.

# LinearGradient.fromstring | undefinedoptional

Start color of gradient.

# LinearGradient.fromOffsetstring | number | undefinedoptional

Number or percent defining the where the 'from' starting color is placed along the gradient.

Default 0%

# LinearGradient.fromOpacitystring | number | undefinedoptional

Opacity of the 'from' starting color.

Default 1

# LinearGradient.rotatestring | number | undefinedoptional

Rotation to apply to gradient.

# LinearGradient.tostring | undefinedoptional

End color of gradient.

# LinearGradient.toOffsetstring | number | undefinedoptional

Number or percent defining the where the 'to' ending color is placed along the gradient.

Default 100%

# LinearGradient.toOpacitystring | number | undefinedoptional

Opacity of the 'to' ending color.

Default 1

# LinearGradient.transformstring | undefinedoptional

Transform to apply to linearGradient, overrides rotate.

# LinearGradient.verticalboolean | undefinedoptional

(When no x or y values are passed), will orient the gradient vertically instead of horizontally.

Default true

# LinearGradient.x1string | number | undefinedoptional

The x coordinate of the starting point along which the linear gradient is drawn.

# LinearGradient.x2string | number | undefinedoptional

The x coordinate of the ending point along which the linear gradient is drawn.

# LinearGradient.y1string | number | undefinedoptional

The y coordinate of the starting point along which the linear gradient is drawn.

# LinearGradient.y2string | number | undefinedoptional

The y coordinate of the ending point along which the linear gradient is drawn.

#<RadialGradient />

# RadialGradient.childrenReactNodeoptional

Override of linearGradient children.

# RadialGradient.fromstring | number | undefinedoptional

Start color of gradient.

# RadialGradient.fromOffsetstring | number | undefinedoptional

Number or percent defining the where the 'from' starting color is placed along the gradient.

Default 0%

# RadialGradient.fromOpacitystring | number | undefinedoptional

Opacity of the 'from' starting color.

Default 1

# RadialGradient.idstring | undefinedoptional

Unique id for the gradient. Should be unique across all page elements.

# RadialGradient.rotatestring | number | undefinedoptional

Rotation to apply to gradient.

# RadialGradient.tostring | number | undefinedoptional

End color of gradient.

# RadialGradient.toOffsetstring | number | undefinedoptional

Number or percent defining the where the 'to' ending color is placed along the gradient.

Default 100%

# RadialGradient.toOpacitystring | number | undefinedoptional

Opacity of the 'to' ending color.

Default 1

# RadialGradient.transformstring | undefinedoptional

Transform to apply to linearGradient, overrides rotate.

#<GradientDarkgreenGreen />

# GradientDarkgreenGreen.idstringrequired

Unique id for the gradient. Should be unique across all page elements.

# GradientDarkgreenGreen.childrenReactNodeoptional

Override of linearGradient children.

# GradientDarkgreenGreen.fromstring | undefinedoptional

Start color of gradient.

Default #184E86

# GradientDarkgreenGreen.fromOffsetstring | number | undefinedoptional

Number or percent defining the where the 'from' starting color is placed along the gradient.

# GradientDarkgreenGreen.fromOpacitystring | number | undefinedoptional

Opacity of the 'from' starting color.

# GradientDarkgreenGreen.rotatestring | number | undefinedoptional

Rotation to apply to gradient.

# GradientDarkgreenGreen.tostring | undefinedoptional

End color of gradient.

Default #57CA85

# GradientDarkgreenGreen.toOffsetstring | number | undefinedoptional

Number or percent defining the where the 'to' ending color is placed along the gradient.

# GradientDarkgreenGreen.toOpacitystring | number | undefinedoptional

Opacity of the 'to' ending color.

# GradientDarkgreenGreen.transformstring | undefinedoptional

Transform to apply to linearGradient, overrides rotate.

# GradientDarkgreenGreen.verticalboolean | undefinedoptional

(When no x or y values are passed), will orient the gradient vertically instead of horizontally.

# GradientDarkgreenGreen.x1string | number | undefinedoptional

The x coordinate of the starting point along which the linear gradient is drawn.

# GradientDarkgreenGreen.x2string | number | undefinedoptional

The x coordinate of the ending point along which the linear gradient is drawn.

# GradientDarkgreenGreen.y1string | number | undefinedoptional

The y coordinate of the starting point along which the linear gradient is drawn.

# GradientDarkgreenGreen.y2string | number | undefinedoptional

The y coordinate of the ending point along which the linear gradient is drawn.

#<GradientLightgreenGreen />

# GradientLightgreenGreen.idstringrequired

Unique id for the gradient. Should be unique across all page elements.

# GradientLightgreenGreen.childrenReactNodeoptional

Override of linearGradient children.

# GradientLightgreenGreen.fromstring | undefinedoptional

Start color of gradient.

Default #42E695

# GradientLightgreenGreen.fromOffsetstring | number | undefinedoptional

Number or percent defining the where the 'from' starting color is placed along the gradient.

# GradientLightgreenGreen.fromOpacitystring | number | undefinedoptional

Opacity of the 'from' starting color.

# GradientLightgreenGreen.rotatestring | number | undefinedoptional

Rotation to apply to gradient.

# GradientLightgreenGreen.tostring | undefinedoptional

End color of gradient.

Default #3BB2B8

# GradientLightgreenGreen.toOffsetstring | number | undefinedoptional

Number or percent defining the where the 'to' ending color is placed along the gradient.

# GradientLightgreenGreen.toOpacitystring | number | undefinedoptional

Opacity of the 'to' ending color.

# GradientLightgreenGreen.transformstring | undefinedoptional

Transform to apply to linearGradient, overrides rotate.

# GradientLightgreenGreen.verticalboolean | undefinedoptional

(When no x or y values are passed), will orient the gradient vertically instead of horizontally.

# GradientLightgreenGreen.x1string | number | undefinedoptional

The x coordinate of the starting point along which the linear gradient is drawn.

# GradientLightgreenGreen.x2string | number | undefinedoptional

The x coordinate of the ending point along which the linear gradient is drawn.

# GradientLightgreenGreen.y1string | number | undefinedoptional

The y coordinate of the starting point along which the linear gradient is drawn.

# GradientLightgreenGreen.y2string | number | undefinedoptional

The y coordinate of the ending point along which the linear gradient is drawn.

#<GradientOrangeRed />

# GradientOrangeRed.idstringrequired

Unique id for the gradient. Should be unique across all page elements.

# GradientOrangeRed.childrenReactNodeoptional

Override of linearGradient children.

# GradientOrangeRed.fromstring | undefinedoptional

Start color of gradient.

Default #FCE38A

# GradientOrangeRed.fromOffsetstring | number | undefinedoptional

Number or percent defining the where the 'from' starting color is placed along the gradient.

# GradientOrangeRed.fromOpacitystring | number | undefinedoptional

Opacity of the 'from' starting color.

# GradientOrangeRed.rotatestring | number | undefinedoptional

Rotation to apply to gradient.

# GradientOrangeRed.tostring | undefinedoptional

End color of gradient.

Default #F38181

# GradientOrangeRed.toOffsetstring | number | undefinedoptional

Number or percent defining the where the 'to' ending color is placed along the gradient.

# GradientOrangeRed.toOpacitystring | number | undefinedoptional

Opacity of the 'to' ending color.

# GradientOrangeRed.transformstring | undefinedoptional

Transform to apply to linearGradient, overrides rotate.

# GradientOrangeRed.verticalboolean | undefinedoptional

(When no x or y values are passed), will orient the gradient vertically instead of horizontally.

# GradientOrangeRed.x1string | number | undefinedoptional

The x coordinate of the starting point along which the linear gradient is drawn.

# GradientOrangeRed.x2string | number | undefinedoptional

The x coordinate of the ending point along which the linear gradient is drawn.

# GradientOrangeRed.y1string | number | undefinedoptional

The y coordinate of the starting point along which the linear gradient is drawn.

# GradientOrangeRed.y2string | number | undefinedoptional

The y coordinate of the ending point along which the linear gradient is drawn.

#<GradientPinkBlue />

# GradientPinkBlue.idstringrequired

Unique id for the gradient. Should be unique across all page elements.

# GradientPinkBlue.childrenReactNodeoptional

Override of linearGradient children.

# GradientPinkBlue.fromstring | undefinedoptional

Start color of gradient.

Default #F02FC2

# GradientPinkBlue.fromOffsetstring | number | undefinedoptional

Number or percent defining the where the 'from' starting color is placed along the gradient.

# GradientPinkBlue.fromOpacitystring | number | undefinedoptional

Opacity of the 'from' starting color.

# GradientPinkBlue.rotatestring | number | undefinedoptional

Rotation to apply to gradient.

# GradientPinkBlue.tostring | undefinedoptional

End color of gradient.

Default #6094EA

# GradientPinkBlue.toOffsetstring | number | undefinedoptional

Number or percent defining the where the 'to' ending color is placed along the gradient.

# GradientPinkBlue.toOpacitystring | number | undefinedoptional

Opacity of the 'to' ending color.

# GradientPinkBlue.transformstring | undefinedoptional

Transform to apply to linearGradient, overrides rotate.

# GradientPinkBlue.verticalboolean | undefinedoptional

(When no x or y values are passed), will orient the gradient vertically instead of horizontally.

# GradientPinkBlue.x1string | number | undefinedoptional

The x coordinate of the starting point along which the linear gradient is drawn.

# GradientPinkBlue.x2string | number | undefinedoptional

The x coordinate of the ending point along which the linear gradient is drawn.

# GradientPinkBlue.y1string | number | undefinedoptional

The y coordinate of the starting point along which the linear gradient is drawn.

# GradientPinkBlue.y2string | number | undefinedoptional

The y coordinate of the ending point along which the linear gradient is drawn.

#<GradientPinkRed />

# GradientPinkRed.idstringrequired

Unique id for the gradient. Should be unique across all page elements.

# GradientPinkRed.childrenReactNodeoptional

Override of linearGradient children.

# GradientPinkRed.fromstring | undefinedoptional

Start color of gradient.

Default #F54EA2

# GradientPinkRed.fromOffsetstring | number | undefinedoptional

Number or percent defining the where the 'from' starting color is placed along the gradient.

# GradientPinkRed.fromOpacitystring | number | undefinedoptional

Opacity of the 'from' starting color.

# GradientPinkRed.rotatestring | number | undefinedoptional

Rotation to apply to gradient.

# GradientPinkRed.tostring | undefinedoptional

End color of gradient.

Default #FF7676

# GradientPinkRed.toOffsetstring | number | undefinedoptional

Number or percent defining the where the 'to' ending color is placed along the gradient.

# GradientPinkRed.toOpacitystring | number | undefinedoptional

Opacity of the 'to' ending color.

# GradientPinkRed.transformstring | undefinedoptional

Transform to apply to linearGradient, overrides rotate.

# GradientPinkRed.verticalboolean | undefinedoptional

(When no x or y values are passed), will orient the gradient vertically instead of horizontally.

# GradientPinkRed.x1string | number | undefinedoptional

The x coordinate of the starting point along which the linear gradient is drawn.

# GradientPinkRed.x2string | number | undefinedoptional

The x coordinate of the ending point along which the linear gradient is drawn.

# GradientPinkRed.y1string | number | undefinedoptional

The y coordinate of the starting point along which the linear gradient is drawn.

# GradientPinkRed.y2string | number | undefinedoptional

The y coordinate of the ending point along which the linear gradient is drawn.

#<GradientPurpleOrange />

# GradientPurpleOrange.idstringrequired

Unique id for the gradient. Should be unique across all page elements.

# GradientPurpleOrange.childrenReactNodeoptional

Override of linearGradient children.

# GradientPurpleOrange.fromstring | undefinedoptional

Start color of gradient.

Default #7117EA

# GradientPurpleOrange.fromOffsetstring | number | undefinedoptional

Number or percent defining the where the 'from' starting color is placed along the gradient.

# GradientPurpleOrange.fromOpacitystring | number | undefinedoptional

Opacity of the 'from' starting color.

# GradientPurpleOrange.rotatestring | number | undefinedoptional

Rotation to apply to gradient.

# GradientPurpleOrange.tostring | undefinedoptional

End color of gradient.

Default #EA6060

# GradientPurpleOrange.toOffsetstring | number | undefinedoptional

Number or percent defining the where the 'to' ending color is placed along the gradient.

# GradientPurpleOrange.toOpacitystring | number | undefinedoptional

Opacity of the 'to' ending color.

# GradientPurpleOrange.transformstring | undefinedoptional

Transform to apply to linearGradient, overrides rotate.

# GradientPurpleOrange.verticalboolean | undefinedoptional

(When no x or y values are passed), will orient the gradient vertically instead of horizontally.

# GradientPurpleOrange.x1string | number | undefinedoptional

The x coordinate of the starting point along which the linear gradient is drawn.

# GradientPurpleOrange.x2string | number | undefinedoptional

The x coordinate of the ending point along which the linear gradient is drawn.

# GradientPurpleOrange.y1string | number | undefinedoptional

The y coordinate of the starting point along which the linear gradient is drawn.

# GradientPurpleOrange.y2string | number | undefinedoptional

The y coordinate of the ending point along which the linear gradient is drawn.

#<GradientPurpleRed />

# GradientPurpleRed.idstringrequired

Unique id for the gradient. Should be unique across all page elements.

# GradientPurpleRed.childrenReactNodeoptional

Override of linearGradient children.

# GradientPurpleRed.fromstring | undefinedoptional

Start color of gradient.

Default #622774

# GradientPurpleRed.fromOffsetstring | number | undefinedoptional

Number or percent defining the where the 'from' starting color is placed along the gradient.

# GradientPurpleRed.fromOpacitystring | number | undefinedoptional

Opacity of the 'from' starting color.

# GradientPurpleRed.rotatestring | number | undefinedoptional

Rotation to apply to gradient.

# GradientPurpleRed.tostring | undefinedoptional

End color of gradient.

Default #C53364

# GradientPurpleRed.toOffsetstring | number | undefinedoptional

Number or percent defining the where the 'to' ending color is placed along the gradient.

# GradientPurpleRed.toOpacitystring | number | undefinedoptional

Opacity of the 'to' ending color.

# GradientPurpleRed.transformstring | undefinedoptional

Transform to apply to linearGradient, overrides rotate.

# GradientPurpleRed.verticalboolean | undefinedoptional

(When no x or y values are passed), will orient the gradient vertically instead of horizontally.

# GradientPurpleRed.x1string | number | undefinedoptional

The x coordinate of the starting point along which the linear gradient is drawn.

# GradientPurpleRed.x2string | number | undefinedoptional

The x coordinate of the ending point along which the linear gradient is drawn.

# GradientPurpleRed.y1string | number | undefinedoptional

The y coordinate of the starting point along which the linear gradient is drawn.

# GradientPurpleRed.y2string | number | undefinedoptional

The y coordinate of the ending point along which the linear gradient is drawn.

#<GradientPurpleTeal />

# GradientPurpleTeal.idstringrequired

Unique id for the gradient. Should be unique across all page elements.

# GradientPurpleTeal.childrenReactNodeoptional

Override of linearGradient children.

# GradientPurpleTeal.fromstring | undefinedoptional

Start color of gradient.

Default #5B247A

# GradientPurpleTeal.fromOffsetstring | number | undefinedoptional

Number or percent defining the where the 'from' starting color is placed along the gradient.

# GradientPurpleTeal.fromOpacitystring | number | undefinedoptional

Opacity of the 'from' starting color.

# GradientPurpleTeal.rotatestring | number | undefinedoptional

Rotation to apply to gradient.

# GradientPurpleTeal.tostring | undefinedoptional

End color of gradient.

Default #1BCEDF

# GradientPurpleTeal.toOffsetstring | number | undefinedoptional

Number or percent defining the where the 'to' ending color is placed along the gradient.

# GradientPurpleTeal.toOpacitystring | number | undefinedoptional

Opacity of the 'to' ending color.

# GradientPurpleTeal.transformstring | undefinedoptional

Transform to apply to linearGradient, overrides rotate.

# GradientPurpleTeal.verticalboolean | undefinedoptional

(When no x or y values are passed), will orient the gradient vertically instead of horizontally.

# GradientPurpleTeal.x1string | number | undefinedoptional

The x coordinate of the starting point along which the linear gradient is drawn.

# GradientPurpleTeal.x2string | number | undefinedoptional

The x coordinate of the ending point along which the linear gradient is drawn.

# GradientPurpleTeal.y1string | number | undefinedoptional

The y coordinate of the starting point along which the linear gradient is drawn.

# GradientPurpleTeal.y2string | number | undefinedoptional

The y coordinate of the ending point along which the linear gradient is drawn.

#<GradientSteelPurple />

# GradientSteelPurple.idstringrequired

Unique id for the gradient. Should be unique across all page elements.

# GradientSteelPurple.childrenReactNodeoptional

Override of linearGradient children.

# GradientSteelPurple.fromstring | undefinedoptional

Start color of gradient.

Default #65799B

# GradientSteelPurple.fromOffsetstring | number | undefinedoptional

Number or percent defining the where the 'from' starting color is placed along the gradient.

# GradientSteelPurple.fromOpacitystring | number | undefinedoptional

Opacity of the 'from' starting color.

# GradientSteelPurple.rotatestring | number | undefinedoptional

Rotation to apply to gradient.

# GradientSteelPurple.tostring | undefinedoptional

End color of gradient.

Default #5E2563

# GradientSteelPurple.toOffsetstring | number | undefinedoptional

Number or percent defining the where the 'to' ending color is placed along the gradient.

# GradientSteelPurple.toOpacitystring | number | undefinedoptional

Opacity of the 'to' ending color.

# GradientSteelPurple.transformstring | undefinedoptional

Transform to apply to linearGradient, overrides rotate.

# GradientSteelPurple.verticalboolean | undefinedoptional

(When no x or y values are passed), will orient the gradient vertically instead of horizontally.

# GradientSteelPurple.x1string | number | undefinedoptional

The x coordinate of the starting point along which the linear gradient is drawn.

# GradientSteelPurple.x2string | number | undefinedoptional

The x coordinate of the ending point along which the linear gradient is drawn.

# GradientSteelPurple.y1string | number | undefinedoptional

The y coordinate of the starting point along which the linear gradient is drawn.

# GradientSteelPurple.y2string | number | undefinedoptional

The y coordinate of the ending point along which the linear gradient is drawn.

#<GradientTealBlue />

# GradientTealBlue.idstringrequired

Unique id for the gradient. Should be unique across all page elements.

# GradientTealBlue.childrenReactNodeoptional

Override of linearGradient children.

# GradientTealBlue.fromstring | undefinedoptional

Start color of gradient.

Default #17EAD9

# GradientTealBlue.fromOffsetstring | number | undefinedoptional

Number or percent defining the where the 'from' starting color is placed along the gradient.

# GradientTealBlue.fromOpacitystring | number | undefinedoptional

Opacity of the 'from' starting color.

# GradientTealBlue.rotatestring | number | undefinedoptional

Rotation to apply to gradient.

# GradientTealBlue.tostring | undefinedoptional

End color of gradient.

Default #6078EA

# GradientTealBlue.toOffsetstring | number | undefinedoptional

Number or percent defining the where the 'to' ending color is placed along the gradient.

# GradientTealBlue.toOpacitystring | number | undefinedoptional

Opacity of the 'to' ending color.

# GradientTealBlue.transformstring | undefinedoptional

Transform to apply to linearGradient, overrides rotate.

# GradientTealBlue.verticalboolean | undefinedoptional

(When no x or y values are passed), will orient the gradient vertically instead of horizontally.

# GradientTealBlue.x1string | number | undefinedoptional

The x coordinate of the starting point along which the linear gradient is drawn.

# GradientTealBlue.x2string | number | undefinedoptional

The x coordinate of the ending point along which the linear gradient is drawn.

# GradientTealBlue.y1string | number | undefinedoptional

The y coordinate of the starting point along which the linear gradient is drawn.

# GradientTealBlue.y2string | number | undefinedoptional

The y coordinate of the ending point along which the linear gradient is drawn.