未验证 提交 9046bc52 编写于 作者: VK1688's avatar VK1688 提交者: Gitee

!10 feat: 新增 checkbox 中间态

Merge pull request !10 from chuion/feat-checkbox-indeterminate
<template>
<view class="u-checkbox" :style="[checkboxStyle]">
<view class="u-checkbox__icon-wrap" @tap="toggle" :class="[iconClass]" :style="[iconStyle]">
<u-icon class="u-checkbox__icon-wrap__icon" name="checkbox-mark" :size="checkboxIconSize" :color="iconColor" />
<u-icon v-if="indeterminate" class="u-checkbox__icon-wrap__icon" name="minus" :size="checkboxIconSize" :color="iconColor" />
<u-icon v-else class="u-checkbox__icon-wrap__icon" name="checkbox-mark" :size="checkboxIconSize" :color="iconColor" />
</view>
<view
class="u-checkbox__label"
......@@ -82,6 +83,11 @@ export default {
size: {
type: [String, Number],
default: ""
},
// 设置不确定状态,仅负责样式控制
indeterminate: {
type: Boolean,
default: false
}
},
data() {
......@@ -143,6 +149,7 @@ export default {
},
// checkbox内部的勾选图标,如果选中状态,为白色,否则为透明色即可
iconColor() {
if (this.indeterminate) return '#ffffff';
return this.valueCom ? "#ffffff" : "transparent";
},
iconClass() {
......@@ -151,6 +158,7 @@ export default {
if (this.valueCom == true) classes.push("u-checkbox__icon-wrap--checked");
if (this.isDisabled) classes.push("u-checkbox__icon-wrap--disabled");
if (this.valueCom && this.isDisabled) classes.push("u-checkbox__icon-wrap--disabled--checked");
if (this.indeterminate === true) classes.push('u-checkbox__icon-wrap--indeterminate')
// 支付宝小程序无法动态绑定一个数组类名,否则解析出来的结果会带有",",而导致失效
return classes.join(" ");
},
......@@ -305,6 +313,12 @@ export default {
&--disabled--checked {
color: #c8c9cc !important;
}
&--indeterminate {
color: #fff;
background-color: $u-type-primary;
border-color: $u-type-primary;
}
}
&__label {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册