1 | import { bool, string, node, oneOfType, shape, number, arrayOf, object, oneOf } from 'prop-types';
|
2 | import { withTheme } from 'reakit/styled';
|
3 | import _get from 'lodash/get';
|
4 | import './styled/index.js';
|
5 | import { c as _objectWithoutPropertiesLoose, g as _extends } from './chunk-1f79df9b.js';
|
6 | import parseIcons from './parseIcons.js';
|
7 | import { createElement } from 'react';
|
8 | import propTypeUtils from 'airbnb-prop-types';
|
9 | import StyledIcon from './Icon/styled.js';
|
10 |
|
11 | var Icon = function Icon(_ref) {
|
12 | var a11yHidden = _ref.a11yHidden,
|
13 | a11yLabel = _ref.a11yLabel,
|
14 | children = _ref.children,
|
15 | icon = _ref.icon,
|
16 | _size = _ref.size,
|
17 | theme = _ref.theme,
|
18 | type = _ref.type,
|
19 | props = _objectWithoutPropertiesLoose(_ref, ["a11yHidden", "a11yLabel", "children", "icon", "size", "theme", "type"]);
|
20 |
|
21 | var size = _get(theme, "fannypack.fontSizes[" + (_size || '') + "]", 1);
|
22 |
|
23 | var newIcon = _get(theme, "fannypack.Icon.iconNames[" + icon + "]") || icon;
|
24 |
|
25 | var icons = _get(theme, "fannypack.Icon.icons", {});
|
26 |
|
27 |
|
28 | var iconInfo = icons[newIcon];
|
29 |
|
30 | if (type) {
|
31 |
|
32 | var parsedIcons = parseIcons([icon], {
|
33 | type: type
|
34 | });
|
35 | iconInfo = Object.entries(parsedIcons)[0][1];
|
36 | } else if (typeof icon === 'object') {
|
37 | iconInfo = icon;
|
38 | }
|
39 |
|
40 | var _iconInfo = iconInfo,
|
41 | viewBoxWidth = _iconInfo.viewBoxWidth,
|
42 | viewBoxHeight = _iconInfo.viewBoxHeight,
|
43 | paths = _iconInfo.paths;
|
44 | return (
|
45 | createElement(StyledIcon, _extends({
|
46 | use: "svg",
|
47 | "aria-hidden": a11yHidden,
|
48 | role: "img",
|
49 | size: size,
|
50 | viewBox: "0 0 " + viewBoxWidth + " " + viewBoxHeight
|
51 | }, props), a11yLabel && createElement("title", null, a11yLabel), paths.map(function (path) {
|
52 | return createElement("path", {
|
53 | key: path,
|
54 | d: path,
|
55 | fill: "currentColor",
|
56 | fillRule: "evenodd"
|
57 | });
|
58 | }))
|
59 | );
|
60 | };
|
61 | var iconPropTypes = {
|
62 | a11yHidden: propTypeUtils.mutuallyExclusiveProps(bool, 'a11yHidden', 'a11yLabel'),
|
63 |
|
64 | a11yLabel: propTypeUtils.mutuallyExclusiveProps(string, 'a11yHidden', 'a11yLabel'),
|
65 |
|
66 | children: node,
|
67 | color: string,
|
68 | className: string,
|
69 | icon: oneOfType([string, shape({
|
70 | viewBoxHeight: number,
|
71 | viewBoxWidth: number,
|
72 | paths: arrayOf(string)
|
73 | })]),
|
74 | size: string,
|
75 | theme: object,
|
76 |
|
77 | type: oneOf(['font-awesome', 'font-awesome-standalone'])
|
78 | };
|
79 | Icon.propTypes = iconPropTypes;
|
80 | var iconDefaultProps = {
|
81 | children: null,
|
82 | className: undefined,
|
83 | color: undefined,
|
84 | icon: undefined,
|
85 | size: 'default',
|
86 | type: undefined
|
87 | };
|
88 | Icon.defaultProps = iconDefaultProps;
|
89 |
|
90 | var C = withTheme(Icon);
|
91 |
|
92 | export { C as a, iconPropTypes as b, iconDefaultProps as c };
|