vant/packages/vant/src/contact-card/ContactCard.tsx
2022-02-20 20:48:20 +08:00

58 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { defineComponent, type ExtractPropTypes } from 'vue';
import { truthProp, makeStringProp, createNamespace } from '../utils';
import { Cell } from '../cell';
const [name, bem, t] = createNamespace('contact-card');
export type ContactCardType = 'add' | 'edit';
const contactCardProps = {
tel: String,
name: String,
type: makeStringProp<ContactCardType>('add'),
addText: String,
editable: truthProp,
};
export type ContactCardProps = ExtractPropTypes<typeof contactCardProps>;
export default defineComponent({
name,
props: contactCardProps,
emits: ['click'],
setup(props, { emit }) {
const onClick = (event: MouseEvent) => {
if (props.editable) {
emit('click', event);
}
};
const renderContent = () => {
if (props.type === 'add') {
return props.addText || t('addContact');
}
return [
<div>{`${t('name')}${props.name}`}</div>,
<div>{`${t('tel')}${props.tel}`}</div>,
];
};
return () => (
<Cell
v-slots={{ title: renderContent }}
center
icon={props.type === 'edit' ? 'contact' : 'add-square'}
class={bem([props.type])}
border={false}
isLink={props.editable}
titleClass={bem('title')}
onClick={onClick}
/>
);
},
});