UNPKG

6.54 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", {
3 value: true
4});
5Object.defineProperty(exports, "default", {
6 enumerable: true,
7 get: function() {
8 return _default;
9 }
10});
11var _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
12var _utils = require("../utils");
13function _define_property(obj, key, value) {
14 if (key in obj) {
15 Object.defineProperty(obj, key, {
16 value: value,
17 enumerable: true,
18 configurable: true,
19 writable: true
20 });
21 } else {
22 obj[key] = value;
23 }
24 return obj;
25}
26function _getRequireWildcardCache(nodeInterop) {
27 if (typeof WeakMap !== "function") return null;
28 var cacheBabelInterop = new WeakMap();
29 var cacheNodeInterop = new WeakMap();
30 return (_getRequireWildcardCache = function(nodeInterop) {
31 return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
32 })(nodeInterop);
33}
34function _interop_require_wildcard(obj, nodeInterop) {
35 if (!nodeInterop && obj && obj.__esModule) {
36 return obj;
37 }
38 if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
39 return {
40 default: obj
41 };
42 }
43 var cache = _getRequireWildcardCache(nodeInterop);
44 if (cache && cache.has(obj)) {
45 return cache.get(obj);
46 }
47 var newObj = {};
48 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
49 for(var key in obj){
50 if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
51 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
52 if (desc && (desc.get || desc.set)) {
53 Object.defineProperty(newObj, key, desc);
54 } else {
55 newObj[key] = obj[key];
56 }
57 }
58 }
59 newObj.default = obj;
60 if (cache) {
61 cache.set(obj, newObj);
62 }
63 return newObj;
64}
65function _object_spread(target) {
66 for(var i = 1; i < arguments.length; i++){
67 var source = arguments[i] != null ? arguments[i] : {};
68 var ownKeys = Object.keys(source);
69 if (typeof Object.getOwnPropertySymbols === "function") {
70 ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
71 return Object.getOwnPropertyDescriptor(source, sym).enumerable;
72 }));
73 }
74 ownKeys.forEach(function(key) {
75 _define_property(target, key, source[key]);
76 });
77 }
78 return target;
79}
80function ownKeys(object, enumerableOnly) {
81 var keys = Object.keys(object);
82 if (Object.getOwnPropertySymbols) {
83 var symbols = Object.getOwnPropertySymbols(object);
84 if (enumerableOnly) {
85 symbols = symbols.filter(function(sym) {
86 return Object.getOwnPropertyDescriptor(object, sym).enumerable;
87 });
88 }
89 keys.push.apply(keys, symbols);
90 }
91 return keys;
92}
93function _object_spread_props(target, source) {
94 source = source != null ? source : {};
95 if (Object.getOwnPropertyDescriptors) {
96 Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
97 } else {
98 ownKeys(Object(source)).forEach(function(key) {
99 Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
100 });
101 }
102 return target;
103}
104function _object_without_properties(source, excluded) {
105 if (source == null) return {};
106 var target = _object_without_properties_loose(source, excluded);
107 var key, i;
108 if (Object.getOwnPropertySymbols) {
109 var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
110 for(i = 0; i < sourceSymbolKeys.length; i++){
111 key = sourceSymbolKeys[i];
112 if (excluded.indexOf(key) >= 0) continue;
113 if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
114 target[key] = source[key];
115 }
116 }
117 return target;
118}
119function _object_without_properties_loose(source, excluded) {
120 if (source == null) return {};
121 var target = {};
122 var sourceKeys = Object.keys(source);
123 var key, i;
124 for(i = 0; i < sourceKeys.length; i++){
125 key = sourceKeys[i];
126 if (excluded.indexOf(key) >= 0) continue;
127 target[key] = source[key];
128 }
129 return target;
130}
131var twoToneColorPalette = {
132 primaryColor: "#333",
133 secondaryColor: "#E6E6E6",
134 calculated: false
135};
136function setTwoToneColors(param) {
137 var primaryColor = param.primaryColor, secondaryColor = param.secondaryColor;
138 twoToneColorPalette.primaryColor = primaryColor;
139 twoToneColorPalette.secondaryColor = secondaryColor || (0, _utils.getSecondaryColor)(primaryColor);
140 twoToneColorPalette.calculated = !!secondaryColor;
141}
142function getTwoToneColors() {
143 return _object_spread({}, twoToneColorPalette);
144}
145var IconBase = function(props) {
146 var icon = props.icon, className = props.className, onClick = props.onClick, style = props.style, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, restProps = _object_without_properties(props, [
147 "icon",
148 "className",
149 "onClick",
150 "style",
151 "primaryColor",
152 "secondaryColor"
153 ]);
154 var svgRef = _react.useRef();
155 var colors = twoToneColorPalette;
156 if (primaryColor) {
157 colors = {
158 primaryColor: primaryColor,
159 secondaryColor: secondaryColor || (0, _utils.getSecondaryColor)(primaryColor)
160 };
161 }
162 (0, _utils.useInsertStyles)(svgRef);
163 (0, _utils.warning)((0, _utils.isIconDefinition)(icon), "icon should be icon definiton, but got ".concat(icon));
164 if (!(0, _utils.isIconDefinition)(icon)) {
165 return null;
166 }
167 var target = icon;
168 if (target && typeof target.icon === "function") {
169 target = _object_spread_props(_object_spread({}, target), {
170 icon: target.icon(colors.primaryColor, colors.secondaryColor)
171 });
172 }
173 return (0, _utils.generate)(target.icon, "svg-".concat(target.name), _object_spread_props(_object_spread({
174 className: className,
175 onClick: onClick,
176 style: style,
177 "data-icon": target.name,
178 width: "1em",
179 height: "1em",
180 fill: "currentColor",
181 "aria-hidden": "true"
182 }, restProps), {
183 ref: svgRef
184 }));
185};
186IconBase.displayName = "IconReact";
187IconBase.getTwoToneColors = getTwoToneColors;
188IconBase.setTwoToneColors = setTwoToneColors;
189var _default = IconBase;