mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[improvement] icon: tsx (#2767)
This commit is contained in:
parent
2ebcf2a36a
commit
a6a733f735
@ -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);
|
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user