@visx/gradient

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

Example

import { AreaClosed } from '@visx/shape';
import { GradientPinkBlue } from '@visx/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 '@visx/gradient';

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

Installation

npm install --save @visx/gradient

Examples

APIs

#<LinearGradient />

# idstringrequired

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

# childrenReactNode

Override of linearGradient children.

# fromstring | undefined

Start color of gradient.

# fromOffsetstring | number | undefined

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

Default 0%

# fromOpacitystring | number | undefined

Opacity of the 'from' starting color.

Default 1

# rotatestring | number | undefined

Rotation to apply to gradient.

# tostring | undefined

End color of gradient.

# toOffsetstring | number | undefined

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

Default 100%

# toOpacitystring | number | undefined

Opacity of the 'to' ending color.

Default 1

# transformstring | undefined

Transform to apply to linearGradient, overrides rotate.

# verticalboolean | undefined

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

Default true

# x1string | number | undefined

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

# x2string | number | undefined

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

# y1string | number | undefined

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

# y2string | number | undefined

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

#<RadialGradient />

# childrenReactNode

Override of linearGradient children.

# fromstring | number | undefined

Start color of gradient.

# fromOffsetstring | number | undefined

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

Default 0%

# fromOpacitystring | number | undefined

Opacity of the 'from' starting color.

Default 1

# idstring | undefined

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

# rotatestring | number | undefined

Rotation to apply to gradient.

# tostring | number | undefined

End color of gradient.

# toOffsetstring | number | undefined

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

Default 100%

# toOpacitystring | number | undefined

Opacity of the 'to' ending color.

Default 1

# transformstring | undefined

Transform to apply to linearGradient, overrides rotate.

#<GradientDarkgreenGreen />

# idstringrequired

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

# childrenReactNode

Override of linearGradient children.

# fromstring | undefined

Start color of gradient.

Default #184E86

# fromOffsetstring | number | undefined

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

# fromOpacitystring | number | undefined

Opacity of the 'from' starting color.

# rotatestring | number | undefined

Rotation to apply to gradient.

# tostring | undefined

End color of gradient.

Default #57CA85

# toOffsetstring | number | undefined

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

# toOpacitystring | number | undefined

Opacity of the 'to' ending color.

# transformstring | undefined

Transform to apply to linearGradient, overrides rotate.

# verticalboolean | undefined

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

# x1string | number | undefined

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

# x2string | number | undefined

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

# y1string | number | undefined

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

# y2string | number | undefined

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

#<GradientLightgreenGreen />

# idstringrequired

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

# childrenReactNode

Override of linearGradient children.

# fromstring | undefined

Start color of gradient.

Default #42E695

# fromOffsetstring | number | undefined

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

# fromOpacitystring | number | undefined

Opacity of the 'from' starting color.

# rotatestring | number | undefined

Rotation to apply to gradient.

# tostring | undefined

End color of gradient.

Default #3BB2B8

# toOffsetstring | number | undefined

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

# toOpacitystring | number | undefined

Opacity of the 'to' ending color.

# transformstring | undefined

Transform to apply to linearGradient, overrides rotate.

# verticalboolean | undefined

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

# x1string | number | undefined

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

# x2string | number | undefined

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

# y1string | number | undefined

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

# y2string | number | undefined

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

#<GradientOrangeRed />

# idstringrequired

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

# childrenReactNode

Override of linearGradient children.

# fromstring | undefined

Start color of gradient.

Default #FCE38A

# fromOffsetstring | number | undefined

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

# fromOpacitystring | number | undefined

Opacity of the 'from' starting color.

# rotatestring | number | undefined

Rotation to apply to gradient.

# tostring | undefined

End color of gradient.

Default #F38181

# toOffsetstring | number | undefined

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

# toOpacitystring | number | undefined

Opacity of the 'to' ending color.

# transformstring | undefined

Transform to apply to linearGradient, overrides rotate.

# verticalboolean | undefined

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

# x1string | number | undefined

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

# x2string | number | undefined

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

# y1string | number | undefined

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

# y2string | number | undefined

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

#<GradientPinkBlue />

# idstringrequired

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

# childrenReactNode

Override of linearGradient children.

# fromstring | undefined

Start color of gradient.

Default #F02FC2

# fromOffsetstring | number | undefined

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

# fromOpacitystring | number | undefined

Opacity of the 'from' starting color.

# rotatestring | number | undefined

Rotation to apply to gradient.

# tostring | undefined

End color of gradient.

Default #6094EA

# toOffsetstring | number | undefined

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

# toOpacitystring | number | undefined

Opacity of the 'to' ending color.

# transformstring | undefined

Transform to apply to linearGradient, overrides rotate.

# verticalboolean | undefined

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

# x1string | number | undefined

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

# x2string | number | undefined

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

