import React from 'react'; import {IconContext} from './iconContext'; export interface IconBaseProps extends React.SVGAttributes { children?: React.ReactNode; size?: string | number; color?: string; title?: string; } export interface IconTree { tag: string; attr: {[key: string]: string}; child: IconTree[] | undefined; } export function GenIcon(data: IconTree) { return function GenIconInner(props: IconBaseProps) { return ( {Tree2Element(data.child)} ); }; } export interface IconBaseProps extends React.SVGAttributes { children?: React.ReactNode; size?: string | number; color?: string; title?: string; } export type IconType = (props: IconBaseProps) => React.ReactNode; export function IconBase(props: IconBaseProps & {attr?: Record}): React.ReactElement { const elem = (conf: IconContext) => { const {attr, size, title, ...svgProps} = props; const computedSize = size || conf.size || '1em'; let className; if (conf.className) className = conf.className; if (props.className) className = (className ? className + ' ' : '') + props.className; return ( {title && {title}} {props.children} ); }; return {(conf: IconContext) => elem(conf)}; } function Tree2Element(tree: IconTree[] | undefined): React.ReactElement[] | undefined { return tree?.map((node, i) => React.createElement(node.tag, {key: i, ...node.attr}, Tree2Element(node.child))); }