UNPKG

react-ions

Version:

An open source set of React components that implement Ambassador's Design and UX patterns.

92 lines (74 loc) 2.02 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); var _generatedList = require('../../assets/icons/generated-list'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var Icon = function Icon(props) { var name = props.name, width = props.width, height = props.height, fill = props.fill, className = props.className, onClick = props.onClick; var obj = _generatedList.paths.find(function (item) { return item.name === name; }); var createMarkup = function createMarkup(data) { return { __html: data }; }; var getData = function getData() { if (obj === undefined) return; var data = obj !== undefined && obj.data; return data; }; return _react2.default.createElement('svg', { role: 'img', name: name, width: width, height: height, fill: fill, className: className, onClick: onClick, style: onClick && { cursor: 'pointer' }, viewBox: '0 0 24 24' // We control the exact content being injected here, // thus this is considered to be "safe" injection // See scripts/gen-sprite.js for details , dangerouslySetInnerHTML: createMarkup(getData()) }); }; Icon.defaultProps = { height: '24', width: '24' }; Icon.propTypes = { /** * The name of the icon. */ name: _propTypes2.default.string.isRequired, /** * The width of the icon. */ width: _propTypes2.default.string, /** * The height of the icon. */ height: _propTypes2.default.string, /** * The color (fill) of the icon. */ fill: _propTypes2.default.string, /** * The CSS class of the icon. */ className: _propTypes2.default.string, /** * A function to be called on click */ onClick: _propTypes2.default.func }; exports.default = Icon;