2.0.3 • Published 5 months ago

@wu-component/wu-checkbox-button v2.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

Checkbox 多选

一组备选项中进行多选

基础用法

单独使用可以表示两种状态之间的切换,写在标签中的内容为 checkbox 按钮后的介绍。

::: demo

<template>
    <div style="display: flex; align-items: center;justify-content: space-around;padding: 16px">
        <wu-plus-checkbox label="测试4"></wu-plus-checkbox>
    </div>
</template>
<script>
</script>

:::

禁用

多选框不可用状态。

::: demo

<template>
    <div style="display: flex; align-items: center;justify-content: space-around;padding: 16px">
        <wu-plus-checkbox value="false" disabled="true" id="switchId1">测试</wu-plus-checkbox>
    </div>
</template>
<script>
</script>

:::

多选框组

适用于多个勾选框绑定到同一个数组的情景,通过是否勾选来表示这一组选项中选中的项。

::: demo

<template>
    <div style="display: flex; align-items: center;justify-content: space-around;padding: 16px">
        <wu-plus-checkbox-group value="['测试1']" id="checkoutBoxGroup">
            <wu-plus-checkbox label="测试1" style="margin-right: 8px"></wu-plus-checkbox>
            <wu-plus-checkbox label="测试2" style="margin-right: 8px"></wu-plus-checkbox>
            <wu-plus-checkbox label="测试3"></wu-plus-checkbox>
        </wu-plus-checkbox-group>
    </div>
</template>
<script>
</script>

:::

indeterminate 状态

indeterminate 属性用以表示 checkbox 的不确定状态,一般用于实现全选的效果

::: demo

<template>
    <div style="display: flex; align-items: center;justify-content: space-around;padding: 16px">
        <wu-plus-checkbox label="测试4" style="margin-right: 8px" indeterminate="true" id="indeterminate2"></wu-plus-checkbox>
        <wu-plus-checkbox-group value="['测试1']" id="checkoutBoxGroup2">
            <wu-plus-checkbox label="测试1" style="margin-right: 8px"></wu-plus-checkbox>
            <wu-plus-checkbox label="测试2" style="margin-right: 8px"></wu-plus-checkbox>
            <wu-plus-checkbox label="测试3"></wu-plus-checkbox>
        </wu-plus-checkbox-group>
    </div>
</template>
<script>
    let _groupIndex = 0
    const _groupValueList = [["测试1", "测试2"], ["测试1", "测试3"], ["测试1"], ["测试3"]]
    export default  {
        data() {
            return {
                indeterminate: false,
                value: ['测试1']
            }
        },
        mounted() {
            // 代码有些啰嗦,简单实现关联多选框选择
            const indeterminate = document.getElementById("indeterminate2");
            const checkoutBoxGroup = document.getElementById("checkoutBoxGroup2");
            indeterminate.addEventListener('change', (e) => {
                console.log(e.detail);
                if (e.detail.value) {
                    checkoutBoxGroup.setAttribute("value", ['测试1', '测试2', '测试3'])
                    indeterminate.setAttribute("indeterminate", "")
                    indeterminate.setAttribute("checked", true)
                } else {
                    indeterminate.setAttribute("indeterminate", "")
                    checkoutBoxGroup.setAttribute("value", [])
                    indeterminate.setAttribute("checked", false)
                }
            })
            checkoutBoxGroup.addEventListener("change", (e) => {
                const value = checkoutBoxGroup.getAttribute("value");
                if (value.length === 0) {
                    indeterminate.setAttribute("indeterminate", false)
                    indeterminate.setAttribute("checked", false);
                    return
                }
                if (value.length < 3) {
                    indeterminate.setAttribute("indeterminate", true)
                    return;
                }
                if (value.length === 3) {
                    indeterminate.setAttribute("indeterminate", false)
                    indeterminate.setAttribute("checked", true)
                }
                
            })
        }
    }
</script>

:::

checkbox Attributes

参数说明类型可选值默认值
checked是否选中Booleantrue、false--
disabled禁用Booleantrue、falsefalse
indeterminate中间态Booleantrue、falsefalse
size组件大小UISizemedium、small、minimini
namenameString----
labellabelString----

checkbox Event

事件名说明参数
change值修改(event: CustomEvent) => void

checkbox-group Attributes

参数说明类型可选值默认值
valueArray----
disabled禁用Booleantrue、falsefalse
size组件大小UISizemedium、small、minimini

checkbox-group Event

事件名说明参数
change值修改(event: CustomEvent) => void
2.0.3

5 months ago

2.0.1

1 year ago

2.0.0

1 year ago

1.11.8

1 year ago

1.11.7

1 year ago

1.11.6

1 year ago

1.11.4

1 year ago

1.11.3

1 year ago

1.11.1

1 year ago

1.11.0

1 year ago

1.10.6

1 year ago

1.10.5

1 year ago

1.10.4

1 year ago

1.10.3

1 year ago

1.10.2

1 year ago

1.10.1

1 year ago

1.10.0

1 year ago

1.9.24

2 years ago

1.9.22

2 years ago

1.9.21

2 years ago

1.9.20

2 years ago

1.9.18

2 years ago

1.9.17

2 years ago

1.9.1

2 years ago

1.8.0

2 years ago

1.7.0

2 years ago

1.6.1

2 years ago

1.6.0

2 years ago

1.5.0

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.0.1

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago