import React from 'react'; import svgPaths from '@uiw/icons/fonts/w-icon.json'; import './style/index.less'; export type IconsName = keyof typeof svgPaths; export type IconTagType = React.ElementType | keyof JSX.IntrinsicElements; type ElementProps = { fill?: string; style?: React.CSSProperties; className?: string; prefixCls?: string; /** * HTML tag to use for the rendered element. * @default "span" */ tagName?: T; type?: IconsName | null | E; spin?: boolean; color?: string; verticalAlign?: 'middle' | 'baseline'; }; export type IconProps = ElementProps & React.ComponentPropsWithoutRef; const Icon = (props: IconProps) => { const { className, prefixCls = 'w-icon', verticalAlign = 'middle', tagName: Element = 'span', color, type, spin = false, style, ...reset } = props; let svg = null; if (typeof type === 'string') { svg = ( {(svgPaths[type as IconsName] || []).map((d, i) => ( ))} ); } const initStyle = { fill: 'currentColor', ...style }; const cls = [ prefixCls, className, prefixCls && verticalAlign ? `${prefixCls}-${verticalAlign}` : null, spin && prefixCls ? `${prefixCls}-spin` : null, ] .filter(Boolean) .join(' ') .trim(); return ( {svg} ); }; export default Icon;