[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 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<IconProps> = 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 && <img src={props.name} />}
<Info info={props.info} />
</i>
);
}
};
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<IconProps>(Icon);

View File

@ -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<Props>
): VNode;
props?: PropDefs;