UNPKG

3.18 kBJavaScriptView Raw
1'use strict';
2
3function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
4
5var PropTypes = require('prop-types');
6var styled = require('reakit/styled');
7var styled__default = _interopDefault(styled);
8var _get = _interopDefault(require('lodash/get'));
9require('./styled/index.js');
10var __chunk_1 = require('./chunk-c300b528.js');
11var parseIcons = require('./parseIcons.js');
12var React = require('react');
13var React__default = _interopDefault(React);
14var propTypeUtils = _interopDefault(require('airbnb-prop-types'));
15var styled$2 = require('./Icon/styled.js');
16
17var 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", {}); // @ts-ignore
32
33
34 var iconInfo = icons[newIcon];
35
36 if (type) {
37 // @ts-ignore
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 (// @ts-ignore
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};
67var iconPropTypes = {
68 a11yHidden: propTypeUtils.mutuallyExclusiveProps(PropTypes.bool, 'a11yHidden', 'a11yLabel'),
69 // eslint-disable-line
70 a11yLabel: propTypeUtils.mutuallyExclusiveProps(PropTypes.string, 'a11yHidden', 'a11yLabel'),
71 // eslint-disable-line
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 // eslint-disable-line
83 type: PropTypes.oneOf(['font-awesome', 'font-awesome-standalone'])
84};
85Icon.propTypes = iconPropTypes;
86var iconDefaultProps = {
87 children: null,
88 className: undefined,
89 color: undefined,
90 icon: undefined,
91 size: 'default',
92 type: undefined
93};
94Icon.defaultProps = iconDefaultProps; // @ts-ignore
95
96var C = styled.withTheme(Icon);
97
98exports.Icon = C;
99exports.iconDefaultProps = iconDefaultProps;
100exports.iconPropTypes = iconPropTypes;