/
LinearGradient.js
41 lines (38 loc) · 1.12 KB
/
LinearGradient.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* This file is part of the nivo project.
*
* Copyright 2016-present, Raphaël Benitte.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import PropTypes from 'prop-types'
export const LinearGradient = ({ id, colors, ...rest }) => (
<linearGradient id={id} x1={0} x2={0} y1={0} y2={1} {...rest}>
{colors.map(({ offset, color, opacity }) => (
<stop
key={offset}
offset={`${offset}%`}
stopColor={color}
stopOpacity={opacity !== undefined ? opacity : 1}
/>
))}
</linearGradient>
)
LinearGradient.propTypes = {
id: PropTypes.string.isRequired,
colors: PropTypes.arrayOf(
PropTypes.shape({
offset: PropTypes.number.isRequired,
color: PropTypes.string.isRequired,
opacity: PropTypes.number,
})
).isRequired,
gradientTransform: PropTypes.string,
}
export const linearGradientDef = (id, colors, options = {}) => ({
id,
type: 'linearGradient',
colors,
...options,
})