[improvement] icon: tsx (#2767)

This commit is contained in:
neverland 2019-02-17 08:39:05 +08:00 committed by GitHub
parent 2ebcf2a36a
commit a6a733f735
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 5 deletions

View File

@ -3,9 +3,12 @@ import { inherit } from '../utils/functional';
import Info from '../info'; import Info from '../info';
import isSrc from '../utils/validate/src'; import isSrc from '../utils/validate/src';
// Types
import { FunctionalComponent } from '../utils/use/sfc';
const [sfc] = use('icon'); const [sfc] = use('icon');
function Icon(h, props, slots, ctx) { const Icon: FunctionalComponent<IconProps> = function(h, props, slots, ctx) {
const urlIcon = isSrc(props.name); const urlIcon = isSrc(props.name);
return ( return (
@ -20,12 +23,20 @@ function Icon(h, props, slots, ctx) {
}} }}
{...inherit(ctx, true)} {...inherit(ctx, true)}
> >
{ctx.default && ctx.default()} {slots.default && slots.default()}
{urlIcon && <img src={props.name} />} {urlIcon && <img src={props.name} />}
<Info info={props.info} /> <Info info={props.info} />
</i> </i>
); );
} };
export type IconProps = {
name: string;
size?: string;
color?: string;
info?: string | number;
classPrefix?: string;
};
Icon.props = { Icon.props = {
name: String, name: String,
@ -38,4 +49,4 @@ Icon.props = {
} }
}; };
export default sfc(Icon); export default sfc<IconProps>(Icon);

View File

@ -29,7 +29,10 @@ export type FunctionalComponent<
( (
h: CreateElement, h: CreateElement,
props: Props, props: Props,
slots: { [key: string]: ScopedSlot | undefined }, slots: {
[key: string]: ScopedSlot | undefined
default: ScopedSlot | undefined
},
context: RenderContext<Props> context: RenderContext<Props>
): VNode; ): VNode;
props?: PropDefs; props?: PropDefs;