1 | import { parse, icon } from '@fortawesome/fontawesome-svg-core';
|
2 | import PropTypes from 'prop-types';
|
3 | import React from 'react';
|
4 |
|
5 | function ownKeys(object, enumerableOnly) {
|
6 | var keys = Object.keys(object);
|
7 |
|
8 | if (Object.getOwnPropertySymbols) {
|
9 | var symbols = Object.getOwnPropertySymbols(object);
|
10 | enumerableOnly && (symbols = symbols.filter(function (sym) {
|
11 | return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
12 | })), keys.push.apply(keys, symbols);
|
13 | }
|
14 |
|
15 | return keys;
|
16 | }
|
17 |
|
18 | function _objectSpread2(target) {
|
19 | for (var i = 1; i < arguments.length; i++) {
|
20 | var source = null != arguments[i] ? arguments[i] : {};
|
21 | i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
22 | _defineProperty(target, key, source[key]);
|
23 | }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
24 | Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
25 | });
|
26 | }
|
27 |
|
28 | return target;
|
29 | }
|
30 |
|
31 | function _typeof(obj) {
|
32 | "@babel/helpers - typeof";
|
33 |
|
34 | return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
35 | return typeof obj;
|
36 | } : function (obj) {
|
37 | return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
38 | }, _typeof(obj);
|
39 | }
|
40 |
|
41 | function _defineProperty(obj, key, value) {
|
42 | if (key in obj) {
|
43 | Object.defineProperty(obj, key, {
|
44 | value: value,
|
45 | enumerable: true,
|
46 | configurable: true,
|
47 | writable: true
|
48 | });
|
49 | } else {
|
50 | obj[key] = value;
|
51 | }
|
52 |
|
53 | return obj;
|
54 | }
|
55 |
|
56 | function _objectWithoutPropertiesLoose(source, excluded) {
|
57 | if (source == null) return {};
|
58 | var target = {};
|
59 | var sourceKeys = Object.keys(source);
|
60 | var key, i;
|
61 |
|
62 | for (i = 0; i < sourceKeys.length; i++) {
|
63 | key = sourceKeys[i];
|
64 | if (excluded.indexOf(key) >= 0) continue;
|
65 | target[key] = source[key];
|
66 | }
|
67 |
|
68 | return target;
|
69 | }
|
70 |
|
71 | function _objectWithoutProperties(source, excluded) {
|
72 | if (source == null) return {};
|
73 |
|
74 | var target = _objectWithoutPropertiesLoose(source, excluded);
|
75 |
|
76 | var key, i;
|
77 |
|
78 | if (Object.getOwnPropertySymbols) {
|
79 | var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
80 |
|
81 | for (i = 0; i < sourceSymbolKeys.length; i++) {
|
82 | key = sourceSymbolKeys[i];
|
83 | if (excluded.indexOf(key) >= 0) continue;
|
84 | if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
85 | target[key] = source[key];
|
86 | }
|
87 | }
|
88 |
|
89 | return target;
|
90 | }
|
91 |
|
92 | function _toConsumableArray(arr) {
|
93 | return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
94 | }
|
95 |
|
96 | function _arrayWithoutHoles(arr) {
|
97 | if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
98 | }
|
99 |
|
100 | function _iterableToArray(iter) {
|
101 | if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
102 | }
|
103 |
|
104 | function _unsupportedIterableToArray(o, minLen) {
|
105 | if (!o) return;
|
106 | if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
107 | var n = Object.prototype.toString.call(o).slice(8, -1);
|
108 | if (n === "Object" && o.constructor) n = o.constructor.name;
|
109 | if (n === "Map" || n === "Set") return Array.from(o);
|
110 | if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
111 | }
|
112 |
|
113 | function _arrayLikeToArray(arr, len) {
|
114 | if (len == null || len > arr.length) len = arr.length;
|
115 |
|
116 | for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
117 |
|
118 | return arr2;
|
119 | }
|
120 |
|
121 | function _nonIterableSpread() {
|
122 | throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
123 | }
|
124 |
|
125 |
|
126 | function classList(props) {
|
127 | var _classes;
|
128 |
|
129 | var beat = props.beat,
|
130 | fade = props.fade,
|
131 | beatFade = props.beatFade,
|
132 | bounce = props.bounce,
|
133 | shake = props.shake,
|
134 | flash = props.flash,
|
135 | spin = props.spin,
|
136 | spinPulse = props.spinPulse,
|
137 | spinReverse = props.spinReverse,
|
138 | pulse = props.pulse,
|
139 | fixedWidth = props.fixedWidth,
|
140 | inverse = props.inverse,
|
141 | border = props.border,
|
142 | listItem = props.listItem,
|
143 | flip = props.flip,
|
144 | size = props.size,
|
145 | rotation = props.rotation,
|
146 | pull = props.pull;
|
147 |
|
148 | var classes = (_classes = {
|
149 | 'fa-beat': beat,
|
150 | 'fa-fade': fade,
|
151 | 'fa-beat-fade': beatFade,
|
152 | 'fa-bounce': bounce,
|
153 | 'fa-shake': shake,
|
154 | 'fa-flash': flash,
|
155 | 'fa-spin': spin,
|
156 | 'fa-spin-reverse': spinReverse,
|
157 | 'fa-spin-pulse': spinPulse,
|
158 | 'fa-pulse': pulse,
|
159 | 'fa-fw': fixedWidth,
|
160 | 'fa-inverse': inverse,
|
161 | 'fa-border': border,
|
162 | 'fa-li': listItem,
|
163 | 'fa-flip': flip === true,
|
164 | 'fa-flip-horizontal': flip === 'horizontal' || flip === 'both',
|
165 | 'fa-flip-vertical': flip === 'vertical' || flip === 'both'
|
166 | }, _defineProperty(_classes, "fa-".concat(size), typeof size !== 'undefined' && size !== null), _defineProperty(_classes, "fa-rotate-".concat(rotation), typeof rotation !== 'undefined' && rotation !== null && rotation !== 0), _defineProperty(_classes, "fa-pull-".concat(pull), typeof pull !== 'undefined' && pull !== null), _defineProperty(_classes, 'fa-swap-opacity', props.swapOpacity), _classes);
|
167 |
|
168 |
|
169 | return Object.keys(classes).map(function (key) {
|
170 | return classes[key] ? key : null;
|
171 | }).filter(function (key) {
|
172 | return key;
|
173 | });
|
174 | }
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 | function _isNumerical(obj) {
|
181 | obj = obj - 0;
|
182 |
|
183 | return obj === obj;
|
184 | }
|
185 |
|
186 | function camelize(string) {
|
187 | if (_isNumerical(string)) {
|
188 | return string;
|
189 | }
|
190 |
|
191 |
|
192 | string = string.replace(/[\-_\s]+(.)?/g, function (match, chr) {
|
193 | return chr ? chr.toUpperCase() : '';
|
194 | });
|
195 |
|
196 | return string.substr(0, 1).toLowerCase() + string.substr(1);
|
197 | }
|
198 |
|
199 | var _excluded$1 = ["style"];
|
200 |
|
201 | function capitalize(val) {
|
202 | return val.charAt(0).toUpperCase() + val.slice(1);
|
203 | }
|
204 |
|
205 | function styleToObject(style) {
|
206 | return style.split(';').map(function (s) {
|
207 | return s.trim();
|
208 | }).filter(function (s) {
|
209 | return s;
|
210 | }).reduce(function (acc, pair) {
|
211 | var i = pair.indexOf(':');
|
212 | var prop = camelize(pair.slice(0, i));
|
213 | var value = pair.slice(i + 1).trim();
|
214 | prop.startsWith('webkit') ? acc[capitalize(prop)] = value : acc[prop] = value;
|
215 | return acc;
|
216 | }, {});
|
217 | }
|
218 |
|
219 | function convert(createElement, element) {
|
220 | var extraProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
221 |
|
222 | if (typeof element === 'string') {
|
223 | return element;
|
224 | }
|
225 |
|
226 | var children = (element.children || []).map(function (child) {
|
227 | return convert(createElement, child);
|
228 | });
|
229 |
|
230 |
|
231 | var mixins = Object.keys(element.attributes || {}).reduce(function (acc, key) {
|
232 | var val = element.attributes[key];
|
233 |
|
234 | switch (key) {
|
235 | case 'class':
|
236 | acc.attrs['className'] = val;
|
237 | delete element.attributes['class'];
|
238 | break;
|
239 |
|
240 | case 'style':
|
241 | acc.attrs['style'] = styleToObject(val);
|
242 | break;
|
243 |
|
244 | default:
|
245 | if (key.indexOf('aria-') === 0 || key.indexOf('data-') === 0) {
|
246 | acc.attrs[key.toLowerCase()] = val;
|
247 | } else {
|
248 | acc.attrs[camelize(key)] = val;
|
249 | }
|
250 |
|
251 | }
|
252 |
|
253 | return acc;
|
254 | }, {
|
255 | attrs: {}
|
256 | });
|
257 |
|
258 | var _extraProps$style = extraProps.style,
|
259 | existingStyle = _extraProps$style === void 0 ? {} : _extraProps$style,
|
260 | remaining = _objectWithoutProperties(extraProps, _excluded$1);
|
261 |
|
262 | mixins.attrs['style'] = _objectSpread2(_objectSpread2({}, mixins.attrs['style']), existingStyle);
|
263 |
|
264 |
|
265 | return createElement.apply(void 0, [element.tag, _objectSpread2(_objectSpread2({}, mixins.attrs), remaining)].concat(_toConsumableArray(children)));
|
266 | }
|
267 |
|
268 | var PRODUCTION = false;
|
269 |
|
270 | try {
|
271 | PRODUCTION = process.env.NODE_ENV === 'production';
|
272 | } catch (e) {}
|
273 |
|
274 | function log () {
|
275 | if (!PRODUCTION && console && typeof console.error === 'function') {
|
276 | var _console;
|
277 |
|
278 | (_console = console).error.apply(_console, arguments);
|
279 | }
|
280 | }
|
281 |
|
282 | function normalizeIconArgs(icon) {
|
283 |
|
284 |
|
285 | if (icon && _typeof(icon) === 'object' && icon.prefix && icon.iconName && icon.icon) {
|
286 | return icon;
|
287 | }
|
288 |
|
289 | if (parse.icon) {
|
290 | return parse.icon(icon);
|
291 | }
|
292 |
|
293 |
|
294 | if (icon === null) {
|
295 | return null;
|
296 | }
|
297 |
|
298 |
|
299 | if (icon && _typeof(icon) === 'object' && icon.prefix && icon.iconName) {
|
300 | return icon;
|
301 | }
|
302 |
|
303 |
|
304 | if (Array.isArray(icon) && icon.length === 2) {
|
305 |
|
306 | return {
|
307 | prefix: icon[0],
|
308 | iconName: icon[1]
|
309 | };
|
310 | }
|
311 |
|
312 |
|
313 | if (typeof icon === 'string') {
|
314 | return {
|
315 | prefix: 'fas',
|
316 | iconName: icon
|
317 | };
|
318 | }
|
319 | }
|
320 |
|
321 |
|
322 |
|
323 |
|
324 | function objectWithKey(key, value) {
|
325 |
|
326 |
|
327 |
|
328 |
|
329 | return Array.isArray(value) && value.length > 0 || !Array.isArray(value) && value ? _defineProperty({}, key, value) : {};
|
330 | }
|
331 |
|
332 | var _excluded = ["forwardedRef"];
|
333 | function FontAwesomeIcon(_ref) {
|
334 | var forwardedRef = _ref.forwardedRef,
|
335 | props = _objectWithoutProperties(_ref, _excluded);
|
336 |
|
337 | var iconArgs = props.icon,
|
338 | maskArgs = props.mask,
|
339 | symbol = props.symbol,
|
340 | className = props.className,
|
341 | title = props.title,
|
342 | titleId = props.titleId,
|
343 | maskId = props.maskId;
|
344 | var iconLookup = normalizeIconArgs(iconArgs);
|
345 | var classes = objectWithKey('classes', [].concat(_toConsumableArray(classList(props)), _toConsumableArray(className.split(' '))));
|
346 | var transform = objectWithKey('transform', typeof props.transform === 'string' ? parse.transform(props.transform) : props.transform);
|
347 | var mask = objectWithKey('mask', normalizeIconArgs(maskArgs));
|
348 | var renderedIcon = icon(iconLookup, _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, classes), transform), mask), {}, {
|
349 | symbol: symbol,
|
350 | title: title,
|
351 | titleId: titleId,
|
352 | maskId: maskId
|
353 | }));
|
354 |
|
355 | if (!renderedIcon) {
|
356 | log('Could not find icon', iconLookup);
|
357 | return null;
|
358 | }
|
359 |
|
360 | var abstract = renderedIcon.abstract;
|
361 | var extraProps = {
|
362 | ref: forwardedRef
|
363 | };
|
364 | Object.keys(props).forEach(function (key) {
|
365 |
|
366 | if (!FontAwesomeIcon.defaultProps.hasOwnProperty(key)) {
|
367 | extraProps[key] = props[key];
|
368 | }
|
369 | });
|
370 | return convertCurry(abstract[0], extraProps);
|
371 | }
|
372 | FontAwesomeIcon.displayName = 'FontAwesomeIcon';
|
373 | FontAwesomeIcon.propTypes = {
|
374 | beat: PropTypes.bool,
|
375 | border: PropTypes.bool,
|
376 | beatFade: PropTypes.bool,
|
377 | bounce: PropTypes.bool,
|
378 | className: PropTypes.string,
|
379 | fade: PropTypes.bool,
|
380 | flash: PropTypes.bool,
|
381 | mask: PropTypes.oneOfType([PropTypes.object, PropTypes.array, PropTypes.string]),
|
382 | maskId: PropTypes.string,
|
383 | fixedWidth: PropTypes.bool,
|
384 | inverse: PropTypes.bool,
|
385 | flip: PropTypes.oneOf([true, false, 'horizontal', 'vertical', 'both']),
|
386 | icon: PropTypes.oneOfType([PropTypes.object, PropTypes.array, PropTypes.string]),
|
387 | listItem: PropTypes.bool,
|
388 | pull: PropTypes.oneOf(['right', 'left']),
|
389 | pulse: PropTypes.bool,
|
390 | rotation: PropTypes.oneOf([0, 90, 180, 270]),
|
391 | shake: PropTypes.bool,
|
392 | size: PropTypes.oneOf(['2xs', 'xs', 'sm', 'lg', 'xl', '2xl', '1x', '2x', '3x', '4x', '5x', '6x', '7x', '8x', '9x', '10x']),
|
393 | spin: PropTypes.bool,
|
394 | spinPulse: PropTypes.bool,
|
395 | spinReverse: PropTypes.bool,
|
396 | symbol: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
397 | title: PropTypes.string,
|
398 | titleId: PropTypes.string,
|
399 | transform: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
|
400 | swapOpacity: PropTypes.bool
|
401 | };
|
402 | FontAwesomeIcon.defaultProps = {
|
403 | border: false,
|
404 | className: '',
|
405 | mask: null,
|
406 | maskId: null,
|
407 | fixedWidth: false,
|
408 | inverse: false,
|
409 | flip: false,
|
410 | icon: null,
|
411 | listItem: false,
|
412 | pull: null,
|
413 | pulse: false,
|
414 | rotation: null,
|
415 | size: null,
|
416 | spin: false,
|
417 | spinPulse: false,
|
418 | spinReverse: false,
|
419 | beat: false,
|
420 | fade: false,
|
421 | beatFade: false,
|
422 | bounce: false,
|
423 | shake: false,
|
424 | symbol: false,
|
425 | title: '',
|
426 | titleId: null,
|
427 | transform: null,
|
428 | swapOpacity: false
|
429 | };
|
430 | var convertCurry = convert.bind(null, React.createElement);
|
431 |
|
432 | export { FontAwesomeIcon };
|