@braineet/ui
Version:
Braineet design system
48 lines (46 loc) • 1.88 kB
JavaScript
var _excluded = ["name", "size", "color", "className"];
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, 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;