UNPKG

2.78 kBJavaScriptView Raw
1import { bool, string, node, oneOfType, shape, number, arrayOf, object, oneOf } from 'prop-types';
2import { withTheme } from 'reakit/styled';
3import _get from 'lodash/get';
4import './styled/index.js';
5import { c as _objectWithoutPropertiesLoose, g as _extends } from './chunk-1f79df9b.js';
6import parseIcons from './parseIcons.js';
7import { createElement } from 'react';
8import propTypeUtils from 'airbnb-prop-types';
9import StyledIcon from './Icon/styled.js';
10
11var 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", {}); // @ts-ignore
26
27
28 var iconInfo = icons[newIcon];
29
30 if (type) {
31 // @ts-ignore
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 (// @ts-ignore
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};
61var iconPropTypes = {
62 a11yHidden: propTypeUtils.mutuallyExclusiveProps(bool, 'a11yHidden', 'a11yLabel'),
63 // eslint-disable-line
64 a11yLabel: propTypeUtils.mutuallyExclusiveProps(string, 'a11yHidden', 'a11yLabel'),
65 // eslint-disable-line
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 // eslint-disable-line
77 type: oneOf(['font-awesome', 'font-awesome-standalone'])
78};
79Icon.propTypes = iconPropTypes;
80var iconDefaultProps = {
81 children: null,
82 className: undefined,
83 color: undefined,
84 icon: undefined,
85 size: 'default',
86 type: undefined
87};
88Icon.defaultProps = iconDefaultProps; // @ts-ignore
89
90var C = withTheme(Icon);
91
92export { C as a, iconPropTypes as b, iconDefaultProps as c };