Checkbox
Checkbox 多选框
代码示例
import { BfCheckbox, BfCheckboxGroup } from '@bud-fe/react-taro-ui';import { View } from '@tarojs/components';import React, { useState } from 'react';export default () => {const [singleChecked, setSingleChecked] = useState(true);const [singleRoundChecked, setSingleRoundChecked] = useState(true);const [groupChecked, setGroupChecked] = useState<any[]>(['1']);return (<><View className="group-title">BfCheckbox - 基本用法</View><BfCheckboxid="1000"label="选项1"value="1"checked={singleChecked}onChange={(v, p) => {console.log('onChange===', v, p);setSingleChecked((pre) => !pre);}}/><View className="group-title">BfCheckbox - 半选</View><BfCheckboxlabel="选项1"value="1"halfCheckedonChange={(v, p) => {console.log('onChange===', v, p);}}/><View className="group-title">BfCheckbox - selectable</View><BfCheckboxlabel="选项1"value="1"selectablechecked={singleChecked}onChange={(v, p) => {console.log('onChange===', v, p);setSingleChecked((pre) => !pre);}}onLabelClick={({ label, value }) => {console.log('onLabelClick===', { label, value });}}/><View className="group-title">BfCheckbox - disabled=true</View><BfCheckbox disabled label="选项1" value="1" checked /><View className="group-title">BfCheckbox - iconStyle="circle"</View><BfCheckboxlabel="选项2"value="2"iconStyle="circle"checked={singleRoundChecked}onChange={() => setSingleRoundChecked((pre) => !pre)}/><BfCheckboxlabel="选项2-半选"value="2"iconStyle="circle"halfChecked={singleRoundChecked}onChange={() => setSingleRoundChecked((pre) => !pre)}/><View className="group-title">BfCheckboxGroup - 基本用法</View><BfCheckboxGroupvalues={groupChecked}groups={[{ label: '选项1', value: '1' },{ label: '选项2', value: '2' },{ label: '选项3', value: '3' },{ label: '选项4', value: '4' },{ label: '选项5', value: '5' },{ label: '选项6', value: '6' },{ label: '选项7', value: '7' },]}onChange={(vals) => {setGroupChecked(vals);}}/><View className="group-title">BfCheckboxGroup - 垂直布局</View><BfCheckboxGroupiconStyle="circle"values={['2']}groups={[{ label: '选项1', value: '1' },{ label: '选项2', value: '2' },{ label: '选项3', value: '3' },]}layout="vertical"/></>);};
API
属性名 | 描述 | 类型 | 默认值 |
---|---|---|---|
selectable | 是否开启选择模式。开启后点击 label 会触发 onLabelClick,点击 icon 才会触发 onChange | boolean | false |
label | 多选框 label | any | (必选) |
value | 多选框 value | any | (必选) |
checked | 是否选中。当设置为 true 时,优先级高于 halfChecked | boolean | false |
halfChecked | 是否半选 | boolean | false |
selected | 是否 label 文字高亮 | boolean | false |
disabled | 是否禁用 | boolean | false |
iconClass | icon 类名 | string | -- |
iconStyle | icon 的样式 square | circle | TIconStyle | square |
onChange | 选中态变更回调 | (value: any, props: IBfCheckboxProps & ViewProps) => void | -- |
onLabelClick | 点击 label 的回调 | (props: IBfCheckboxProps & ViewProps) => void | -- |