import React from 'react';
import { IconProps } from './types';
//TODO 按需加载？
const IconData = require.context('styles/icons/components', true);
const GetIconData = (name: string) => IconData(`./${name}`, true).default;

export const Icon = function(
    { name, color = '#101934', fillColorRule = '&&& path', size = 'small', ...rest }: IconProps,
    ref: any
) {
    const Component = GetIconData(name);
    return <Component fillColor={color} {...rest} ref={ref} fillColorRule={fillColorRule} size={size} />;
};

export default React.forwardRef(Icon);

//export default function({ name, color, ...rest }: IconProps) {
//    const Component = GetIconData(name);
//    return <Component {...rest} fillColor={color} />;
//}
