[improvement] Functional components be just functions (#2735)
This commit is contained in:
@@ -4,46 +4,46 @@ import Cell from '../cell';
|
||||
|
||||
const [sfc, bem, t] = use('contact-card');
|
||||
|
||||
export default sfc({
|
||||
functional: true,
|
||||
function ContactCard(h, props, slots, ctx) {
|
||||
const { type, editable } = props;
|
||||
|
||||
props: {
|
||||
tel: String,
|
||||
name: String,
|
||||
addText: String,
|
||||
editable: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
default: 'add'
|
||||
}
|
||||
return (
|
||||
<Cell
|
||||
center
|
||||
border={false}
|
||||
isLink={editable}
|
||||
class={bem([type])}
|
||||
valueClass={bem('value')}
|
||||
icon={type === 'edit' ? 'contact' : 'add-square'}
|
||||
onClick={event => {
|
||||
if (editable) {
|
||||
emit(ctx, 'click', event);
|
||||
}
|
||||
}}
|
||||
{...inherit(ctx)}
|
||||
>
|
||||
{type === 'add'
|
||||
? props.addText || t('addText')
|
||||
: [
|
||||
<div>{`${t('name')}:${props.name}`}</div>,
|
||||
<div>{`${t('tel')}:${props.tel}`}</div>
|
||||
]}
|
||||
</Cell>
|
||||
);
|
||||
}
|
||||
|
||||
ContactCard.props = {
|
||||
tel: String,
|
||||
name: String,
|
||||
addText: String,
|
||||
editable: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
|
||||
render(h, context) {
|
||||
const { props } = context;
|
||||
const { type, editable } = props;
|
||||
|
||||
return (
|
||||
<Cell
|
||||
center
|
||||
border={false}
|
||||
isLink={editable}
|
||||
class={bem([type])}
|
||||
valueClass={bem('value')}
|
||||
icon={type === 'edit' ? 'contact' : 'add-square'}
|
||||
onClick={event => {
|
||||
if (editable) {
|
||||
emit(context, 'click', event);
|
||||
}
|
||||
}}
|
||||
{...inherit(context)}
|
||||
>
|
||||
{type === 'add'
|
||||
? props.addText || t('addText')
|
||||
: [<div>{`${t('name')}:${props.name}`}</div>, <div>{`${t('tel')}:${props.tel}`}</div>]}
|
||||
</Cell>
|
||||
);
|
||||
type: {
|
||||
type: String,
|
||||
default: 'add'
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export default sfc(ContactCard);
|
||||
|
||||
Reference in New Issue
Block a user