@braineet/ui
Version:
Braineet design system
48 lines (46 loc) • 1.71 kB
JavaScript
var _excluded = ["name", "size", "color", "className"];
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
/* eslint-disable no-param-reassign */
import React from 'react';
import { useTheme } from 'styled-components';
import { fluid } from '../../utils';
import * as icons from './icons';
/**
* The `Icon` component.
*/
import { jsx as _jsx } from "react/jsx-runtime";
var iconList = _extends({}, icons);
var Icon = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
var name = _ref.name,
size = _ref.size,
color = _ref.color,
className = _ref.className,
restProps = _objectWithoutPropertiesLoose(_ref, _excluded);
var theme = useTheme();
var IconContent = iconList[name];
if (name === null || typeof name === 'undefined' || typeof IconContent === 'undefined') {
return null;
}
if (typeof name !== 'string') {
return name;
}
var iconColor = theme.helpers.getIconColor(color);
return /*#__PURE__*/_jsx(IconContent, _extends({
ref: ref,
className: className,
color: iconColor,
style: {
width: fluid(size),
height: fluid(size),
flexShrink: 0
},
"aria-hidden": "true",
focusable: "false"
}, restProps));
});
Icon.defaultProps = {
size: 24,
color: 'currentColor'
};
export default Icon;