[Improvement] Radio: name support any types (#863)

This commit is contained in:
neverland 2018-04-12 15:45:28 +08:00 committed by GitHub
parent ec47c8d0d3
commit 7c84582d7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 49 additions and 74 deletions

View File

@ -1,30 +1,21 @@
<template> <template>
<demo-section> <demo-section>
<demo-block :title="$t('basicUsage')"> <demo-block :title="$t('basicUsage')">
<div class="van-radios"> <van-radio-group v-model="radio1" class="demo-radio-group">
<van-radio name="1" v-model="radio1">{{ $t('radio') }} 1</van-radio> <van-radio name="1">{{ $t('radio') }} 1</van-radio>
<van-radio name="2" v-model="radio1">{{ $t('radio') }} 2</van-radio> <van-radio name="2">{{ $t('radio') }} 2</van-radio>
</div> </van-radio-group>
</demo-block> </demo-block>
<demo-block :title="$t('disabled')"> <demo-block :title="$t('disabled')">
<div class="van-radios"> <van-radio-group v-model="radio2" class="demo-radio-group" disabled>
<van-radio name="1" v-model="radio2" disabled>{{ $t('text1') }}</van-radio> <van-radio name="1">{{ $t('radio') }} 1</van-radio>
<van-radio name="2" v-model="radio2" disabled>{{ $t('text2') }}</van-radio> <van-radio name="2">{{ $t('radio') }} 2</van-radio>
</div> </van-radio-group>
</demo-block> </demo-block>
<demo-block :title="$t('title3')"> <demo-block :title="$t('title3')">
<div class="van-radios"> <van-radio-group v-model="radio3">
<van-radio-group v-model="radio3">
<van-radio name="1">{{ $t('radio') }} 1</van-radio>
<van-radio name="2">{{ $t('radio') }} 2</van-radio>
</van-radio-group>
</div>
</demo-block>
<demo-block :title="$t('title4')">
<van-radio-group v-model="radio4">
<van-cell-group> <van-cell-group>
<van-cell><van-radio name="1">{{ $t('radio') }}1</van-radio></van-cell> <van-cell><van-radio name="1">{{ $t('radio') }}1</van-radio></van-cell>
<van-cell><van-radio name="2">{{ $t('radio') }}2</van-radio></van-cell> <van-cell><van-radio name="2">{{ $t('radio') }}2</van-radio></van-cell>
@ -41,15 +32,13 @@ export default {
radio: '单选框', radio: '单选框',
text1: '未选中禁用', text1: '未选中禁用',
text2: '选中且禁用', text2: '选中且禁用',
title3: 'Radio 组', title3: '与 Cell 组件一起使用'
title4: '与 Cell 组件一起使用'
}, },
'en-US': { 'en-US': {
radio: 'Radio', radio: 'Radio',
text1: 'Disabled', text1: 'Disabled',
text2: 'Disabled and checked', text2: 'Disabled and checked',
title3: 'Radio Group', title: 'Inside a Cell'
title4: 'Inside a Cell'
} }
}, },
@ -57,8 +46,7 @@ export default {
return { return {
radio1: '1', radio1: '1',
radio2: '2', radio2: '2',
radio3: '1', radio3: '1'
radio4: '1'
}; };
} }
}; };
@ -66,11 +54,11 @@ export default {
<style lang="postcss"> <style lang="postcss">
.demo-radio { .demo-radio {
.van-radios { &-group {
padding: 0 20px; padding: 0 17px;
.van-radio { .van-radio {
margin: 10px 0; margin-bottom: 10px;
} }
} }

View File

@ -83,12 +83,12 @@ export default {
</van-checkbox-group> </van-checkbox-group>
``` ```
### Checkbox API ### Checkbox API
| Attribute | Description | Type | Default | Accepted Values | | Attribute | Description | Type | Default | Accepted Values |
|-----------|-----------|-----------|-------------|-------------| |-----------|-----------|-----------|-------------|-------------|
| name | Checkbox name | `Boolean` | `false` | - | | v-model | Check status | `Boolean` | `false` | - |
| name | Checkbox name | `any` | - | - |
| disabled | Diable checkbox | `Boolean` | `false` | - | | disabled | Diable checkbox | `Boolean` | `false` | - |
| label-disabled | Whether to disable label click | `Boolean` | `false` | - | | label-disabled | Whether to disable label click | `Boolean` | `false` | - |
| shape | Checkbox shape | `String` | `round` | `square` | | shape | Checkbox shape | `String` | `round` | `square` |
@ -97,6 +97,7 @@ export default {
| Attribute | Description | Type | Default | Accepted Values | | Attribute | Description | Type | Default | Accepted Values |
|-----------|-----------|-----------|-------------|-------------| |-----------|-----------|-----------|-------------|-------------|
| v-model | Names of all checked checkboxes | `Array` | - | - |
| disabled | Disable all checkboxes | `Boolean` | `false` | - | | disabled | Disable all checkboxes | `Boolean` | `false` | - |
| max | Maximum amount of checked options | `Number` | `0`(Unlimited) | - | | max | Maximum amount of checked options | `Number` | `0`(Unlimited) | - |

View File

@ -10,11 +10,13 @@ Vue.use(Radio);
### Usage ### Usage
#### Basic Usage #### Basic Usage
Use `v-model` to bind check status of radio. The value will be set to the name of radio when radio get checked. Use `v-model` to bind the name of checked radio
```html ```html
<van-radio name="1" v-model="radio">Radio 1</van-radio> <van-radio-group v-model="radio">
<van-radio name="2" v-model="radio">Radio 2</van-radio> <van-radio name="1">Radio 1</van-radio>
<van-radio name="2">Radio 2</van-radio>
</van-radio-group>
``` ```
```javascript ```javascript
@ -30,16 +32,7 @@ export default {
#### Disabled #### Disabled
```html ```html
<van-radio name="1" v-model="radio" disabled>Disabled</van-radio> <van-radio-group v-model="radio" disabled>
<van-radio name="2" v-model="radio" disabled>Disabled and checked</van-radio>
```
#### Radio Group
When Radios are inside a RadioGroup, the checked radio's name is bound with CheckboxGroup by `v-model`.
```html
<van-radio-group v-model="radio">
<van-radio name="1">Radio 1</van-radio> <van-radio name="1">Radio 1</van-radio>
<van-radio name="2">Radio 2</van-radio> <van-radio name="2">Radio 2</van-radio>
</van-radio-group> </van-radio-group>
@ -60,13 +53,14 @@ When Radios are inside a RadioGroup, the checked radio's name is bound with Chec
| Attribute | Description | Type | Default | Accepted Values | | Attribute | Description | Type | Default | Accepted Values |
|-----------|-----------|-----------|-------------|-------------| |-----------|-----------|-----------|-------------|-------------|
| disabled | Diable radio | `Boolean` | `false` | - | | name | Radio name | `any` | - | - |
| name | Radio name | `Boolean` | `false` | - | | disabled | Whether to disable radio | `Boolean` | `false` | - |
### RadioGroup API ### RadioGroup API
| Attribute | Description | Type | Default | Accepted Values | | Attribute | Description | Type | Default | Accepted Values |
|-----------|-----------|-----------|-------------|-------------| |-----------|-----------|-----------|-------------|-------------|
| v-model | Name of checked radio | `any` | - | - |
| disabled | Diable all radios | `Boolean` | `false` | - | | disabled | Diable all radios | `Boolean` | `false` | - |
### RadioGroup Event ### RadioGroup Event

View File

@ -95,7 +95,8 @@ export default {
| 参数 | 说明 | 类型 | 默认值 | 可选值 | | 参数 | 说明 | 类型 | 默认值 | 可选值 |
|-----------|-----------|-----------|-------------|-------------| |-----------|-----------|-----------|-------------|-------------|
| name | 标识 Checkbox 名称 | `Boolean` | `false` | - | | v-model | 是否为选中状态 | `Boolean` | `false` | - |
| name | 标识 Checkbox 名称 | 任意类型 | - | - |
| disabled | 是否禁用单选框 | `Boolean` | `false` | - | | disabled | 是否禁用单选框 | `Boolean` | `false` | - |
| label-disabled | 是否禁用单选框内容点击 | `Boolean` | `false` | - | | label-disabled | 是否禁用单选框内容点击 | `Boolean` | `false` | - |
| shape | 形状 | `String` | `round` | `square` | | shape | 形状 | `String` | `round` | `square` |
@ -104,6 +105,7 @@ export default {
| 参数 | 说明 | 类型 | 默认值 | 可选值 | | 参数 | 说明 | 类型 | 默认值 | 可选值 |
|-----------|-----------|-----------|-------------|-------------| |-----------|-----------|-----------|-------------|-------------|
| v-model | 所有选中项的 name | `Array` | - | - |
| disabled | 是否禁用所有单选框 | `Boolean` | `false` | - | | disabled | 是否禁用所有单选框 | `Boolean` | `false` | - |
| max | 设置最大可选数 | `Number` | `0`(无限制) | - | | max | 设置最大可选数 | `Number` | `0`(无限制) | - |

View File

@ -10,12 +10,13 @@ Vue.use(Radio);
### 代码演示 ### 代码演示
#### 基础用法 #### 基础用法
通过`v-model`绑定值当前选中项的 name
通过`v-model`绑定值即可。当`Radio`选中时,绑定的值即为`Radio``name`属性设置的值。
```html ```html
<van-radio name="1" v-model="radio">单选框 1</van-radio> <van-radio-group v-model="radio">
<van-radio name="2" v-model="radio">单选框 2</van-radio> <van-radio name="1">单选框 1</van-radio>
<van-radio name="2">单选框 2</van-radio>
</van-radio-group>
``` ```
```javascript ```javascript
@ -29,28 +30,16 @@ export default {
``` ```
#### 禁用状态 #### 禁用状态
通过`disabled`属性禁止选项切换,在`van-radio`上设置`diabled`可以禁用单个选项
设置`disabled`属性即可,此时`Radio`不能点击。
```html ```html
<van-radio name="1" v-model="radio" disabled>未选中禁用</van-radio> <van-radio-group v-model="radio" disabled>
<van-radio name="2" v-model="radio" disabled>选中且禁用</van-radio>
```
#### Radio 组
需要与`van-radio-group`一起使用,在`van-radio-group`通过`v-model`来绑定当前选中的值。例如下面的`radio3`
```html
<van-radio-group v-model="radio">
<van-radio name="1">单选框 1</van-radio> <van-radio name="1">单选框 1</van-radio>
<van-radio name="2">单选框 2</van-radio> <van-radio name="2">单选框 2</van-radio>
</van-radio-group> </van-radio-group>
``` ```
#### 与 Cell 组件一起使用 #### 与 Cell 组件一起使用
此时你需要再引入`Cell``CellGroup`组件。 此时你需要再引入`Cell``CellGroup`组件。
```html ```html
@ -66,17 +55,18 @@ export default {
| 参数 | 说明 | 类型 | 默认值 | 可选值 | | 参数 | 说明 | 类型 | 默认值 | 可选值 |
|-----------|-----------|-----------|-------------|-------------| |-----------|-----------|-----------|-------------|-------------|
| disabled | 是否禁用单选框 | `Boolean` | `false` | - | | name | 唯一标识符 | 任意类型 | - | - |
| name | 根据这个来判断 radio 是否选中 | `Boolean` | `false` | - | | disabled | 是否为禁用状态 | `Boolean` | `false` | - |
### RadioGroup API ### RadioGroup API
| 参数 | 说明 | 类型 | 默认值 | 可选值 | | 参数 | 说明 | 类型 | 默认值 | 可选值 |
|-----------|-----------|-----------|-------------|-------------| |-----------|-----------|-----------|-------------|-------------|
| disabled | 是否禁用单选框 | `Boolean` | `false` | - | | v-model | 当前选中项的 name | 任意类型 | - | - |
| disabled | 是否禁用所有单选框 | `Boolean` | `false` | - |
### RadioGroup Event ### RadioGroup Event
| 事件名称 | 说明 | 回调参数 | | 事件名称 | 说明 | 回调参数 |
|-----------|-----------|-----------| |-----------|-----------|-----------|
| change | 当绑定值变化时触发的事件 | 当前组件的值 | | change | 当绑定值变化时触发的事件 | 当前选中项的 name |

View File

@ -11,7 +11,7 @@ export default create({
name: 'checkbox-group', name: 'checkbox-group',
props: { props: {
value: {}, value: null,
disabled: Boolean, disabled: Boolean,
max: { max: {
default: 0, default: 0,

View File

@ -27,13 +27,13 @@ export default create({
mixins: [findParent], mixins: [findParent],
props: { props: {
value: {}, name: null,
value: null,
disabled: Boolean, disabled: Boolean,
labelDisabled: { labelDisabled: {
type: Boolean, type: Boolean,
default: false default: false
}, },
name: [String, Number],
shape: { shape: {
type: String, type: String,
default: 'round' default: 'round'

View File

@ -11,7 +11,7 @@ export default create({
name: 'radio-group', name: 'radio-group',
props: { props: {
value: {}, value: null,
disabled: Boolean disabled: Boolean
}, },

View File

@ -30,9 +30,9 @@ export default create({
mixins: [findParent], mixins: [findParent],
props: { props: {
value: {}, name: null,
disabled: Boolean, value: null,
name: [String, Number] disabled: Boolean
}, },
computed: { computed: {