feat(ContactList): refactor style & add new prop defaultTagText (#5089)

This commit is contained in:
rex 2019-11-26 20:44:35 +08:00 committed by neverland
parent c58f8e54ba
commit 592bcafda0
7 changed files with 88 additions and 47 deletions

View File

@ -155,6 +155,7 @@ export default {
| v-model | Id of chosen contact | *string \| number* | - | - | | v-model | Id of chosen contact | *string \| number* | - | - |
| list | Contact list | *Contact[]* | `[]` | - | | list | Contact list | *Contact[]* | `[]` | - |
| add-text | Add button text | *string* | `Add new contact` | - | | add-text | Add button text | *string* | `Add new contact` | - |
| default-tag-text | Default tag text | *string* | - | - |
### ContactList Events ### ContactList Events
@ -164,6 +165,7 @@ export default {
| edit | Triggered when click edit button | item: contact objectindex | | edit | Triggered when click edit button | item: contact objectindex |
| select | Triggered when select contact | item: contact object | | select | Triggered when select contact | item: contact object |
### ContactEdit Props ### ContactEdit Props
| Attribute | Description | Type | Default | Version | | Attribute | Description | Type | Default | Version |
@ -190,3 +192,4 @@ export default {
| id | ID | *string \| number* | | id | ID | *string \| number* |
| name | Name | *string* | | name | Name | *string* |
| tel | Phone | *string* | | tel | Phone | *string* |
| isDefault | Is default contact | *boolean* |

View File

@ -159,6 +159,7 @@ export default {
| v-model | 当前选中联系人的 id | *string \| number* | - | - | | v-model | 当前选中联系人的 id | *string \| number* | - | - |
| list | 联系人列表 | *Contact[]* | `[]` | - | | list | 联系人列表 | *Contact[]* | `[]` | - |
| add-text | 新建按钮文案 | *string* | `新建联系人` | - | | add-text | 新建按钮文案 | *string* | `新建联系人` | - |
| default-tag-text | 默认联系人标签文案 | *string* | - | - |
### ContactList Events ### ContactList Events
@ -194,3 +195,4 @@ export default {
| id | 每位联系人的唯一标识 | *string \| number* | | id | 每位联系人的唯一标识 | *string \| number* |
| name | 联系人姓名 | *string* | | name | 联系人姓名 | *string* |
| tel | 联系人手机号 | *string \| number* | | tel | 联系人手机号 | *string \| number* |
| isDefault | 是否为默认联系人 | *boolean* |

View File

@ -16,6 +16,7 @@
<van-contact-list <van-contact-list
v-model="chosenContactId" v-model="chosenContactId"
:list="list" :list="list"
:default-tag-text="$t('defaultTagText')"
@add="onAdd" @add="onAdd"
@edit="onEdit" @edit="onEdit"
@select="onSelect" @select="onSelect"
@ -54,11 +55,13 @@ export default {
i18n: { i18n: {
'zh-CN': { 'zh-CN': {
name: '张三', name: '张三',
defaultLabel: '设为默认联系人' defaultLabel: '设为默认联系人',
defaultTagText: '默认'
}, },
'en-US': { 'en-US': {
name: 'John Snow', name: 'John Snow',
defaultLabel: 'Set as the default contact' defaultLabel: 'Set as the default contact',
defaultTagText: 'default'
} }
}, },
@ -78,7 +81,8 @@ export default {
return { return {
name: this.$t('name'), name: this.$t('name'),
tel: '13000000000', tel: '13000000000',
id: 0 id: 0,
isDefault: 1
}; };
}, },

View File

@ -11,16 +11,16 @@ exports[`renders demo correctly 1`] = `
<div class="van-popup van-popup--bottom" style="display: none;" name="van-popup-slide-bottom"> <div class="van-popup van-popup--bottom" style="display: none;" name="van-popup-slide-bottom">
<div class="van-contact-list"> <div class="van-contact-list">
<div role="radiogroup" class="van-radio-group van-contact-list__group"> <div role="radiogroup" class="van-radio-group van-contact-list__group">
<div role="button" tabindex="0" class="van-cell van-cell--clickable van-contact-list__item"> <div role="button" tabindex="0" class="van-cell van-cell--clickable van-cell--center van-contact-list__item"><i class="van-icon van-icon-edit van-contact-list__edit">
<div class="van-cell__value van-cell__value--alone van-contact-list__item-value"> <!----></i>
<div class="van-cell__value van-cell__value--alone van-contact-list__item-value">张三13000000000<span class="van-tag van-tag--round van-tag--danger van-contact-list__item-tag">默认</span></div>
<div role="radio" tabindex="-1" aria-checked="false" class="van-radio"> <div role="radio" tabindex="-1" aria-checked="false" class="van-radio">
<div class="van-radio__icon van-radio__icon--round" style="font-size: 16px;"><i class="van-icon van-icon-success"> <div class="van-radio__icon van-radio__icon--round" style="font-size: 16px;"><i class="van-icon van-icon-success">
<!----></i></div><span class="van-radio__label"><div class="van-contact-list__name">张三13000000000</div></span> <!----></i></div>
</div> </div>
</div><i class="van-icon van-icon-edit van-contact-list__edit">
<!----></i>
</div> </div>
</div><button class="van-button van-button--danger van-button--large van-button--square van-contact-list__add"><span class="van-button__text">新建联系人</span></button> </div>
<div class="van-contact-list__bottom"><button class="van-button van-button--danger van-button--normal van-button--block van-button--round van-contact-list__add"><span class="van-button__text">新建联系人</span></button></div>
</div> </div>
</div> </div>
<div class="van-popup van-popup--bottom" style="display: none;" name="van-popup-slide-bottom"> <div class="van-popup van-popup--bottom" style="display: none;" name="van-popup-slide-bottom">

View File

@ -3,15 +3,15 @@
exports[`ContactList render 1`] = ` exports[`ContactList render 1`] = `
<div class="van-contact-list"> <div class="van-contact-list">
<div role="radiogroup" class="van-radio-group van-contact-list__group"> <div role="radiogroup" class="van-radio-group van-contact-list__group">
<div role="button" tabindex="0" class="van-cell van-cell--clickable van-contact-list__item"> <div role="button" tabindex="0" class="van-cell van-cell--clickable van-cell--center van-contact-list__item"><i class="van-icon van-icon-edit van-contact-list__edit">
<div class="van-cell__value van-cell__value--alone van-contact-list__item-value"> <!----></i>
<div class="van-cell__value van-cell__value--alone van-contact-list__item-value">test123123213</div>
<div role="radio" tabindex="0" aria-checked="true" class="van-radio"> <div role="radio" tabindex="0" aria-checked="true" class="van-radio">
<div class="van-radio__icon van-radio__icon--round van-radio__icon--checked" style="font-size: 16px;"><i class="van-icon van-icon-success" style="border-color: #ee0a24; background-color: rgb(238, 10, 36);"> <div class="van-radio__icon van-radio__icon--round van-radio__icon--checked" style="font-size: 16px;"><i class="van-icon van-icon-success" style="border-color: #ee0a24; background-color: rgb(238, 10, 36);">
<!----></i></div><span class="van-radio__label"><div class="van-contact-list__name">test123123213</div></span> <!----></i></div>
</div> </div>
</div><i class="van-icon van-icon-edit van-contact-list__edit">
<!----></i>
</div> </div>
</div><button class="van-button van-button--danger van-button--large van-button--square van-contact-list__add"><span class="van-button__text">新建联系人</span></button> </div>
<div class="van-contact-list__bottom"><button class="van-button van-button--danger van-button--normal van-button--block van-button--round van-contact-list__add"><span class="van-button__text">新建联系人</span></button></div>
</div> </div>
`; `;

View File

@ -10,7 +10,18 @@
} }
&__item-value { &__item-value {
display: flex;
align-items: center;
padding-right: @padding-xl; padding-right: @padding-xl;
padding-left: @padding-xs;
}
&__item-tag {
flex: none;
margin-left: @padding-xs;
padding-top: 0;
padding-bottom: 0;
line-height: 1.4em;
} }
&__group { &__group {
@ -20,24 +31,22 @@
-webkit-overflow-scrolling: touch; -webkit-overflow-scrolling: touch;
} }
&__name {
font-weight: @font-weight-bold;
font-size: @font-size-md;
line-height: 20px;
}
&__edit { &__edit {
position: absolute;
top: 50%;
right: @padding-md;
font-size: @contact-list-edit-icon-size; font-size: @contact-list-edit-icon-size;
transform: translate(0, -50%);
} }
&__add { &__bottom {
position: fixed; position: fixed;
right: 0;
bottom: 0; bottom: 0;
left: 0; left: 0;
z-index: @contact-list-add-button-z-index; z-index: @contact-list-add-button-z-index;
padding: 5px 16px;
background-color: #fff;
}
&__add {
height: 40px;
line-height: 38px;
} }
} }

View File

@ -3,6 +3,7 @@ import { RED } from '../utils/constant';
import { emit, inherit } from '../utils/functional'; import { emit, inherit } from '../utils/functional';
import Icon from '../icon'; import Icon from '../icon';
import Cell from '../cell'; import Cell from '../cell';
import Tag from '../tag';
import Button from '../button'; import Button from '../button';
import Radio from '../radio'; import Radio from '../radio';
import RadioGroup from '../radio-group'; import RadioGroup from '../radio-group';
@ -15,12 +16,14 @@ export type ContactListItem = {
id: string | number; id: string | number;
tel: string | number; tel: string | number;
name: string; name: string;
isDefault: boolean;
}; };
export type ContactListProps = { export type ContactListProps = {
value?: any; value?: any;
list?: ContactListItem[]; list?: ContactListItem[];
addText?: string; addText?: string;
defaultTagText?: string;
}; };
const [createComponent, bem, t] = createNamespace('contact-list'); const [createComponent, bem, t] = createNamespace('contact-list');
@ -39,15 +42,18 @@ function ContactList(
emit(ctx, 'select', item, index); emit(ctx, 'select', item, index);
} }
function Content() { function RightIcon() {
return ( return (
<Radio name={item.id} iconSize={16} checkedColor={RED} onClick={onClick}> <Radio
<div class={bem('name')}>{`${item.name}${item.tel}`}</div> name={item.id}
</Radio> iconSize={16}
checkedColor={RED}
onClick={onClick}
/>
); );
} }
function RightIcon() { function LeftIcon() {
return ( return (
<Icon <Icon
name="edit" name="edit"
@ -60,15 +66,29 @@ function ContactList(
); );
} }
function Content() {
return [
`${item.name}${item.tel}`,
item.isDefault && props.defaultTagText && (
<Tag type="danger" round class={bem('item-tag')}>
{props.defaultTagText}
</Tag>
)
];
}
return ( return (
<Cell <Cell
key={item.id} key={item.id}
isLink isLink
center
class={bem('item')} class={bem('item')}
valueClass={bem('item-value')} valueClass={bem('item-value')}
// @ts-ignore
scopedSlots={{ scopedSlots={{
default: Content, default: Content,
'right-icon': RightIcon 'right-icon': RightIcon,
icon: LeftIcon
}} }}
onClick={onClick} onClick={onClick}
/> />
@ -80,9 +100,10 @@ function ContactList(
<RadioGroup value={props.value} class={bem('group')}> <RadioGroup value={props.value} class={bem('group')}>
{List} {List}
</RadioGroup> </RadioGroup>
<div class={bem('bottom')}>
<Button <Button
square round
size="large" block
type="danger" type="danger"
class={bem('add')} class={bem('add')}
text={props.addText || t('addText')} text={props.addText || t('addText')}
@ -91,13 +112,15 @@ function ContactList(
}} }}
/> />
</div> </div>
</div>
); );
} }
ContactList.props = { ContactList.props = {
value: null as any, value: null as any,
list: Array, list: Array,
addText: String addText: String,
defaultTagText: String
}; };
export default createComponent(ContactList); export default createComponent(ContactList);