UNPKG

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