UNPKG

3.76 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports["default"] = void 0;
7
8var _utils = require("../utils");
9
10var _excluded = ["icon", "primaryColor", "secondaryColor"];
11
12function _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; }
13
14function _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; }
15
16function _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; }
17
18function _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; }
19
20var twoToneColorPalette = {
21 primaryColor: '#333',
22 secondaryColor: '#E6E6E6',
23 calculated: false
24};
25
26function setTwoToneColors(_ref) {
27 var primaryColor = _ref.primaryColor,
28 secondaryColor = _ref.secondaryColor;
29 twoToneColorPalette.primaryColor = primaryColor;
30 twoToneColorPalette.secondaryColor = secondaryColor || (0, _utils.getSecondaryColor)(primaryColor);
31 twoToneColorPalette.calculated = !!secondaryColor;
32}
33
34function getTwoToneColors() {
35 return _objectSpread({}, twoToneColorPalette);
36}
37
38var IconBase = function IconBase(props, context) {
39 var _props$context$attrs = _objectSpread({}, props, context.attrs),
40 icon = _props$context$attrs.icon,
41 primaryColor = _props$context$attrs.primaryColor,
42 secondaryColor = _props$context$attrs.secondaryColor,
43 restProps = _objectWithoutProperties(_props$context$attrs, _excluded);
44
45 var colors = twoToneColorPalette;
46
47 if (primaryColor) {
48 colors = {
49 primaryColor: primaryColor,
50 secondaryColor: secondaryColor || (0, _utils.getSecondaryColor)(primaryColor)
51 };
52 }
53
54 (0, _utils.useInsertStyles)();
55 (0, _utils.warning)((0, _utils.isIconDefinition)(icon), "icon should be icon definiton, but got ".concat(icon));
56
57 if (!(0, _utils.isIconDefinition)(icon)) {
58 return null;
59 }
60
61 var target = icon;
62
63 if (target && typeof target.icon === 'function') {
64 target = _objectSpread({}, target, {
65 icon: target.icon(colors.primaryColor, colors.secondaryColor)
66 });
67 }
68
69 return (0, _utils.generate)(target.icon, "svg-".concat(target.name), _objectSpread({}, restProps, {
70 'data-icon': target.name,
71 width: '1em',
72 height: '1em',
73 fill: 'currentColor',
74 'aria-hidden': 'true'
75 })); // },
76};
77
78IconBase.props = {
79 icon: Object,
80 primaryColor: String,
81 secondaryColor: String,
82 focusable: String
83};
84IconBase.inheritAttrs = false;
85IconBase.displayName = 'IconBase';
86IconBase.getTwoToneColors = getTwoToneColors;
87IconBase.setTwoToneColors = setTwoToneColors;
88var _default = IconBase;
89exports["default"] = _default;
\No newline at end of file