Skip to content

Checkbox 复选

查看 sn-checkbox 的 2.0 版本差异

基础用法

  • 复选组件由三部分组成:sn-checkbox-group(复选组,管理选中状态与组级配置)、sn-checkbox(方框形态选项)、sn-checkbox-tag(标签形态选项)。
  • sn-checkbox-groupv-model 绑定一个索引数组,每个选项按其在组内的顺序获得索引,选中多项时数组包含多个索引;点击已选中的选项会将其从数组中移除。
  • 每一个选项(sn-checkboxsn-checkbox-tag)必须是 sn-checkbox-group 的子代,选项自身不维护选中状态,需通过组控制。
  • 同一复选组内可混用 sn-checkboxsn-checkbox-tag,索引统一分配。
  • 选项默认自带右、下外边距,组内自动换行排列;verticaltrue 时纵向排列。
vue
<template>
	<sn-checkbox-group v-model="checked">
		<sn-checkbox text="苹果"></sn-checkbox>
		<sn-checkbox text="香蕉"></sn-checkbox>
		<sn-checkbox-tag text="菠萝"></sn-checkbox-tag>
	</sn-checkbox-group>
</template>

<script lang="uts" setup>
const checked = ref<number[]>([])
</script>

更多演示请下载 demo 查看

组配置下发

sn-checkbox-group 上的尺寸、颜色与样式类等配置会统一下发到组内全部 sn-checkbox / sn-checkbox-tag(这些配置项构成组配置对象 CheckboxGroupConfig)。选项组件自身的同名属性(如 icontypetext-class)优先级高于组配置,可单独覆盖某一选项的表现。尺寸类属性支持 $ 前缀动态尺寸(乘对应乘数),颜色类属性支持 $ 简写(如 $primary 自动引用主题色变量)。

sn-checkbox 属性

参数说明类型默认值可选值
text方框右侧的文本内容String''-
icon选中时方框内显示的图标名称,覆盖组配置 box-iconString''-
disabled是否禁用该选项Booleanfalsetrue | false
containStyle自定义选项整行容器样式(仅当前选项生效)UTSJSONObject | String''-
boxClass勾选方框的外部样式类String''-
customStyle自定义勾选方框样式(仅当前选项生效,定制整行容器用 containStyleUTSJSONObject | String''-
boxIconClass方框内图标的外部样式类String''-
textClass文本的外部样式类String''-

sn-checkbox-tag 属性

参数说明类型默认值可选值
text标签内部文本内容String''-
type标签主题类型,覆盖组配置 tag-typeString''(默认取组配置,兜底 primaryprimary | info | success | error | warning
level标签等级(选中态配色深浅),覆盖组配置 tag-levelString''(默认取组配置,兜底 secondfirst | second | third | least
disabled是否禁用该选项Booleanfalsetrue | false
customStyle自定义标签样式(仅当前选项生效)UTSJSONObject | String''-
textClass文本的外部样式类String''-

标签选项未选中时默认 info 色背景配 text 色文字;选中后配色由 typelevel 共同决定:

level背景文字
firsttype 对应原色(如 $primarytype 对应文字色(如 $primaryText
secondtype 对应浅色(如 $primaryLighttype 对应原色
thirdinfotype 对应原色
least透明type 对应原色

禁用时未选中为 disabled 底配 disabledText 字,选中为 disabledDark 底配 disabledDarkText 字。

sn-checkbox-group 属性

参数说明类型默认值可选值
v-model绑定值,当前选中项的索引数组Array<Number>[]-
vertical是否纵向排列Booleanfalsetrue | false
boxSize勾选方框边长String | Number'19px'-
boxBorderRadius勾选方框圆角String | Number'5px'-
boxBorderWidth勾选方框边框宽度String | Number'2px'-
boxTextSize方框选项文本大小String | Number''(默认 13px × fontsizeFactor)-
boxTextColor方框选项文本颜色String''(默认主题 text 色)-
disabledBoxTextColor禁用状态下方框选项文本颜色String''(默认主题 disabledText 色)-
boxIcon勾选方框内图标名称String'check-fill'-
boxIconSize勾选方框内图标大小String | Number''(默认 13px × fontsizeFactor)-
boxIconColor勾选方框内图标颜色String'#fff'-
disabledBoxIconColor禁用状态下方框内图标颜色String'#fff'-
boxBorderColor勾选方框边框颜色String''(默认主题 line 色)-
disabledBoxBorderColor禁用且未选中时方框边框颜色String''(默认主题 disabled 色)-
boxActiveBorderColor选中时方框边框颜色String''(默认主题 primary 色)-
disabledBoxActiveBorderColor禁用且选中时方框边框颜色String''(默认主题 disabledText 色)-
boxBgColor勾选方框背景颜色String''(默认透明)-
disabledBoxBgColor禁用且未选中时方框背景颜色String''(默认主题 disabled 色)-
boxActiveBgColor选中时方框背景颜色String''(默认主题 primary 色)-
disabledBoxActiveBgColor禁用且选中时方框背景颜色String''(默认主题 disabledText 色)-
tagType标签选项主题类型String'primary'primary | info | success | error | warning
tagLevel标签选项等级String'second'first | second | third | least
tagBorderRadius标签选项圆角String | Number'10px'-
tagPadding标签选项内边距String'6px 10px'-
tagTextSize标签选项文本大小String | Number''(默认 12px × fontsizeFactor)-
tagBgColor标签选项未选中时背景颜色String''(默认主题 info 色)-
disabledTagBgColor禁用且未选中时标签背景颜色String''(默认主题 disabled 色)-
tagActiveBgColor标签选项选中时背景颜色String''(默认由 tag-type + tag-level 决定)-
disabledTagActiveBgColor禁用且选中时标签背景颜色String''(默认主题 disabledDark 色)-
tagTextColor标签选项未选中时文本颜色String''(默认主题 text 色)-
disabledTagTextColor禁用且未选中时标签文本颜色String''(默认主题 disabledText 色)-
tagActiveTextColor标签选项选中时文本颜色String''(默认由 tag-type + tag-level 决定)-
disabledTagActiveTextColor禁用且选中时标签文本颜色String''(默认主题 disabledDarkText 色)-
boxContainStyle自定义方框选项整行容器样式UTSJSONObject | String''-
boxStyle自定义勾选方框样式UTSJSONObject | String''-
boxIconStyle自定义方框内图标样式UTSJSONObject | String''-
tagStyle自定义标签选项样式UTSJSONObject | String''-
textStyle自定义选项文本样式UTSJSONObject | String''-
boxContainClass方框选项整行容器的外部样式类String''-
boxClass勾选方框的外部样式类String''-
boxIconClass方框内图标的外部样式类String''-
tagClass标签选项根节点的外部样式类String''-
textClass选项文本的外部样式类String''-
customStyle自定义复选组根节点样式UTSJSONObject | String''-

事件

sn-checkbox-group

名称类型说明
change(value: number[]) => Void选中项变化时触发,携带最新的选中索引数组

插槽

sn-checkbox

名称说明
default替换方框右侧的文本内容,可以是任意内容

sn-checkbox-tag

名称说明
default替换标签内部的文本内容,可以是任意内容

sn-checkbox-group

名称说明
default放置子组件 sn-checkboxsn-checkbox-tag

使用 MIT 协议