# y1string | number | undefined

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

# y2string | number | undefined

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

#<GradientPinkRed />

# idstringrequired

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

# childrenReactNode

Override of linearGradient children.

# fromstring | undefined

Start color of gradient.

Default #F54EA2

# fromOffsetstring | number | undefined

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

# fromOpacitystring | number | undefined

Opacity of the 'from' starting color.

# rotatestring | number | undefined

Rotation to apply to gradient.

# tostring | undefined

End color of gradient.

Default #FF7676

# toOffsetstring | number | undefined

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

# toOpacitystring | number | undefined

Opacity of the 'to' ending color.

# transformstring | undefined

Transform to apply to linearGradient, overrides rotate.

# verticalboolean | undefined

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

# x1string | number | undefined

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

# x2string | number | undefined

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

# y1string | number | undefined

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

# y2string | number | undefined

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

#<GradientPurpleOrange />

# idstringrequired

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

# childrenReactNode

Override of linearGradient children.

# fromstring | undefined

Start color of gradient.

Default #7117EA

# fromOffsetstring | number | undefined

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

# fromOpacitystring | number | undefined

Opacity of the 'from' starting color.

# rotatestring | number | undefined

Rotation to apply to gradient.

# tostring | undefined

End color of gradient.

Default #EA6060

# toOffsetstring | number | undefined

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

# toOpacitystring | number | undefined

Opacity of the 'to' ending color.

# transformstring | undefined

Transform to apply to linearGradient, overrides rotate.

# verticalboolean | undefined

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

# x1string | number | undefined

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

# x2string | number | undefined

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

# y1string | number | undefined

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

# y2string | number | undefined

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

#<GradientPurpleRed />

# idstringrequired

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

# childrenReactNode

Override of linearGradient children.

# fromstring | undefined

Start color of gradient.

Default #622774

# fromOffsetstring | number | undefined

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

# fromOpacitystring | number | undefined

Opacity of the 'from' starting color.

# rotatestring | number | undefined

Rotation to apply to gradient.

# tostring | undefined

End color of gradient.

Default #C53364

# toOffsetstring | number | undefined

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

# toOpacitystring | number | undefined

Opacity of the 'to' ending color.

# transformstring | undefined

Transform to apply to linearGradient, overrides rotate.

# verticalboolean | undefined

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

# x1string | number | undefined

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

# x2string | number | undefined

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

# y1string | number | undefined

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

# y2string | number | undefined

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

#<GradientPurpleTeal />

# idstringrequired

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

# childrenReactNode

Override of linearGradient children.

# fromstring | undefined

Start color of gradient.

Default #5B247A

# fromOffsetstring | number | undefined

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

# fromOpacitystring | number | undefined

Opacity of the 'from' starting color.

# rotatestring | number | undefined

Rotation to apply to gradient.

# tostring | undefined

End color of gradient.

Default #1BCEDF

# toOffsetstring | number | undefined

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

# toOpacitystring | number | undefined

Opacity of the 'to' ending color.

# transformstring | undefined

Transform to apply to linearGradient, overrides rotate.

# verticalboolean | undefined

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

# x1string | number | undefined

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

# x2string | number | undefined

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

# y1string | number | undefined

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

# y2string | number | undefined

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

#<GradientSteelPurple />

# idstringrequired

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

# childrenReactNode

Override of linearGradient children.

# fromstring | undefined

Start color of gradient.

Default #65799B

# fromOffsetstring | number | undefined

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

# fromOpacitystring | number | undefined

Opacity of the 'from' starting color.

# rotatestring | number | undefined

Rotation to apply to gradient.

# tostring | undefined

End color of gradient.

Default #5E2563

# toOffsetstring | number | undefined

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

# toOpacitystring | number | undefined

Opacity of the 'to' ending color.

# transformstring | undefined

Transform to apply to linearGradient, overrides rotate.

# verticalboolean | undefined

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

# x1string | number | undefined

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

# x2string | number | undefined

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

# y1string | number | undefined

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

# y2string | number | undefined

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

#<GradientTealBlue />

# idstringrequired

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

# childrenReactNode

Override of linearGradient children.

# fromstring | undefined

Start color of gradient.

Default #17EAD9

# fromOffsetstring | number | undefined

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

# fromOpacitystring | number | undefined

Opacity of the 'from' starting color.

# rotatestring | number | undefined

Rotation to apply to gradient.

# tostring | undefined

End color of gradient.

Default #6078EA

# toOffsetstring | number | undefined

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

# toOpacitystring | number | undefined

Opacity of the 'to' ending color.

# transformstring | undefined

Transform to apply to linearGradient, overrides rotate.

# verticalboolean | undefined

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

# x1string | number | undefined

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

# x2string | number | undefined

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

# y1string | number | undefined

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

# y2string | number | undefined

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