import React from 'react'; import * as icons from './icons'; import styleMaps from './index.less'; type IconName = keyof typeof icons; interface IconProps { name?: IconName; size?: number; color?: string; svg?: string; [key: string]: any; } interface SvgProps { size?: number; color?: string; [key: string]: any; } interface ImgProps { url: string; width?: number; height?: number; [key: string]: any; } type IconSvgInterface = React.FC; export const IconSvg: IconSvgInterface = ({ size, color, children, ...props }) => { const styles = { fontSize: size ? size + 'px' : undefined, color, }; return ( {children} ); }; type IconImgInterface = React.FC; export const IconImg: IconImgInterface = ({ url, width, height, ...props }) => { const styles = { width, height, }; if (url) return ( ); return null; }; interface IconInterface extends React.FC { Svg: typeof IconSvg; Img: typeof IconImg; iconNames: IconName[]; } const Icon: IconInterface = ({ name, svg, size, color, ...props }) => { const svgContent = svg || (name ? icons[name] : ''); const styles = { fontSize: size ? size + 'px' : undefined, color, }; return ( ); }; export const iconNames = Object.keys(icons) as IconName[]; Icon.Svg = IconSvg; Icon.Img = IconImg; Icon.iconNames = iconNames; export default Icon;