UNPKG

2.23 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = radialGradient;
5var _constructGradientValue = _interopRequireDefault(require("../internalHelpers/_constructGradientValue"));
6var _errors = _interopRequireDefault(require("../internalHelpers/_errors"));
7var _templateObject;
8function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9function _taggedTemplateLiteralLoose(strings, raw) { if (!raw) { raw = strings.slice(0); } strings.raw = raw; return strings; }
10/**
11 * CSS for declaring a radial gradient, including a fallback background-color. The fallback is either the first color-stop or an explicitly passed fallback color.
12 *
13 * @example
14 * // Styles as object usage
15 * const styles = {
16 * ...radialGradient({
17 * colorStops: ['#00FFFF 0%', 'rgba(0, 0, 255, 0) 50%', '#0000FF 95%'],
18 * extent: 'farthest-corner at 45px 45px',
19 * position: 'center',
20 * shape: 'ellipse',
21 * })
22 * }
23 *
24 * // styled-components usage
25 * const div = styled.div`
26 * ${radialGradient({
27 * colorStops: ['#00FFFF 0%', 'rgba(0, 0, 255, 0) 50%', '#0000FF 95%'],
28 * extent: 'farthest-corner at 45px 45px',
29 * position: 'center',
30 * shape: 'ellipse',
31 * })}
32 *`
33 *
34 * // CSS as JS Output
35 *
36 * div: {
37 * 'backgroundColor': '#00FFFF',
38 * 'backgroundImage': 'radial-gradient(center ellipse farthest-corner at 45px 45px, #00FFFF 0%, rgba(0, 0, 255, 0) 50%, #0000FF 95%)',
39 * }
40 */
41function radialGradient(_ref) {
42 var colorStops = _ref.colorStops,
43 _ref$extent = _ref.extent,
44 extent = _ref$extent === void 0 ? '' : _ref$extent,
45 fallback = _ref.fallback,
46 _ref$position = _ref.position,
47 position = _ref$position === void 0 ? '' : _ref$position,
48 _ref$shape = _ref.shape,
49 shape = _ref$shape === void 0 ? '' : _ref$shape;
50 if (!colorStops || colorStops.length < 2) {
51 throw new _errors["default"](57);
52 }
53 return {
54 backgroundColor: fallback || colorStops[0].split(' ')[0],
55 backgroundImage: (0, _constructGradientValue["default"])(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["radial-gradient(", "", "", "", ")"])), position, shape, extent, colorStops.join(', '))
56 };
57}
58module.exports = exports.default;
\No newline at end of file