[improvement] Functional components be just functions (#2735)

This commit is contained in:
neverland
2019-02-14 11:56:02 +08:00
committed by GitHub
parent 166397dad4
commit 5a9143c736
21 changed files with 704 additions and 674 deletions
+40 -40
View File
@@ -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);