mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[improvement] ContactCard: tsx (#2781)
This commit is contained in:
parent
267b47ac54
commit
7b238ed1e7
@ -22,6 +22,10 @@ export type CellSlots = DefaultSlots & {
|
|||||||
'right-icon'?: ScopedSlot;
|
'right-icon'?: ScopedSlot;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type CellEvents = {
|
||||||
|
onClick(event: Event): void;
|
||||||
|
};
|
||||||
|
|
||||||
const [sfc, bem] = use('cell');
|
const [sfc, bem] = use('cell');
|
||||||
|
|
||||||
function Cell(
|
function Cell(
|
||||||
@ -102,4 +106,4 @@ Cell.props = {
|
|||||||
arrowDirection: String
|
arrowDirection: String
|
||||||
};
|
};
|
||||||
|
|
||||||
export default sfc<CellProps>(Cell);
|
export default sfc<CellProps, CellEvents>(Cell);
|
||||||
|
@ -2,9 +2,26 @@ import { use } from '../utils';
|
|||||||
import { emit, inherit } from '../utils/functional';
|
import { emit, inherit } from '../utils/functional';
|
||||||
import Cell from '../cell';
|
import Cell from '../cell';
|
||||||
|
|
||||||
|
// Types
|
||||||
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
|
import { DefaultSlots } from '../utils/use/sfc';
|
||||||
|
|
||||||
const [sfc, bem, t] = use('contact-card');
|
const [sfc, bem, t] = use('contact-card');
|
||||||
|
|
||||||
function ContactCard(h, props, slots, ctx) {
|
export type ContactCardProps = {
|
||||||
|
tel?: string;
|
||||||
|
name?: string;
|
||||||
|
type?: string;
|
||||||
|
addText?: string;
|
||||||
|
editable?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
function ContactCard(
|
||||||
|
h: CreateElement,
|
||||||
|
props: ContactCardProps,
|
||||||
|
slots: DefaultSlots,
|
||||||
|
ctx: RenderContext<ContactCardProps>
|
||||||
|
) {
|
||||||
const { type, editable } = props;
|
const { type, editable } = props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -15,7 +32,7 @@ function ContactCard(h, props, slots, ctx) {
|
|||||||
class={bem([type])}
|
class={bem([type])}
|
||||||
valueClass={bem('value')}
|
valueClass={bem('value')}
|
||||||
icon={type === 'edit' ? 'contact' : 'add-square'}
|
icon={type === 'edit' ? 'contact' : 'add-square'}
|
||||||
onClick={event => {
|
onClick={(event: Event) => {
|
||||||
if (editable) {
|
if (editable) {
|
||||||
emit(ctx, 'click', event);
|
emit(ctx, 'click', event);
|
||||||
}
|
}
|
||||||
@ -46,4 +63,4 @@ ContactCard.props = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default sfc(ContactCard);
|
export default sfc<ContactCardProps>(ContactCard);
|
@ -35,6 +35,8 @@ export interface VantComponentOptions extends ComponentOptions<Vue> {
|
|||||||
|
|
||||||
export type DefaultProps = Record<string, any>;
|
export type DefaultProps = Record<string, any>;
|
||||||
|
|
||||||
|
export type DefaultEvents = {};
|
||||||
|
|
||||||
export type FunctionalComponent<
|
export type FunctionalComponent<
|
||||||
Props = DefaultProps,
|
Props = DefaultProps,
|
||||||
PropDefs = PropsDefinition<Props>
|
PropDefs = PropsDefinition<Props>
|
||||||
@ -54,7 +56,9 @@ export type TsxBaseProps = {
|
|||||||
class?: any;
|
class?: any;
|
||||||
style?: any;
|
style?: any;
|
||||||
};
|
};
|
||||||
export type TsxComponent<T> = (props: T & TsxBaseProps) => VNode;
|
export type TsxComponent<Props, Events> = (
|
||||||
|
props: Props & Events & TsxBaseProps
|
||||||
|
) => VNode;
|
||||||
|
|
||||||
const arrayProp = {
|
const arrayProp = {
|
||||||
type: Array,
|
type: Array,
|
||||||
@ -110,9 +114,9 @@ function transformFunctionalComponent(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (name: string) => <T = DefaultProps>(
|
export default (name: string) => <Props = DefaultProps, Events = DefaultEvents>(
|
||||||
sfc: VantComponentOptions | FunctionalComponent
|
sfc: VantComponentOptions | FunctionalComponent
|
||||||
): TsxComponent<T> => {
|
): TsxComponent<Props, Events> => {
|
||||||
if (typeof sfc === 'function') {
|
if (typeof sfc === 'function') {
|
||||||
sfc = transformFunctionalComponent(sfc);
|
sfc = transformFunctionalComponent(sfc);
|
||||||
}
|
}
|
||||||
@ -129,5 +133,5 @@ export default (name: string) => <T = DefaultProps>(
|
|||||||
sfc.name = name;
|
sfc.name = name;
|
||||||
sfc.install = install;
|
sfc.install = install;
|
||||||
|
|
||||||
return sfc as TsxComponent<T>;
|
return sfc as TsxComponent<Props, Events>;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user