From 6b8360c349cf515e090835c91c4594dca9292c48 Mon Sep 17 00:00:00 2001 From: HeskeyBaozi Date: Thu, 19 Jul 2018 19:23:33 +0800 Subject: [PATCH] add viewBox attr & create method can add extra props --- components/icon/CustomIcon.tsx | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/components/icon/CustomIcon.tsx b/components/icon/CustomIcon.tsx index 629b45461d..e156d374a5 100644 --- a/components/icon/CustomIcon.tsx +++ b/components/icon/CustomIcon.tsx @@ -5,28 +5,40 @@ import { Omit } from '../_util/type'; import { IconProps } from './index'; export interface CustomIconProps extends Omit { - src?: string; + viewBox?: string; + component?: React.ComponentType; +} + +export interface CustomIconComponentProps extends Omit { } const CustomIcon: React.SFC = (props) => { - const { className = '', spin, src, children } = props; + const { + className = '', + spin, + viewBox = '0 0 24 24', + children, + component: Component, + } = props; + const classString = classNames({ anticon: true, 'anticon-spin': !!spin, }, className); - if (typeof src === 'string' && src.length) { + if (Component) { return ( - + viewBox={viewBox} + > + {children} + ); } @@ -38,6 +50,7 @@ const CustomIcon: React.SFC = (props) => { height={'1em'} fill={'currentColor'} aria-hidden={'true'} + viewBox={viewBox} > {children} @@ -50,10 +63,11 @@ export interface CustomIconOptions { namespace?: string; prefix?: string; scriptLink?: string; + [key: string]: any; } export function create(options: CustomIconOptions = {}): React.ComponentClass { - const { namespace, prefix = '', scriptLink } = options; + const { namespace, prefix = '', scriptLink, ...extraCommonProps } = options; class Custom extends React.Component { render() { @@ -64,6 +78,7 @@ export function create(options: CustomIconOptions = {}): React.ComponentClass