UNPKG

2.02 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _react = require('react');
8
9var _react2 = _interopRequireDefault(_react);
10
11var _propTypes = require('prop-types');
12
13var _propTypes2 = _interopRequireDefault(_propTypes);
14
15var _generatedList = require('../../assets/icons/generated-list');
16
17function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
19var Icon = function Icon(props) {
20 var name = props.name,
21 width = props.width,
22 height = props.height,
23 fill = props.fill,
24 className = props.className,
25 onClick = props.onClick;
26
27
28 var obj = _generatedList.paths.find(function (item) {
29 return item.name === name;
30 });
31
32 var createMarkup = function createMarkup(data) {
33 return { __html: data };
34 };
35
36 var getData = function getData() {
37 if (obj === undefined) return;
38
39 var data = obj !== undefined && obj.data;
40
41 return data;
42 };
43
44 return _react2.default.createElement('svg', {
45 role: 'img',
46 name: name,
47 width: width,
48 height: height,
49 fill: fill,
50 className: className,
51 onClick: onClick,
52 style: onClick && { cursor: 'pointer' },
53 viewBox: '0 0 24 24'
54 // We control the exact content being injected here,
55 // thus this is considered to be "safe" injection
56 // See scripts/gen-sprite.js for details
57 , dangerouslySetInnerHTML: createMarkup(getData()) });
58};
59
60Icon.defaultProps = {
61 height: '24',
62 width: '24'
63};
64
65Icon.propTypes = {
66 /**
67 * The name of the icon.
68 */
69 name: _propTypes2.default.string.isRequired,
70 /**
71 * The width of the icon.
72 */
73 width: _propTypes2.default.string,
74 /**
75 * The height of the icon.
76 */
77 height: _propTypes2.default.string,
78 /**
79 * The color (fill) of the icon.
80 */
81 fill: _propTypes2.default.string,
82 /**
83 * The CSS class of the icon.
84 */
85 className: _propTypes2.default.string,
86 /**
87 * A function to be called on click
88 */
89 onClick: _propTypes2.default.func
90};
91
92exports.default = Icon;
\No newline at end of file