From 4dd41b23decbaf86c8812e0afcc1d72773f223f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=98=89=E6=B6=B5?= Date: Mon, 10 Feb 2020 19:02:30 +0800 Subject: [PATCH] feat(RadioGroup): add direction prop --- src/mixins/checkbox.js | 15 +++++--- src/radio-group/index.js | 3 +- src/radio-group/index.less | 8 +++++ src/radio/README.md | 10 ++++++ src/radio/README.zh-CN.md | 12 +++++++ src/radio/demo/index.vue | 34 ++++++++++++++----- src/radio/index.less | 4 +++ .../test/__snapshots__/demo.spec.js.snap | 12 +++++++ 8 files changed, 85 insertions(+), 13 deletions(-) create mode 100644 src/radio-group/index.less diff --git a/src/mixins/checkbox.js b/src/mixins/checkbox.js index c57228f6b..11b7577a0 100644 --- a/src/mixins/checkbox.js +++ b/src/mixins/checkbox.js @@ -36,6 +36,10 @@ export const CheckboxMixin = ({ parent, bem, role }) => ({ return (this.parent && this.parent.disabled) || this.disabled; }, + direction() { + return (this.parent && this.parent.direction) || null; + }, + iconStyle() { const checkedColor = this.checkedColor || (this.parent && this.parent.checkedColor); @@ -120,10 +124,13 @@ export const CheckboxMixin = ({ parent, bem, role }) => ({ return (
+
{this.slots()}
); diff --git a/src/radio-group/index.less b/src/radio-group/index.less new file mode 100644 index 000000000..d8e478261 --- /dev/null +++ b/src/radio-group/index.less @@ -0,0 +1,8 @@ +@import '../style/var'; + +.van-radio-group { + &--horizontal { + display: flex; + flex-wrap: wrap; + } +} diff --git a/src/radio/README.md b/src/radio/README.md index ec0fbac49..f4628d757 100644 --- a/src/radio/README.md +++ b/src/radio/README.md @@ -33,6 +33,15 @@ export default { }; ``` +### Horizontal + +```html + + Radio 1 + Radio 2 + +``` + ### Disabled ```html @@ -150,6 +159,7 @@ export default { |------|------|------|------| | v-model (v-model) | Name of checked radio | *any* | - | | disabled | Disable all radios | *boolean* | `false` | +| direction `v2.5.0` | Direction, can be set to `horizontal` | *string* | `vertical` | | icon-size `v2.2.3` | Icon size of all radios | *number \| string* | `20px` | | checked-color `v2.2.3` | Checked color of all radios | *string* | `#1989fa` | - | diff --git a/src/radio/README.zh-CN.md b/src/radio/README.zh-CN.md index 29b50828d..908dc92b4 100644 --- a/src/radio/README.zh-CN.md +++ b/src/radio/README.zh-CN.md @@ -33,6 +33,17 @@ export default { }; ``` +### 水平排列 + +将`direction`属性设置为`horizontal`后,单选框组会变成水平排列 + +```html + + 单选框 1 + 单选框 2 + +``` + ### 禁用状态 通过`disabled`属性禁止选项切换,在`Radio`上设置`disabled`可以禁用单个选项 @@ -160,6 +171,7 @@ export default { |------|------|------|------| | v-model (value) | 当前选中项的标识符 | *any* | - | | disabled | 是否禁用所有单选框 | *boolean* | `false` | +| direction `v2.5.0` | 排列方向,可选值为`horizontal` | *string* | `vertical` | | icon-size `v2.2.3` | 所有单选框的图标大小,默认单位为`px` | *number \| string* | `20px` | | checked-color `v2.2.3` | 所有单选框的选中状态颜色 | *string* | `#1989fa` | diff --git a/src/radio/demo/index.vue b/src/radio/demo/index.vue index 1dadd8c0f..d9a22492e 100644 --- a/src/radio/demo/index.vue +++ b/src/radio/demo/index.vue @@ -7,6 +7,17 @@ + + + {{ $t('radio') }} 1 + {{ $t('radio') }} 2 + + + {{ $t('radio') }} 1 @@ -89,22 +100,24 @@ export default { radio: '单选框', text1: '未选中禁用', text2: '选中且禁用', + withCell: '与 Cell 组件一起使用', + horizontal: '水平排列', customIcon: '自定义图标', - customIconSize: '自定义大小', customColor: '自定义颜色', customShape: '自定义形状', - withCell: '与 Cell 组件一起使用', + customIconSize: '自定义大小', disabledLabelClick: '禁用文本点击', }, 'en-US': { radio: 'Radio', text1: 'Disabled', text2: 'Disabled and checked', + withCell: 'Inside a Cell', + horizontal: 'Hrizontal', customIcon: 'Custom Icon', - customIconSize: 'Custom Icon Size', customColor: 'Custom Color', customShape: 'Custom Shape', - withCell: 'Inside a Cell', + customIconSize: 'Custom Icon Size', disabledLabelClick: 'Disable the click event of label', }, }, @@ -117,8 +130,9 @@ export default { radio4: '1', radio5: '1', radioLabel: '1', - radioIconSize: '1', radioShape: '1', + radioIconSize: '1', + radioHorizontal: '1', icon: { active: 'https://img.yzcdn.cn/vant/user-active.png', inactive: 'https://img.yzcdn.cn/vant/user-inactive.png', @@ -135,15 +149,19 @@ export default { background: @white; &-group { - padding: 0 17px; + padding: 0 16px; - .van-radio:not(:last-child) { - margin-bottom: 10px; + .van-radio { + margin-bottom: 8px; } } img { height: 20px; } + + .van-doc-demo-block__title { + margin-top: -8px; + } } diff --git a/src/radio/index.less b/src/radio/index.less index 45d0e006a..1c5bcaa59 100644 --- a/src/radio/index.less +++ b/src/radio/index.less @@ -15,6 +15,10 @@ cursor: default; } + &--horizontal { + margin-right: 12px; + } + &__icon { flex: none; height: 1em; diff --git a/src/radio/test/__snapshots__/demo.spec.js.snap b/src/radio/test/__snapshots__/demo.spec.js.snap index 0b0b46527..747e04ca6 100644 --- a/src/radio/test/__snapshots__/demo.spec.js.snap +++ b/src/radio/test/__snapshots__/demo.spec.js.snap @@ -14,6 +14,18 @@ exports[`renders demo correctly 1`] = `
+
+
+ + +
+