Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(checkbox-group): improve docs example #1627

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: '最大选中数量',
}
Loading