UNPKG

4.7 kBTypeScriptView Raw
1import { ComponentType } from 'react'
2import { StandardProps, CommonEventFunction, FormItemProps } from './common'
3interface CheckboxProps extends StandardProps {
4 /** `<Checkbox/>`标识,选中时触发`<CheckboxGroup/>`的 change 事件,并携带 `<Checkbox/>` 的 value
5 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
6 */
7 value: string
8 /** 是否禁用
9 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
10 * @default false
11 */
12 disabled?: boolean
13 /** 当前是否选中,可用来设置默认选中
14 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
15 * @default false
16 */
17 checked?: boolean
18 /** checkbox的颜色,同 css 的 color
19 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
20 */
21 color?: string
22 /**
23 * Checkbox 的名字
24 * @supported h5, harmony, harmony_hybrid
25 */
26 name?: string
27 /** 用于透传 `WebComponents` 上的属性到内部 H5 标签上
28 * @supported h5, harmony_hybrid
29 */
30 nativeProps?: Record<string, unknown>
31 /** 无障碍访问,(属性)元素的额外描述
32 * @supported qq
33 */
34 ariaLabel?: string
35 /** 选中项发生变化时触发 change 事件,小程序无此 API
36 * @supported alipay, h5, rn, harmony_hybrid
37 */
38 onChange?: CommonEventFunction<{
39 value: string[]
40 }>
41}
42/** 多选项目
43 * @classification forms
44 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony, harmony_hybrid
45 * @example_react
46 * ```tsx
47 * export default class PageCheckbox extends Component {
48 * state = {
49 * list: [
50 * {
51 * value: '美国',
52 * text: '美国',
53 * checked: false
54 * },
55 * {
56 * value: '中国',
57 * text: '中国',
58 * checked: true
59 * },
60 * {
61 * value: '巴西',
62 * text: '巴西',
63 * checked: false
64 * },
65 * {
66 * value: '日本',
67 * text: '日本',
68 * checked: false
69 * },
70 * {
71 * value: '英国',
72 * text: '英国',
73 * checked: false
74 * },
75 * {
76 * value: '法国',
77 * text: '法国',
78 * checked: false
79 * }
80 * ]
81 * }
82 * render () {
83 * return (
84 * <View className='page-body'>
85 * <View className='page-section'>
86 * <Text>默认样式</Text>
87 * <Checkbox value='选中' checked>选中</Checkbox>
88 * <Checkbox style='margin-left: 20rpx' value='未选中'>未选中</Checkbox>
89 * </View>
90 * <View className='page-section'>
91 * <Text>推荐展示样式</Text>
92 * {this.state.list.map((item, i) => {
93 * return (
94 * <Label className='checkbox-list__label' for={i} key={i}>
95 * <Checkbox className='checkbox-list__checkbox' value={item.value} checked={item.checked}>{item.text}</Checkbox>
96 * </Label>
97 * )
98 * })}
99 * </View>
100 * </View>
101 * )
102 * }
103 * }
104 * ```
105 * @example_vue
106 * ```html
107 * <template>
108 * <view class="container">
109 * <view class="page-section">
110 * <text>默认样式</text>
111 * <checkbox value="选中" :checked="true">选中</checkbox>
112 * <checkbox style="margin-left: 20rpx;" value="未选中">未选中</checkbox>
113 * </view>
114 * <view class="page-section">
115 * <text>推荐展示样式(Taro 团队成员):</text>
116 * <label v-for="item in list" class="checkbox-list__label">
117 * <checkbox class="checkbox-list__checkbox" :value="item.value" :checked="item.checked">{{ item.text }}</checkbox>
118 * </label>
119 * </view>
120 * </view>
121 * </template>
122 *
123 * <script>
124 * export default {
125 * data() {
126 * return {
127 * list: [
128 * {
129 * value: '美国',
130 * text: '美国',
131 * checked: false
132 * },
133 * {
134 * value: '中国',
135 * text: '中国',
136 * checked: true
137 * },
138 * {
139 * value: '巴西',
140 * text: '巴西',
141 * checked: false
142 * },
143 * {
144 * value: '日本',
145 * text: '日本',
146 * checked: false
147 * },
148 * {
149 * value: '英国',
150 * text: '英国',
151 * checked: false
152 * },
153 * {
154 * value: '法国',
155 * text: '法国',
156 * checked: false
157 * }
158 * ]
159 * }
160 * }
161 * }
162 * </script>
163 * ```
164 * @see https://developers.weixin.qq.com/miniprogram/dev/component/checkbox.html
165 */
166declare const Checkbox: ComponentType<CheckboxProps>
167export { Checkbox, CheckboxProps }