feat: migrate ContactCard component

This commit is contained in:
chenjiahan
2020-08-17 15:31:00 +08:00
parent 6d13094a20
commit 41796b0616
2 changed files with 166 additions and 0 deletions
+55
View File
@@ -0,0 +1,55 @@
import { createNamespace } from '../utils';
import Cell from '../cell';
const [createComponent, bem, t] = createNamespace('contact-card');
export default createComponent({
props: {
tel: String,
name: String,
addText: String,
editable: {
type: Boolean,
default: true,
},
type: {
type: String,
default: 'add',
},
},
emits: ['click'],
setup(props, { emit }) {
function onClick(event) {
if (props.editable) {
emit('click', event);
}
}
function Content() {
if (props.type === 'add') {
return props.addText || t('addText');
}
return [
<div>{`${t('name')}${props.name}`}</div>,
<div>{`${t('tel')}${props.tel}`}</div>,
];
}
return () => (
<Cell
center
border={false}
isLink={props.editable}
class={bem([props.type])}
valueClass={bem('value')}
icon={props.type === 'edit' ? 'contact' : 'add-square'}
onClick={onClick}
>
{Content()}
</Cell>
);
},
});