From a6a733f735fefd693e5214ffa03cbaff9461b9ea Mon Sep 17 00:00:00 2001 From: neverland Date: Sun, 17 Feb 2019 08:39:05 +0800 Subject: [PATCH] [improvement] icon: tsx (#2767) --- packages/icon/{index.js => index.tsx} | 19 +++++++++++++++---- packages/utils/use/sfc.ts | 5 ++++- 2 files changed, 19 insertions(+), 5 deletions(-) rename packages/icon/{index.js => index.tsx} (67%) diff --git a/packages/icon/index.js b/packages/icon/index.tsx similarity index 67% rename from packages/icon/index.js rename to packages/icon/index.tsx index 71bc515e7..93dd0fd53 100644 --- a/packages/icon/index.js +++ b/packages/icon/index.tsx @@ -3,9 +3,12 @@ import { inherit } from '../utils/functional'; import Info from '../info'; import isSrc from '../utils/validate/src'; +// Types +import { FunctionalComponent } from '../utils/use/sfc'; + const [sfc] = use('icon'); -function Icon(h, props, slots, ctx) { +const Icon: FunctionalComponent = function(h, props, slots, ctx) { const urlIcon = isSrc(props.name); return ( @@ -20,12 +23,20 @@ function Icon(h, props, slots, ctx) { }} {...inherit(ctx, true)} > - {ctx.default && ctx.default()} + {slots.default && slots.default()} {urlIcon && } ); -} +}; + +export type IconProps = { + name: string; + size?: string; + color?: string; + info?: string | number; + classPrefix?: string; +}; Icon.props = { name: String, @@ -38,4 +49,4 @@ Icon.props = { } }; -export default sfc(Icon); +export default sfc(Icon); diff --git a/packages/utils/use/sfc.ts b/packages/utils/use/sfc.ts index bedd34142..ada6db151 100644 --- a/packages/utils/use/sfc.ts +++ b/packages/utils/use/sfc.ts @@ -29,7 +29,10 @@ export type FunctionalComponent< ( h: CreateElement, props: Props, - slots: { [key: string]: ScopedSlot | undefined }, + slots: { + [key: string]: ScopedSlot | undefined + default: ScopedSlot | undefined + }, context: RenderContext ): VNode; props?: PropDefs;