Skip to content

Commit

Permalink
docs(checkbox-group): improve docs example (#1627)
Browse files Browse the repository at this point in the history
  • Loading branch information
chouchouji committed May 20, 2024
1 parent 1985659 commit 039edaf
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
19 changes: 19 additions & 0 deletions packages/varlet-ui/src/checkbox-group/docs/en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,25 @@ const value = ref([])
</template>
```

### Maximum Number Of Checked

In a checkbox group, you can limit the maximum number of selections by setting `max`.

```html
<script setup>
import { ref } from 'vue'
const value = ref([])
</script>

<template>
<var-checkbox-group v-model="value" :max="1">
<var-checkbox :checked-value="0">Eat</var-checkbox>
<var-checkbox :checked-value="1">Sleep</var-checkbox>
</var-checkbox-group>
</template>
```

### Checkbox Validation

```html
Expand Down
19 changes: 19 additions & 0 deletions packages/varlet-ui/src/checkbox-group/docs/zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,25 @@ const value = ref([])
</template>
```

### 最大选中数量

在复选框组中,可以通过设置 `max` 属性来限制最大选中数量。

```html
<script setup>
import { ref } from 'vue'
const value = ref([])
</script>

<template>
<var-checkbox-group v-model="value" :max="1">
<var-checkbox :checked-value="0">吃饭</var-checkbox>
<var-checkbox :checked-value="1">睡觉</var-checkbox>
</var-checkbox-group>
</template>
```

### 复选框字段校验

```html
Expand Down
24 changes: 22 additions & 2 deletions packages/varlet-ui/src/checkbox-group/example/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,26 @@ const values = reactive({
value8: [],
value9: [],
value10: false,
value11: [],
group: null,
indeterminate: true,
})
const { value, value2, value3, value4, value5, value6, value7, value8, value9, group, value10, indeterminate } =
toRefs(values)
const {
value,
value2,
value3,
value4,
value5,
value6,
value7,
value8,
value9,
group,
value10,
value11,
indeterminate,
} = toRefs(values)
watchLang(use)
onThemeChange()
Expand Down Expand Up @@ -78,6 +92,12 @@ onThemeChange()
</var-checkbox-group>
<div class="relation">{{ t('currentValue') }} {{ value9 }}</div>

<app-type>{{ t('max') }}</app-type>
<var-checkbox-group v-model="value11" :max="1">
<var-checkbox :checked-value="0">{{ t('eat') }}</var-checkbox>
<var-checkbox :checked-value="1">{{ t('sleep') }}</var-checkbox>
</var-checkbox-group>

<app-type>{{ t('checkboxValidate') }}</app-type>
<var-checkbox v-model="value7" :rules="[(v) => v || t('checkboxValidateMessage')]">
{{ t('currentValue') }} {{ value7 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export default {
indeterminate: 'Indeterminate',
indeterminateValue: 'Current value:',
toggle: 'Toggle',
max: 'Maximum Number Of Checked',
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export default {
indeterminate: '不确定状态',
indeterminateValue: '不确定状态的值:',
toggle: '切换',
max: '最大选中数量',
}

0 comments on commit 039edaf

Please sign in to comment.