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