import React from 'react' import * as FeatherIcons from 'react-feather' import { SpaceProps, space, color as styledColor, BorderRadiusProps, borderRadius, } from 'styled-system' import { styled, css } from '@styled-components' import { NewColorProps as ColorProps } from '../../utils/color-props.js' import { cssClass } from '../../utils/css-class.js' /** * Prop Types of an Icon component. * Apart from props defined below it extends all {@link ColorProps} and {@link SpaceProps} * * @memberof Icon * @alias IconProps * @property {string} [...] Other props from {@link ColorProps} and {@link SpaceProps} */ export type IconProps = SpaceProps & BorderRadiusProps & ColorProps & { /** * CamelCased name of an icon from https://feathericons.com/ */ icon?: keyof typeof FeatherIcons | string /** * Size variant. Default to 16 */ size?: number /** * Icon color */ color?: string /** * Icon background */ bg?: string /** * If background should be rounded */ rounded?: boolean /** * Indicates if given icons should spin */ spin?: boolean } const spinCss = css` @keyframes iconSpin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } animation-name: iconSpin; animation-duration: 1000ms; animation-iteration-count: infinite; animation-timing-function: linear; ` const Wrapper = styled.span` vertical-align: middle; display: inline-block; line-height: ${({ theme }) => theme.lineHeights.sm}; font-size: ${({ theme }) => theme.fontSizes.sm}; & > svg { stroke: ${({ theme, color }) => (color && color !== 'inherit' ? theme.colors[color] : 'currentColor')}; ${({ spin }) => (spin ? spinCss : '')}; } ${({ rounded }) => (rounded ? 'border-radius: 9999px;' : '')}; ${space}; ${styledColor}; ${borderRadius} ` /** * @classdesc * * * * Component wrapping [react-feather](https://www.npmjs.com/package/react-feather). * List of all icons can be found here: https://feathericons.com/ * If you have problem verifying the key of given icon - you can always open the * Chrome Terminal (with AdminJS open) and write there: * * ``` * Object.keys(window.FeatherIcons) * ``` * * to see list of all available icon keys. * * ### Usage * * ```javascript * import { Icon, IconProps } from '@adminjs/design-system' * ``` * * @component * @subcategory Atoms * @see IconProps * @see {@link https://storybook.adminjs.co/?path=/story/designsystem-atoms-icon--default Storybook} * @hideconstructor * @example Icons inside other elements * return ( * * * * * ) * @example Different sizes * const sizes = [16, 20, 24, 32] * return ( * * {sizes.map(size => ( * * ))} * * ) * * @example Big rounded icon with background * return ( * * * * ) * @section design-system */ const Icon: React.FC = (props) => { const { icon, size = 16, color = 'inherit', ...other } = props if (!icon) return null const FeatherIcon = FeatherIcons[icon] || FeatherIcons.Slash if (FeatherIcon) { return ( ) } return null } export { Icon } export default Icon