1 | function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
2 |
|
3 | function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
4 |
|
5 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? Object(arguments[i]) : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
|
6 |
|
7 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
8 |
|
9 | import { generate, getSecondaryColor, isIconDefinition, warning, useInsertStyles } from '../utils';
|
10 | var twoToneColorPalette = {
|
11 | primaryColor: '#333',
|
12 | secondaryColor: '#E6E6E6',
|
13 | calculated: false
|
14 | };
|
15 |
|
16 | function setTwoToneColors(_ref) {
|
17 | var primaryColor = _ref.primaryColor,
|
18 | secondaryColor = _ref.secondaryColor;
|
19 | twoToneColorPalette.primaryColor = primaryColor;
|
20 | twoToneColorPalette.secondaryColor = secondaryColor || getSecondaryColor(primaryColor);
|
21 | twoToneColorPalette.calculated = !!secondaryColor;
|
22 | }
|
23 |
|
24 | function getTwoToneColors() {
|
25 | return _objectSpread({}, twoToneColorPalette);
|
26 | }
|
27 |
|
28 | var IconBase = function IconBase(props, context) {
|
29 | var _props$context$attrs = _objectSpread({}, props, context.attrs),
|
30 | icon = _props$context$attrs.icon,
|
31 | primaryColor = _props$context$attrs.primaryColor,
|
32 | secondaryColor = _props$context$attrs.secondaryColor,
|
33 | restProps = _objectWithoutProperties(_props$context$attrs, ["icon", "primaryColor", "secondaryColor"]);
|
34 |
|
35 | var colors = twoToneColorPalette;
|
36 |
|
37 | if (primaryColor) {
|
38 | colors = {
|
39 | primaryColor: primaryColor,
|
40 | secondaryColor: secondaryColor || getSecondaryColor(primaryColor)
|
41 | };
|
42 | }
|
43 |
|
44 | useInsertStyles();
|
45 | warning(isIconDefinition(icon), "icon should be icon definiton, but got ".concat(icon));
|
46 |
|
47 | if (!isIconDefinition(icon)) {
|
48 | return null;
|
49 | }
|
50 |
|
51 | var target = icon;
|
52 |
|
53 | if (target && typeof target.icon === 'function') {
|
54 | target = _objectSpread({}, target, {
|
55 | icon: target.icon(colors.primaryColor, colors.secondaryColor)
|
56 | });
|
57 | }
|
58 |
|
59 | return generate(target.icon, "svg-".concat(target.name), _objectSpread({}, restProps, {
|
60 | 'data-icon': target.name,
|
61 | width: '1em',
|
62 | height: '1em',
|
63 | fill: 'currentColor',
|
64 | 'aria-hidden': 'true'
|
65 | }));
|
66 | };
|
67 |
|
68 | IconBase.props = {
|
69 | icon: Object,
|
70 | primaryColor: String,
|
71 | secondaryColor: String,
|
72 | focusable: String
|
73 | };
|
74 | IconBase.inheritAttrs = false;
|
75 | IconBase.displayName = 'IconBase';
|
76 | IconBase.getTwoToneColors = getTwoToneColors;
|
77 | IconBase.setTwoToneColors = setTwoToneColors;
|
78 | export default IconBase; |
\ | No newline at end of file |