[Improvement] ContactCard add 'editable' prop (#435)

This commit is contained in:
neverland 2017-12-14 14:44:27 +08:00 committed by GitHub
parent e008aa124d
commit 5a96838326
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 2 deletions

View File

@ -47,6 +47,7 @@ Locale.add({
custom: '自定义', custom: '自定义',
loading: '加载状态', loading: '加载状态',
disabled: '禁用状态', disabled: '禁用状态',
uneditable: '不可编辑',
basicUsage: '基础用法', basicUsage: '基础用法',
advancedUsage: '高级用法' advancedUsage: '高级用法'
}, },
@ -67,6 +68,7 @@ Locale.add({
custom: 'Custom', custom: 'Custom',
loading: 'Loading', loading: 'Loading',
disabled: 'Disabled', disabled: 'Disabled',
uneditable: 'Uneditable',
basicUsage: 'Basic Usage', basicUsage: 'Basic Usage',
advancedUsage: 'Advanced Usage' advancedUsage: 'Advanced Usage'
} }

View File

@ -27,6 +27,15 @@
/> />
</van-popup> </van-popup>
</demo-block> </demo-block>
<demo-block :title="$t('uneditable')">
<van-contact-card
type="edit"
:name="list[0].name"
:tel="list[0].tel"
:editable="false"
/>
</demo-block>
</demo-section> </demo-section>
</template> </template>

View File

@ -119,6 +119,17 @@ export default {
}; };
``` ```
#### Uneditable
```html
<van-contact-card
type="edit"
name="张三"
tel="13000000000"
:editable="false"
/>
```
### ContactCard API ### ContactCard API
| Attribute | Description | Type | Default | Accepted Values | | Attribute | Description | Type | Default | Accepted Values |

View File

@ -118,6 +118,17 @@ export default {
}; };
``` ```
#### 不可编辑
```html
<van-contact-card
type="edit"
name="张三"
tel="13000000000"
:editable="false"
/>
```
### ContactCard API ### ContactCard API
| 参数 | 说明 | 类型 | 默认值 | 可选值 | | 参数 | 说明 | 类型 | 默认值 | 可选值 |

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="van-contact-card" :class="`van-contact-card--${type}`" v-on="$listeners"> <div class="van-contact-card" :class="[`van-contact-card--${type}`, { 'van-contact-card--uneditable': !editable }]" @click="onClick">
<div class="van-contact-card__content"> <div class="van-contact-card__content">
<template v-if="type === 'add'"> <template v-if="type === 'add'">
<icon class="van-contact-card__icon" name="add2" /> <icon class="van-contact-card__icon" name="add2" />
@ -13,7 +13,7 @@
</div> </div>
</template> </template>
</div> </div>
<icon class="van-contact-card__arrow" name="arrow" /> <icon v-if="editable" class="van-contact-card__arrow" name="arrow" />
</div> </div>
</template> </template>
@ -27,10 +27,22 @@ export default create({
tel: String, tel: String,
name: String, name: String,
addText: String, addText: String,
editable: {
type: Boolean,
default: true
},
type: { type: {
type: String, type: String,
default: 'add' default: 'add'
} }
},
methods: {
onClick(event) {
if (this.editable) {
this.$emit('click', event);
}
}
} }
}); });
</script> </script>

View File

@ -8,6 +8,12 @@
background-color: $active-color; background-color: $active-color;
} }
&--uneditable {
&:active {
background-color: $white;
}
}
&--add { &--add {
line-height: 40px; line-height: 40px;