@mijadesign/nut-mcp 1.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +147 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +16 -0
- package/dist/services/aliases.service.d.ts +1 -0
- package/dist/services/aliases.service.js +19 -0
- package/dist/services/doc-parser.service.d.ts +3 -0
- package/dist/services/doc-parser.service.js +162 -0
- package/dist/services/index.services.d.ts +3 -0
- package/dist/services/index.services.js +71 -0
- package/dist/services/paths.service.d.ts +5 -0
- package/dist/services/paths.service.js +18 -0
- package/dist/tools/base.tool.d.ts +8 -0
- package/dist/tools/base.tool.js +27 -0
- package/dist/tools/get-component-doc.tool.d.ts +12 -0
- package/dist/tools/get-component-doc.tool.js +40 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.js +4 -0
- package/dist/tools/list-components.tool.d.ts +8 -0
- package/dist/tools/list-components.tool.js +32 -0
- package/dist/tools/search-components.tool.d.ts +12 -0
- package/dist/tools/search-components.tool.js +61 -0
- package/dist/types/index.d.ts +33 -0
- package/dist/types/index.js +1 -0
- package/docs/docs/aliases.json +59 -0
- package/docs/docs/components/base/button/index.md +415 -0
- package/docs/docs/components/base/cell/index.md +279 -0
- package/docs/docs/components/base/configprovider/index.md +215 -0
- package/docs/docs/components/base/image/index.md +282 -0
- package/docs/docs/components/base/overlay/index.md +288 -0
- package/docs/docs/components/dentry/cascader/index.md +1080 -0
- package/docs/docs/components/dentry/checkbox/index.md +842 -0
- package/docs/docs/components/dentry/datepicker/index.md +489 -0
- package/docs/docs/components/dentry/form/index.md +457 -0
- package/docs/docs/components/dentry/input/index.md +257 -0
- package/docs/docs/components/dentry/picker/index.md +621 -0
- package/docs/docs/components/dentry/radio/index.md +364 -0
- package/docs/docs/components/dentry/searchbar/index.md +317 -0
- package/docs/docs/components/dentry/selector/index.md +295 -0
- package/docs/docs/components/dentry/switch/index.md +300 -0
- package/docs/docs/components/dentry/textarea/index.md +231 -0
- package/docs/docs/components/dentry/uploader/index.md +745 -0
- package/docs/docs/components/exhibition/collapse/index.md +339 -0
- package/docs/docs/components/exhibition/swiper/index.md +385 -0
- package/docs/docs/components/exhibition/tag/index.md +253 -0
- package/docs/docs/components/feedback/dialog/index.md +306 -0
- package/docs/docs/components/feedback/drag/index.md +164 -0
- package/docs/docs/components/feedback/empty/index.md +211 -0
- package/docs/docs/components/feedback/infiniteloading/index.md +397 -0
- package/docs/docs/components/feedback/noticebar/index.md +175 -0
- package/docs/docs/components/feedback/popup/index.md +563 -0
- package/docs/docs/components/feedback/pulltorefresh/index.md +254 -0
- package/docs/docs/components/feedback/toast/index.md +355 -0
- package/docs/docs/components/layout/divider/index.md +162 -0
- package/docs/docs/components/layout/grid/index.md +386 -0
- package/docs/docs/components/layout/space/index.md +196 -0
- package/docs/docs/components/nav/tabs/index.md +955 -0
- package/docs/docs/components-index.json +233 -0
- package/package.json +34 -0
|
@@ -0,0 +1,842 @@
|
|
|
1
|
+
---
|
|
2
|
+
order: 6
|
|
3
|
+
demoUrl: 'https://frontend.mishudata.com/mobile/demo/#/dentry/pages/checkbox/index'
|
|
4
|
+
group:
|
|
5
|
+
title: 数据录入
|
|
6
|
+
order: 5
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Checkbox 复选按钮 <Badge>2.0.0</Badge>
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
多选按钮用于选择。
|
|
13
|
+
|
|
14
|
+
## 引入
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
import { Checkbox } from '@mijadesign/mjui-react-taro';
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## 示例代码
|
|
21
|
+
|
|
22
|
+
### 基础用法
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import React, { useState } from 'react'
|
|
27
|
+
import { Checkbox, Cell } from '@mijadesign/mjui-react-taro'
|
|
28
|
+
|
|
29
|
+
const Demo3 = () => {
|
|
30
|
+
const [checked, setChecked] = useState(true)
|
|
31
|
+
return (
|
|
32
|
+
<Cell.Group>
|
|
33
|
+
<Cell className="nut-cell">
|
|
34
|
+
<Checkbox className="test" label="复选框" defaultChecked={checked} />
|
|
35
|
+
</Cell>
|
|
36
|
+
</Cell.Group>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
export default Demo3
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 横向复选
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
import React, { useState } from 'react'
|
|
48
|
+
import { Cell, Checkbox } from '@mijadesign/mjui-react-taro'
|
|
49
|
+
|
|
50
|
+
const Demo16 = () => {
|
|
51
|
+
const [optionsDemo1] = useState([
|
|
52
|
+
{
|
|
53
|
+
label: '选项 1',
|
|
54
|
+
value: '1',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
label: '选项 2',
|
|
58
|
+
value: '2',
|
|
59
|
+
disabled: true,
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
label: '选项 3',
|
|
63
|
+
value: '3',
|
|
64
|
+
},
|
|
65
|
+
])
|
|
66
|
+
return (
|
|
67
|
+
<Cell.Group>
|
|
68
|
+
<Cell>
|
|
69
|
+
<Checkbox.Group defaultValue={['1']} direction="horizontal" style={{ width: '100%' }}>
|
|
70
|
+
<Checkbox value="1" label={optionsDemo1[0].label} />
|
|
71
|
+
<Checkbox value="2" label={optionsDemo1[1].label} />
|
|
72
|
+
<Checkbox value="3" label={optionsDemo1[2].label} />
|
|
73
|
+
</Checkbox.Group>
|
|
74
|
+
</Cell>
|
|
75
|
+
</Cell.Group>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
export default Demo16
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### 复选类型
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
import { Selected } from '@mijadesign/mobile-icons'
|
|
87
|
+
import { Cell, Checkbox } from '@mijadesign/mjui-react-taro'
|
|
88
|
+
import React from 'react'
|
|
89
|
+
|
|
90
|
+
const Demo17 = () => {
|
|
91
|
+
const styles = { color: '#666666', fontWeight: '400' }
|
|
92
|
+
return (
|
|
93
|
+
<div>
|
|
94
|
+
<Cell.Group>
|
|
95
|
+
<Cell>
|
|
96
|
+
<Checkbox value="1" defaultChecked>
|
|
97
|
+
表单类型选项
|
|
98
|
+
</Checkbox>
|
|
99
|
+
</Cell>
|
|
100
|
+
<Cell>
|
|
101
|
+
<Checkbox value="2" defaultChecked>
|
|
102
|
+
表单类型选项 <span style={styles}>说明文本</span>
|
|
103
|
+
</Checkbox>
|
|
104
|
+
</Cell>
|
|
105
|
+
<Cell>
|
|
106
|
+
<Checkbox value="3" defaultChecked>
|
|
107
|
+
<div>
|
|
108
|
+
<div>表单类型选项</div>
|
|
109
|
+
<div style={styles}>说明文本说明文本说明文本说明文本说明文本说明文本说明文本说明文本</div>
|
|
110
|
+
</div>
|
|
111
|
+
</Checkbox>
|
|
112
|
+
</Cell>
|
|
113
|
+
</Cell.Group>
|
|
114
|
+
|
|
115
|
+
<Cell.Group>
|
|
116
|
+
<Cell>
|
|
117
|
+
<Checkbox
|
|
118
|
+
value="1"
|
|
119
|
+
defaultChecked
|
|
120
|
+
icon={<Selected />}
|
|
121
|
+
activeIcon={<Selected className="nut-checkbox-icon-checked" />}
|
|
122
|
+
>
|
|
123
|
+
表单类型选项
|
|
124
|
+
</Checkbox>
|
|
125
|
+
</Cell>
|
|
126
|
+
<Cell>
|
|
127
|
+
<Checkbox
|
|
128
|
+
value="2"
|
|
129
|
+
defaultChecked
|
|
130
|
+
icon={<Selected />}
|
|
131
|
+
activeIcon={<Selected className="nut-checkbox-icon-checked" />}
|
|
132
|
+
>
|
|
133
|
+
表单类型选项 <span style={styles}>说明文本</span>
|
|
134
|
+
</Checkbox>
|
|
135
|
+
</Cell>
|
|
136
|
+
<Cell>
|
|
137
|
+
<Checkbox
|
|
138
|
+
value="3"
|
|
139
|
+
defaultChecked
|
|
140
|
+
icon={<Selected />}
|
|
141
|
+
activeIcon={<Selected className="nut-checkbox-icon-checked" />}
|
|
142
|
+
>
|
|
143
|
+
<div>
|
|
144
|
+
<div>表单类型选项</div>
|
|
145
|
+
<div style={styles}>说明文本说明文本说明文本说明文本说明文本说明文本说明文本说明文本</div>
|
|
146
|
+
</div>
|
|
147
|
+
</Checkbox>
|
|
148
|
+
</Cell>
|
|
149
|
+
</Cell.Group>
|
|
150
|
+
</div>
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
export default Demo17
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## 勾选位置
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
```tsx
|
|
161
|
+
import { Selected } from '@mijadesign/mobile-icons'
|
|
162
|
+
import { Cell, Checkbox } from '@mijadesign/mjui-react-taro'
|
|
163
|
+
import React from 'react'
|
|
164
|
+
|
|
165
|
+
const Demo18 = () => {
|
|
166
|
+
return (
|
|
167
|
+
<Cell.Group>
|
|
168
|
+
<Cell>
|
|
169
|
+
<Checkbox value="1" defaultChecked>
|
|
170
|
+
Icon位置在前
|
|
171
|
+
</Checkbox>
|
|
172
|
+
</Cell>
|
|
173
|
+
<Cell>
|
|
174
|
+
<Checkbox
|
|
175
|
+
labelPosition="left"
|
|
176
|
+
value="1"
|
|
177
|
+
defaultChecked
|
|
178
|
+
icon={<Selected />}
|
|
179
|
+
activeIcon={<Selected className="nut-checkbox-icon-checked" />}
|
|
180
|
+
style={{ width: '100%' }}
|
|
181
|
+
>
|
|
182
|
+
Icon位置在后
|
|
183
|
+
</Checkbox>
|
|
184
|
+
</Cell>
|
|
185
|
+
</Cell.Group>
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
export default Demo18
|
|
189
|
+
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## 组件状态
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
```tsx
|
|
196
|
+
import React from 'react'
|
|
197
|
+
import { Cell, Checkbox } from '@mijadesign/mjui-react-taro'
|
|
198
|
+
|
|
199
|
+
const Demo5 = () => {
|
|
200
|
+
return (
|
|
201
|
+
<Cell.Group>
|
|
202
|
+
<Cell>
|
|
203
|
+
<Checkbox labelPosition="right" label="未选选项禁用" checked={false} disabled />
|
|
204
|
+
</Cell>
|
|
205
|
+
<Cell>
|
|
206
|
+
<Checkbox labelPosition="right" label="半选选项禁用" checked disabled indeterminate />
|
|
207
|
+
</Cell>
|
|
208
|
+
<Cell>
|
|
209
|
+
<Checkbox labelPosition="right" label="已选选项禁用" checked disabled />
|
|
210
|
+
</Cell>
|
|
211
|
+
</Cell.Group>
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
export default Demo5
|
|
215
|
+
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## 半选状态
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
```tsx
|
|
222
|
+
import React from 'react'
|
|
223
|
+
import { Cell, Checkbox } from '@mijadesign/mjui-react-taro'
|
|
224
|
+
|
|
225
|
+
const Demo4 = () => {
|
|
226
|
+
return (
|
|
227
|
+
<Cell>
|
|
228
|
+
<Checkbox value="1" label="复选框1" checked indeterminate />
|
|
229
|
+
</Cell>
|
|
230
|
+
)
|
|
231
|
+
}
|
|
232
|
+
export default Demo4
|
|
233
|
+
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## 自定义图标
|
|
237
|
+
|
|
238
|
+
这里建议同时设置 `icon` 和 `activeIcon` 属性
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
```tsx
|
|
242
|
+
import { Selected } from '@mijadesign/mobile-icons'
|
|
243
|
+
import { Cell, Checkbox } from '@mijadesign/mjui-react-taro'
|
|
244
|
+
import React from 'react'
|
|
245
|
+
|
|
246
|
+
const Demo7 = () => {
|
|
247
|
+
return (
|
|
248
|
+
<Cell.Group>
|
|
249
|
+
<Cell className="nut-cell">
|
|
250
|
+
<Checkbox
|
|
251
|
+
defaultChecked={false}
|
|
252
|
+
icon={<Selected />}
|
|
253
|
+
activeIcon={<Selected className="nut-checkbox-icon-checked" />}
|
|
254
|
+
>
|
|
255
|
+
自定义图标
|
|
256
|
+
</Checkbox>
|
|
257
|
+
</Cell>
|
|
258
|
+
<Cell className="nut-cell">
|
|
259
|
+
<Checkbox.Group labelPosition="left" defaultValue={['1']} style={{ width: '100%' }}>
|
|
260
|
+
<Checkbox
|
|
261
|
+
value="1"
|
|
262
|
+
defaultChecked={false}
|
|
263
|
+
icon={<Selected />}
|
|
264
|
+
activeIcon={<Selected className="nut-checkbox-icon-checked" />}
|
|
265
|
+
>
|
|
266
|
+
自定义图标
|
|
267
|
+
</Checkbox>
|
|
268
|
+
<Checkbox
|
|
269
|
+
value="2"
|
|
270
|
+
defaultChecked={false}
|
|
271
|
+
icon={<Selected />}
|
|
272
|
+
activeIcon={<Selected className="nut-checkbox-icon-checked" />}
|
|
273
|
+
>
|
|
274
|
+
自定义图标
|
|
275
|
+
</Checkbox>
|
|
276
|
+
</Checkbox.Group>
|
|
277
|
+
</Cell>
|
|
278
|
+
</Cell.Group>
|
|
279
|
+
)
|
|
280
|
+
}
|
|
281
|
+
export default Demo7
|
|
282
|
+
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## 点击触发事件
|
|
286
|
+
|
|
287
|
+
值发生变化时,将触发change事件
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
```tsx
|
|
291
|
+
import React, { useState } from 'react'
|
|
292
|
+
import { Checkbox, Toast, Cell } from '@mijadesign/mjui-react-taro'
|
|
293
|
+
|
|
294
|
+
const Demo8 = () => {
|
|
295
|
+
const [showToast, setShowToast] = useState(false)
|
|
296
|
+
const [content, setContent] = useState('')
|
|
297
|
+
const handleChange = (state: any) => {
|
|
298
|
+
if (state) {
|
|
299
|
+
setContent('选中')
|
|
300
|
+
} else {
|
|
301
|
+
setContent('取消选中')
|
|
302
|
+
}
|
|
303
|
+
setShowToast(true)
|
|
304
|
+
}
|
|
305
|
+
return (
|
|
306
|
+
<>
|
|
307
|
+
<Toast
|
|
308
|
+
content={content}
|
|
309
|
+
visible={showToast}
|
|
310
|
+
onClose={() => {
|
|
311
|
+
setShowToast(false)
|
|
312
|
+
}}
|
|
313
|
+
/>
|
|
314
|
+
<Cell.Group>
|
|
315
|
+
<Cell className="nut-cell">
|
|
316
|
+
<Checkbox defaultChecked={false} onChange={(state) => handleChange(state)}>
|
|
317
|
+
复选框
|
|
318
|
+
</Checkbox>
|
|
319
|
+
</Cell>
|
|
320
|
+
</Cell.Group>
|
|
321
|
+
</>
|
|
322
|
+
)
|
|
323
|
+
}
|
|
324
|
+
export default Demo8
|
|
325
|
+
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
## Checkbox.Group
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
```tsx
|
|
332
|
+
import React, { useState } from 'react'
|
|
333
|
+
import { Checkbox, Cell } from '@mijadesign/mjui-react-taro'
|
|
334
|
+
|
|
335
|
+
const Demo9 = () => {
|
|
336
|
+
const [checkboxgroup1, setCheckboxgroup1] = useState(['1'])
|
|
337
|
+
const [content, setContent] = useState('')
|
|
338
|
+
const handleChange = (value: any) => {
|
|
339
|
+
setContent(value.toString())
|
|
340
|
+
setCheckboxgroup1(value)
|
|
341
|
+
}
|
|
342
|
+
return (
|
|
343
|
+
<>
|
|
344
|
+
<Cell>
|
|
345
|
+
<Checkbox.Group defaultValue={checkboxgroup1} direction="horizontal" onChange={(value) => handleChange(value)}>
|
|
346
|
+
<Checkbox value="1">选项</Checkbox>
|
|
347
|
+
<Checkbox value="2">选项</Checkbox>
|
|
348
|
+
<Checkbox value="3">选项</Checkbox>
|
|
349
|
+
<Checkbox value="4">选项</Checkbox>
|
|
350
|
+
</Checkbox.Group>
|
|
351
|
+
</Cell>
|
|
352
|
+
<Cell>
|
|
353
|
+
<span>选中:{checkboxgroup1.toString()}</span>
|
|
354
|
+
</Cell>
|
|
355
|
+
</>
|
|
356
|
+
)
|
|
357
|
+
}
|
|
358
|
+
export default Demo9
|
|
359
|
+
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
## 禁用
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
```tsx
|
|
366
|
+
import React, { useState } from 'react'
|
|
367
|
+
import { Checkbox, Cell } from '@mijadesign/mjui-react-taro'
|
|
368
|
+
|
|
369
|
+
const Demo10 = () => {
|
|
370
|
+
const [checkboxgroup1] = useState(['1'])
|
|
371
|
+
return (
|
|
372
|
+
<Cell>
|
|
373
|
+
<Checkbox.Group
|
|
374
|
+
defaultValue={checkboxgroup1}
|
|
375
|
+
disabled
|
|
376
|
+
direction="horizontal"
|
|
377
|
+
>
|
|
378
|
+
<Checkbox value="1">选项</Checkbox>
|
|
379
|
+
<Checkbox value="2">选项</Checkbox>
|
|
380
|
+
<Checkbox value="3">选项</Checkbox>
|
|
381
|
+
<Checkbox value="4">选项</Checkbox>
|
|
382
|
+
</Checkbox.Group>
|
|
383
|
+
</Cell>
|
|
384
|
+
)
|
|
385
|
+
}
|
|
386
|
+
export default Demo10
|
|
387
|
+
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
## 全选/取消
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
```tsx
|
|
394
|
+
import React, { useState, useRef } from 'react'
|
|
395
|
+
import { Checkbox, Button, Toast, Cell } from '@mijadesign/mjui-react-taro'
|
|
396
|
+
|
|
397
|
+
const Demo11 = () => {
|
|
398
|
+
const [checkboxgroup2, setCheckboxgroup2] = useState(['1'])
|
|
399
|
+
const checkboxgroup2Ref = useRef(null)
|
|
400
|
+
const [showToast, setShowToast] = useState(false)
|
|
401
|
+
const [content, setContent] = useState('')
|
|
402
|
+
const handleChange = (value: any) => {
|
|
403
|
+
setContent(`${value.length === 4 ? '全选' : '取消全选'}`)
|
|
404
|
+
setShowToast(true)
|
|
405
|
+
}
|
|
406
|
+
return (
|
|
407
|
+
<>
|
|
408
|
+
<Cell>
|
|
409
|
+
<Toast
|
|
410
|
+
content={content}
|
|
411
|
+
visible={showToast}
|
|
412
|
+
onClose={() => {
|
|
413
|
+
setShowToast(false)
|
|
414
|
+
}}
|
|
415
|
+
/>
|
|
416
|
+
<Checkbox.Group
|
|
417
|
+
labelPosition="left"
|
|
418
|
+
direction="horizontal"
|
|
419
|
+
ref={checkboxgroup2Ref}
|
|
420
|
+
defaultValue={checkboxgroup2}
|
|
421
|
+
onChange={(value) => handleChange(value)}
|
|
422
|
+
>
|
|
423
|
+
<Checkbox value="1">选项</Checkbox>
|
|
424
|
+
<Checkbox value="2">选项</Checkbox>
|
|
425
|
+
<Checkbox value="3">选项</Checkbox>
|
|
426
|
+
<Checkbox value="4">选项</Checkbox>
|
|
427
|
+
</Checkbox.Group>
|
|
428
|
+
</Cell>
|
|
429
|
+
<Cell>
|
|
430
|
+
<Button
|
|
431
|
+
type="primary"
|
|
432
|
+
onClick={() => {
|
|
433
|
+
;(checkboxgroup2Ref.current as any).toggle(true)
|
|
434
|
+
}}
|
|
435
|
+
style={{ marginInlineEnd: '20px' }}
|
|
436
|
+
>
|
|
437
|
+
全选
|
|
438
|
+
</Button>
|
|
439
|
+
<Button
|
|
440
|
+
onClick={() => {
|
|
441
|
+
;(checkboxgroup2Ref.current as any).toggle(false)
|
|
442
|
+
}}
|
|
443
|
+
style={{ marginInlineEnd: '20px' }}
|
|
444
|
+
>
|
|
445
|
+
取消
|
|
446
|
+
</Button>
|
|
447
|
+
<Button
|
|
448
|
+
type="warning"
|
|
449
|
+
onClick={() => {
|
|
450
|
+
;(checkboxgroup2Ref.current as any).reverse()
|
|
451
|
+
}}
|
|
452
|
+
>
|
|
453
|
+
反选
|
|
454
|
+
</Button>
|
|
455
|
+
</Cell>
|
|
456
|
+
</>
|
|
457
|
+
)
|
|
458
|
+
}
|
|
459
|
+
export default Demo11
|
|
460
|
+
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
## checkboxGroup使用,限制最大可选数(3个), 至少选择数(1个)
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
```tsx
|
|
467
|
+
import React, { useState } from 'react'
|
|
468
|
+
import { Checkbox, Toast, Cell } from '@mijadesign/mjui-react-taro'
|
|
469
|
+
|
|
470
|
+
const Demo12 = () => {
|
|
471
|
+
const [checkboxgroup2, setCheckboxgroup2] = useState(['1'])
|
|
472
|
+
const [showToast, setShowToast] = useState(false)
|
|
473
|
+
const [content, setContent] = useState('')
|
|
474
|
+
const handleLimit = (type: any) => {
|
|
475
|
+
setContent(type === 'max' ? '最多选择3项' : '至少选择1项')
|
|
476
|
+
setShowToast(true)
|
|
477
|
+
}
|
|
478
|
+
return (
|
|
479
|
+
<Cell>
|
|
480
|
+
<Toast
|
|
481
|
+
content={content}
|
|
482
|
+
visible={showToast}
|
|
483
|
+
onClose={() => {
|
|
484
|
+
setShowToast(false)
|
|
485
|
+
}}
|
|
486
|
+
/>
|
|
487
|
+
<Checkbox.Group
|
|
488
|
+
defaultValue={checkboxgroup2}
|
|
489
|
+
max={3}
|
|
490
|
+
min={1}
|
|
491
|
+
onLimit={(type) => handleLimit(type)}
|
|
492
|
+
>
|
|
493
|
+
<Checkbox value="1">选项</Checkbox>
|
|
494
|
+
<Checkbox value="2">选项</Checkbox>
|
|
495
|
+
<Checkbox value="3">选项</Checkbox>
|
|
496
|
+
<Checkbox value="4">选项</Checkbox>
|
|
497
|
+
</Checkbox.Group>
|
|
498
|
+
</Cell>
|
|
499
|
+
)
|
|
500
|
+
}
|
|
501
|
+
export default Demo12
|
|
502
|
+
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
## 全选/半选/取消
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
```tsx
|
|
509
|
+
import React, { useState, useRef } from 'react'
|
|
510
|
+
import { View } from '@tarojs/components'
|
|
511
|
+
import { Checkbox, Cell } from '@mijadesign/mjui-react-taro'
|
|
512
|
+
|
|
513
|
+
const Demo13 = () => {
|
|
514
|
+
const [checkboxgroup2, setCheckboxgroup2] = useState(['1'])
|
|
515
|
+
const checkboxgroup2Ref = useRef(null)
|
|
516
|
+
const [checkbox1, setCheckbox1] = useState(false)
|
|
517
|
+
const [indeterminate, setIndeterminate] = useState(false)
|
|
518
|
+
return (
|
|
519
|
+
<>
|
|
520
|
+
<Cell>
|
|
521
|
+
<View style={{ width: '50%' }}>
|
|
522
|
+
<Checkbox
|
|
523
|
+
checked={checkbox1}
|
|
524
|
+
indeterminate={indeterminate}
|
|
525
|
+
onChange={(state) => {
|
|
526
|
+
if (state) {
|
|
527
|
+
setIndeterminate(false)
|
|
528
|
+
}
|
|
529
|
+
setCheckbox1(state)
|
|
530
|
+
;(checkboxgroup2Ref.current as any).toggle(state)
|
|
531
|
+
}}
|
|
532
|
+
>
|
|
533
|
+
全选
|
|
534
|
+
</Checkbox>
|
|
535
|
+
</View>
|
|
536
|
+
|
|
537
|
+
<Checkbox.Group
|
|
538
|
+
ref={checkboxgroup2Ref}
|
|
539
|
+
direction="horizontal"
|
|
540
|
+
defaultValue={checkboxgroup2}
|
|
541
|
+
style={{ width: '50%' }}
|
|
542
|
+
onChange={(value) => {
|
|
543
|
+
if (value.length === 4) {
|
|
544
|
+
setIndeterminate(false)
|
|
545
|
+
setCheckbox1(true)
|
|
546
|
+
} else if (value.length && value.length < 4) {
|
|
547
|
+
setIndeterminate(true)
|
|
548
|
+
setCheckbox1(true)
|
|
549
|
+
} else {
|
|
550
|
+
setCheckbox1(false)
|
|
551
|
+
}
|
|
552
|
+
}}
|
|
553
|
+
>
|
|
554
|
+
<Checkbox value="1" style={{ marginBottom: 10 }}>
|
|
555
|
+
选项
|
|
556
|
+
</Checkbox>
|
|
557
|
+
<Checkbox value="2" style={{ marginBottom: 10 }}>
|
|
558
|
+
选项
|
|
559
|
+
</Checkbox>
|
|
560
|
+
<Checkbox value="3" style={{ marginBottom: 10 }}>
|
|
561
|
+
选项
|
|
562
|
+
</Checkbox>
|
|
563
|
+
<Checkbox value="4" style={{ marginBottom: 10 }}>
|
|
564
|
+
选项
|
|
565
|
+
</Checkbox>
|
|
566
|
+
</Checkbox.Group>
|
|
567
|
+
</Cell>
|
|
568
|
+
</>
|
|
569
|
+
)
|
|
570
|
+
}
|
|
571
|
+
export default Demo13
|
|
572
|
+
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
## 配置 options 渲染复选按钮
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
```tsx
|
|
579
|
+
import React, { useState } from 'react'
|
|
580
|
+
import { Checkbox, Cell } from '@mijadesign/mjui-react-taro'
|
|
581
|
+
|
|
582
|
+
const Demo14 = () => {
|
|
583
|
+
const [checkboxVal] = useState(['1'])
|
|
584
|
+
const [optionsDemo1] = useState([
|
|
585
|
+
{
|
|
586
|
+
label: '选项1',
|
|
587
|
+
value: '1',
|
|
588
|
+
},
|
|
589
|
+
{
|
|
590
|
+
label: '选项2',
|
|
591
|
+
value: '2',
|
|
592
|
+
disabled: true,
|
|
593
|
+
},
|
|
594
|
+
{
|
|
595
|
+
label: '选项3',
|
|
596
|
+
value: '3',
|
|
597
|
+
},
|
|
598
|
+
])
|
|
599
|
+
return (
|
|
600
|
+
<Cell>
|
|
601
|
+
<Checkbox.Group options={optionsDemo1} defaultValue={checkboxVal} />
|
|
602
|
+
</Cell>
|
|
603
|
+
)
|
|
604
|
+
}
|
|
605
|
+
export default Demo14
|
|
606
|
+
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
## 列表
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
```tsx
|
|
613
|
+
import React from 'react'
|
|
614
|
+
import { Checkbox } from '@mijadesign/mjui-react-taro'
|
|
615
|
+
|
|
616
|
+
const Demo15 = () => {
|
|
617
|
+
return (
|
|
618
|
+
<Checkbox.Group defaultValue={['1']} labelPosition="left" list>
|
|
619
|
+
<Checkbox value="1" label="选项1" style={{ borderTopWidth: 0 }} />
|
|
620
|
+
<Checkbox value="2" label="选项2" />
|
|
621
|
+
<Checkbox value="3" label="选项3" />
|
|
622
|
+
</Checkbox.Group>
|
|
623
|
+
)
|
|
624
|
+
}
|
|
625
|
+
export default Demo15
|
|
626
|
+
|
|
627
|
+
```
|
|
628
|
+
|
|
629
|
+
## 非受控
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
```tsx
|
|
633
|
+
import { Cell, Checkbox } from '@mijadesign/mjui-react-taro'
|
|
634
|
+
import { Checklist } from '@nutui/icons-react-taro'
|
|
635
|
+
import React, { useState } from 'react'
|
|
636
|
+
|
|
637
|
+
const Demo1 = () => {
|
|
638
|
+
const [checked] = useState(false)
|
|
639
|
+
return (
|
|
640
|
+
<>
|
|
641
|
+
<Cell className="nut-cell">
|
|
642
|
+
<div />
|
|
643
|
+
<Checkbox className="test" label="复选框" defaultChecked={checked} />
|
|
644
|
+
</Cell>
|
|
645
|
+
{/* <Cell className="nut-cell">
|
|
646
|
+
<Checkbox
|
|
647
|
+
style={{ marginInlineEnd: '8px' }}
|
|
648
|
+
shape="button"
|
|
649
|
+
className="test"
|
|
650
|
+
label={
|
|
651
|
+
<div
|
|
652
|
+
style={{
|
|
653
|
+
display: 'flex',
|
|
654
|
+
flexDirection: 'column',
|
|
655
|
+
alignItems: 'center',
|
|
656
|
+
}}
|
|
657
|
+
>
|
|
658
|
+
<div>复选框</div>
|
|
659
|
+
<div style={{ color: 'gray' }}>描述信息</div>
|
|
660
|
+
</div>
|
|
661
|
+
}
|
|
662
|
+
defaultChecked={!checked}
|
|
663
|
+
/>
|
|
664
|
+
<Checkbox
|
|
665
|
+
style={{ marginInlineEnd: '8px' }}
|
|
666
|
+
shape="button"
|
|
667
|
+
activeIcon={<Checklist className="nut-checkbox-button-icon-checked" />}
|
|
668
|
+
className="test"
|
|
669
|
+
label={
|
|
670
|
+
<div
|
|
671
|
+
style={{
|
|
672
|
+
display: 'flex',
|
|
673
|
+
flexDirection: 'column',
|
|
674
|
+
alignItems: 'center',
|
|
675
|
+
}}
|
|
676
|
+
>
|
|
677
|
+
<div>复选框</div>
|
|
678
|
+
<div style={{ color: 'gray' }}>描述信息</div>
|
|
679
|
+
</div>
|
|
680
|
+
}
|
|
681
|
+
defaultChecked={checked}
|
|
682
|
+
/>
|
|
683
|
+
<Checkbox
|
|
684
|
+
shape="button"
|
|
685
|
+
className="test"
|
|
686
|
+
disabled
|
|
687
|
+
label={
|
|
688
|
+
<div
|
|
689
|
+
style={{
|
|
690
|
+
display: 'flex',
|
|
691
|
+
flexDirection: 'column',
|
|
692
|
+
alignItems: 'center',
|
|
693
|
+
}}
|
|
694
|
+
>
|
|
695
|
+
<div>复选框</div>
|
|
696
|
+
<div>描述信息</div>
|
|
697
|
+
</div>
|
|
698
|
+
}
|
|
699
|
+
defaultChecked={checked}
|
|
700
|
+
/>
|
|
701
|
+
</Cell> */}
|
|
702
|
+
</>
|
|
703
|
+
)
|
|
704
|
+
}
|
|
705
|
+
export default Demo1
|
|
706
|
+
|
|
707
|
+
```
|
|
708
|
+
|
|
709
|
+
## 受控
|
|
710
|
+
|
|
711
|
+
|
|
712
|
+
```tsx
|
|
713
|
+
import { Cell, Checkbox } from '@mijadesign/mjui-react-taro'
|
|
714
|
+
import React, { useState } from 'react'
|
|
715
|
+
|
|
716
|
+
const Demo2 = () => {
|
|
717
|
+
const [controlled, setControlled] = useState(false)
|
|
718
|
+
const [controlledGroup, setControlledGroup] = useState(['2'])
|
|
719
|
+
const [controlledGroup1, setControlledGroup1] = useState(['2'])
|
|
720
|
+
const [optionsDemo1] = useState([
|
|
721
|
+
{
|
|
722
|
+
label: '选项 1',
|
|
723
|
+
value: '1',
|
|
724
|
+
},
|
|
725
|
+
{
|
|
726
|
+
label: '选项 2',
|
|
727
|
+
value: '2',
|
|
728
|
+
disabled: true,
|
|
729
|
+
},
|
|
730
|
+
{
|
|
731
|
+
label: '选项 3',
|
|
732
|
+
value: '3',
|
|
733
|
+
},
|
|
734
|
+
])
|
|
735
|
+
return (
|
|
736
|
+
<Cell.Group>
|
|
737
|
+
<Cell className="nut-cell">
|
|
738
|
+
<Checkbox className="test" label="复选框" checked={controlled} onChange={(val) => setControlled(val)} />
|
|
739
|
+
</Cell>
|
|
740
|
+
<Cell className="nut-cell">
|
|
741
|
+
<Checkbox.Group labelPosition="left" value={controlledGroup} onChange={(value) => setControlledGroup(value)}>
|
|
742
|
+
<span>
|
|
743
|
+
<Checkbox value="1" label={optionsDemo1[0].label} />
|
|
744
|
+
</span>
|
|
745
|
+
<Checkbox value="2" label={optionsDemo1[1].label} />
|
|
746
|
+
<Checkbox value="3" disabled label={optionsDemo1[2].label} />
|
|
747
|
+
</Checkbox.Group>
|
|
748
|
+
</Cell>
|
|
749
|
+
{/* <Cell className="nut-cell">
|
|
750
|
+
<Checkbox.Group labelPosition="left" value={controlledGroup1} onChange={(value) => setControlledGroup1(value)}>
|
|
751
|
+
<Checkbox
|
|
752
|
+
activeIcon={<Checklist className="nut-checkbox-button-icon-checked" />}
|
|
753
|
+
shape="button"
|
|
754
|
+
value="1"
|
|
755
|
+
label={optionsDemo1[0].label}
|
|
756
|
+
/>
|
|
757
|
+
<Checkbox
|
|
758
|
+
activeIcon={<Checklist className="nut-checkbox-button-icon-checked" />}
|
|
759
|
+
shape="button"
|
|
760
|
+
value="2"
|
|
761
|
+
label={optionsDemo1[1].label}
|
|
762
|
+
/>
|
|
763
|
+
<Checkbox
|
|
764
|
+
activeIcon={<Checklist className="nut-checkbox-button-icon-checked" />}
|
|
765
|
+
shape="button"
|
|
766
|
+
value="3"
|
|
767
|
+
label={optionsDemo1[2].label}
|
|
768
|
+
disabled
|
|
769
|
+
/>
|
|
770
|
+
</Checkbox.Group>
|
|
771
|
+
</Cell> */}
|
|
772
|
+
</Cell.Group>
|
|
773
|
+
)
|
|
774
|
+
}
|
|
775
|
+
export default Demo2
|
|
776
|
+
|
|
777
|
+
```
|
|
778
|
+
|
|
779
|
+
## Checkbox
|
|
780
|
+
|
|
781
|
+
### props
|
|
782
|
+
|
|
783
|
+
| 属性 | 说明 | 类型 | 默认值 |
|
|
784
|
+
| --- | --- | --- | --- |
|
|
785
|
+
| checked | 是否选中 | `boolean` | `false` |
|
|
786
|
+
| defaultChecked | 初始是否选中 | `boolean` | `false` |
|
|
787
|
+
| disabled | 是否禁用选择 | `boolean` | `false` |
|
|
788
|
+
| labelPosition | 文本所在的位置 | `left` \| `right` | `right` |
|
|
789
|
+
| icon | 选中前| `ReactNode` | `'CheckNormal'` |
|
|
790
|
+
| activeIcon | 选中后 | `ReactNode` | `'Checked'` |
|
|
791
|
+
| indeterminateIcon | 半选状态| `ReactNode` | `'CheckDisabled'` |
|
|
792
|
+
| label | 复选框的文本内容 | `string` | `-` |
|
|
793
|
+
| value | 标识值,用于 Group 模式 | `string` \| `number` | `-` |
|
|
794
|
+
| shape | 形状 | `button` \| `round` |`round` |
|
|
795
|
+
| onChange | 值变化时触发 | `(value: boolean) => void` | `-` |
|
|
796
|
+
|
|
797
|
+
## Checkbox.Group
|
|
798
|
+
|
|
799
|
+
### Props
|
|
800
|
+
|
|
801
|
+
| 属性 | 说明 | 类型 | 默认值 |
|
|
802
|
+
| --- | --- | --- | --- |
|
|
803
|
+
| value | 当前选中项的标识符 | `string` \| `number` | `-` |
|
|
804
|
+
| defaultValue | 初始选中项的标识符 | `string` \| `number` | `-` |
|
|
805
|
+
| disabled | 是否禁用选择,将用于其下的全部复选框 | `boolean` | `false` |
|
|
806
|
+
| max | 限制最大可选数 | `number` | `-` |
|
|
807
|
+
| min | 限制至少选择数 | `number` | `-` |
|
|
808
|
+
| labelPosition | 文本所在的位置 | `left` \| `right` | `right` |
|
|
809
|
+
| direction | 使用横纵方向 可选值 horizontal、vertical | `string` | `vertical` |
|
|
810
|
+
| options | 配置 options 渲染复选按钮 | `Array<{ label: string value: string disabled?: boolean }>` | `-` |
|
|
811
|
+
| list | 列表模式 | `boolean` | `false` |
|
|
812
|
+
| onChange | 值变化时触发 | `(value: string[]) => void` | `-` |
|
|
813
|
+
|
|
814
|
+
### Ref
|
|
815
|
+
|
|
816
|
+
| 方法名 | 说明 | 参数 |
|
|
817
|
+
| --- | --- | --- |
|
|
818
|
+
| toggle | 全选/取消 | 传 `true`,表示全选,传 `false`,表示取消全选 |
|
|
819
|
+
| reverse | 反选 | `-` |
|
|
820
|
+
|
|
821
|
+
## 主题定制
|
|
822
|
+
|
|
823
|
+
### 样式变量
|
|
824
|
+
|
|
825
|
+
组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 [ConfigProvider 组件](#/zh-CN/component/configprovider)。
|
|
826
|
+
|
|
827
|
+
| 名称 | 说明 | 默认值 |
|
|
828
|
+
| --- | --- | --- |
|
|
829
|
+
| \--nutui-checkbox-label-color | label 的文本颜色 | `$color-title` |
|
|
830
|
+
| \--nutui-checkbox-label-margin-left | label 的左边距 | `4px` |
|
|
831
|
+
| \--nutui-checkbox-label-font-size | label 的字号 | `$font-size-2` |
|
|
832
|
+
| \--nutui-checkbox-button-font-size | shape为button的字号 | `12px` |
|
|
833
|
+
| \--nutui-checkbox-button-color | 字体颜色 | `$color-text` |
|
|
834
|
+
| \--nutui-checkbox-button-background | shape为button的背景色 | `$color-background` |
|
|
835
|
+
| \--nutui-checkbox-label-button-border-color | shape为button的边框颜色 | `$color-primary` |
|
|
836
|
+
| \--nutui-checkbox-button-active-border | shape为button选中态的边框 | `1px solid $color-primary` |
|
|
837
|
+
| \--nutui-checkbox-button-padding | shape为button的内边距 | `5px 18px` |
|
|
838
|
+
| \--nutui-checkbox-button-border-radius | shape为button的圆角 | `15px` |
|
|
839
|
+
| \--nutui-checkbox-list-background-colors | 列表背景色 | `15px` |
|
|
840
|
+
| \--nutui-checkbox-list-item-border | 列表项的边框 | `15px` |
|
|
841
|
+
| \--nutui-checkbox-list-padding | 列表的padding | `15px` |
|
|
842
|
+
| \--nutui-checkbox-list-item-padding | 列表项的padding | `15px` |
|