@khanacademy/wonder-blocks-form 4.3.0 → 4.3.2
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/CHANGELOG.md +25 -0
- package/dist/es/index.js +27 -24
- package/dist/index.js +27 -24
- package/package.json +6 -6
- package/src/components/checkbox-core.tsx +70 -76
- package/src/components/checkbox-group.tsx +71 -79
- package/src/components/checkbox.tsx +15 -17
- package/src/components/choice-internal.tsx +93 -93
- package/src/components/choice.tsx +34 -33
- package/src/components/radio-core.tsx +41 -47
- package/src/components/radio-group.tsx +56 -61
- package/src/components/radio.tsx +15 -17
- package/tsconfig-build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-form
|
|
2
2
|
|
|
3
|
+
## 4.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4f8133ed: Fix props so `variants` doesn't show up in underlying input attributes
|
|
8
|
+
- Updated dependencies [ec6a33a4]
|
|
9
|
+
- Updated dependencies [1344436f]
|
|
10
|
+
- @khanacademy/wonder-blocks-icon@2.1.0
|
|
11
|
+
- @khanacademy/wonder-blocks-core@5.4.0
|
|
12
|
+
- @khanacademy/wonder-blocks-clickable@3.1.3
|
|
13
|
+
- @khanacademy/wonder-blocks-layout@2.0.16
|
|
14
|
+
- @khanacademy/wonder-blocks-typography@2.1.2
|
|
15
|
+
|
|
16
|
+
## 4.3.1
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- 9f3752d4: Used named functions in componenets with forwarded refs
|
|
21
|
+
- Updated dependencies [9f3752d4]
|
|
22
|
+
- @khanacademy/wonder-blocks-typography@2.1.1
|
|
23
|
+
- @khanacademy/wonder-blocks-core@5.3.1
|
|
24
|
+
- @khanacademy/wonder-blocks-clickable@3.1.2
|
|
25
|
+
- @khanacademy/wonder-blocks-icon@2.0.15
|
|
26
|
+
- @khanacademy/wonder-blocks-layout@2.0.15
|
|
27
|
+
|
|
3
28
|
## 4.3.0
|
|
4
29
|
|
|
5
30
|
### Minor Changes
|
package/dist/es/index.js
CHANGED
|
@@ -35,7 +35,7 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
35
35
|
return target;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
const _excluded$
|
|
38
|
+
const _excluded$5 = ["checked", "disabled", "error", "groupName", "id", "testId"];
|
|
39
39
|
function mapCheckedToAriaChecked(value) {
|
|
40
40
|
switch (value) {
|
|
41
41
|
case true:
|
|
@@ -62,7 +62,7 @@ const checkPath = {
|
|
|
62
62
|
const indeterminatePath = {
|
|
63
63
|
small: "M3 8C3 7.44772 3.44772 7 4 7H12C12.5523 7 13 7.44772 13 8C13 8.55228 12.5523 9 12 9H4C3.44772 9 3 8.55228 3 8Z"
|
|
64
64
|
};
|
|
65
|
-
const CheckboxCore = React.forwardRef((props, ref)
|
|
65
|
+
const CheckboxCore = React.forwardRef(function CheckboxCore(props, ref) {
|
|
66
66
|
const {
|
|
67
67
|
checked,
|
|
68
68
|
disabled,
|
|
@@ -71,7 +71,7 @@ const CheckboxCore = React.forwardRef((props, ref) => {
|
|
|
71
71
|
id,
|
|
72
72
|
testId
|
|
73
73
|
} = props,
|
|
74
|
-
sharedProps = _objectWithoutPropertiesLoose(props, _excluded$
|
|
74
|
+
sharedProps = _objectWithoutPropertiesLoose(props, _excluded$5);
|
|
75
75
|
const innerRef = React.useRef(null);
|
|
76
76
|
React.useEffect(() => {
|
|
77
77
|
if (innerRef.current != null) {
|
|
@@ -209,7 +209,7 @@ const _generateStyles$1 = (checked, error) => {
|
|
|
209
209
|
return styles$5[styleKey];
|
|
210
210
|
};
|
|
211
211
|
|
|
212
|
-
const _excluded$
|
|
212
|
+
const _excluded$4 = ["checked", "disabled", "error", "groupName", "id", "testId"];
|
|
213
213
|
const {
|
|
214
214
|
blue,
|
|
215
215
|
red,
|
|
@@ -220,7 +220,7 @@ const {
|
|
|
220
220
|
offBlack50
|
|
221
221
|
} = Color;
|
|
222
222
|
const StyledInput$1 = addStyle("input");
|
|
223
|
-
const RadioCore = React.forwardRef((props, ref)
|
|
223
|
+
const RadioCore = React.forwardRef(function RadioCore(props, ref) {
|
|
224
224
|
const handleChange = () => {
|
|
225
225
|
return;
|
|
226
226
|
};
|
|
@@ -232,7 +232,7 @@ const RadioCore = React.forwardRef((props, ref) => {
|
|
|
232
232
|
id,
|
|
233
233
|
testId
|
|
234
234
|
} = props,
|
|
235
|
-
sharedProps = _objectWithoutPropertiesLoose(props, _excluded$
|
|
235
|
+
sharedProps = _objectWithoutPropertiesLoose(props, _excluded$4);
|
|
236
236
|
const stateStyles = _generateStyles(checked, error);
|
|
237
237
|
const defaultStyle = [sharedStyles.inputReset, sharedStyles.default, !disabled && stateStyles.default, disabled && sharedStyles.disabled];
|
|
238
238
|
return React.createElement(React.Fragment, null, React.createElement(StyledInput$1, _extends({}, sharedProps, {
|
|
@@ -354,19 +354,21 @@ const _generateStyles = (checked, error) => {
|
|
|
354
354
|
return styles$4[styleKey];
|
|
355
355
|
};
|
|
356
356
|
|
|
357
|
-
const
|
|
357
|
+
const _excluded$3 = ["checked", "description", "disabled", "error", "id", "label", "onChange", "style", "className", "variant"];
|
|
358
|
+
const ChoiceInternal = React.forwardRef(function ChoiceInternal(props, ref) {
|
|
358
359
|
const {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
360
|
+
checked,
|
|
361
|
+
description,
|
|
362
|
+
disabled = false,
|
|
363
|
+
error = false,
|
|
364
|
+
id,
|
|
365
|
+
label,
|
|
366
|
+
onChange,
|
|
367
|
+
style,
|
|
368
|
+
className,
|
|
369
|
+
variant
|
|
370
|
+
} = props,
|
|
371
|
+
coreProps = _objectWithoutPropertiesLoose(props, _excluded$3);
|
|
370
372
|
const handleClick = () => {
|
|
371
373
|
if (variant === "radio" && checked) {
|
|
372
374
|
return;
|
|
@@ -406,8 +408,9 @@ const ChoiceInternal = React.forwardRef((props, ref) => {
|
|
|
406
408
|
}, React.createElement(View, {
|
|
407
409
|
style: styles$3.wrapper,
|
|
408
410
|
tabIndex: -1
|
|
409
|
-
}, React.createElement(ChoiceCore, _extends({},
|
|
411
|
+
}, React.createElement(ChoiceCore, _extends({}, coreProps, {
|
|
410
412
|
id: uniqueId,
|
|
413
|
+
checked: checked,
|
|
411
414
|
"aria-describedby": descriptionId,
|
|
412
415
|
onClick: handleClick,
|
|
413
416
|
disabled: disabled,
|
|
@@ -437,7 +440,7 @@ const styles$3 = StyleSheet.create({
|
|
|
437
440
|
}
|
|
438
441
|
});
|
|
439
442
|
|
|
440
|
-
const Checkbox = React.forwardRef((props, ref)
|
|
443
|
+
const Checkbox = React.forwardRef(function Checkbox(props, ref) {
|
|
441
444
|
const {
|
|
442
445
|
disabled = false,
|
|
443
446
|
error = false
|
|
@@ -451,7 +454,7 @@ const Checkbox = React.forwardRef((props, ref) => {
|
|
|
451
454
|
});
|
|
452
455
|
|
|
453
456
|
const _excluded$2 = ["disabled", "error"];
|
|
454
|
-
const Radio = React.forwardRef((props, ref)
|
|
457
|
+
const Radio = React.forwardRef(function Radio(props, ref) {
|
|
455
458
|
const {
|
|
456
459
|
disabled = false,
|
|
457
460
|
error = false
|
|
@@ -466,7 +469,7 @@ const Radio = React.forwardRef((props, ref) => {
|
|
|
466
469
|
});
|
|
467
470
|
|
|
468
471
|
const _excluded$1 = ["checked", "disabled", "onChange", "value", "variant"];
|
|
469
|
-
const Choice = React.forwardRef((props, ref)
|
|
472
|
+
const Choice = React.forwardRef(function Choice(props, ref) {
|
|
470
473
|
const {
|
|
471
474
|
checked = false,
|
|
472
475
|
disabled = false,
|
|
@@ -514,7 +517,7 @@ const styles$2 = StyleSheet.create({
|
|
|
514
517
|
|
|
515
518
|
const StyledFieldset$1 = addStyle("fieldset");
|
|
516
519
|
const StyledLegend$1 = addStyle("legend");
|
|
517
|
-
const CheckboxGroup = React.forwardRef((props, ref)
|
|
520
|
+
const CheckboxGroup = React.forwardRef(function CheckboxGroup(props, ref) {
|
|
518
521
|
const {
|
|
519
522
|
children,
|
|
520
523
|
label,
|
|
@@ -571,7 +574,7 @@ const CheckboxGroup = React.forwardRef((props, ref) => {
|
|
|
571
574
|
|
|
572
575
|
const StyledFieldset = addStyle("fieldset");
|
|
573
576
|
const StyledLegend = addStyle("legend");
|
|
574
|
-
const RadioGroup = React.forwardRef((props, ref)
|
|
577
|
+
const RadioGroup = React.forwardRef(function RadioGroup(props, ref) {
|
|
575
578
|
const {
|
|
576
579
|
children,
|
|
577
580
|
label,
|
package/dist/index.js
CHANGED
|
@@ -64,7 +64,7 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
64
64
|
return target;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
const _excluded$
|
|
67
|
+
const _excluded$5 = ["checked", "disabled", "error", "groupName", "id", "testId"];
|
|
68
68
|
function mapCheckedToAriaChecked(value) {
|
|
69
69
|
switch (value) {
|
|
70
70
|
case true:
|
|
@@ -91,7 +91,7 @@ const checkPath = {
|
|
|
91
91
|
const indeterminatePath = {
|
|
92
92
|
small: "M3 8C3 7.44772 3.44772 7 4 7H12C12.5523 7 13 7.44772 13 8C13 8.55228 12.5523 9 12 9H4C3.44772 9 3 8.55228 3 8Z"
|
|
93
93
|
};
|
|
94
|
-
const CheckboxCore = React__namespace.forwardRef((props, ref)
|
|
94
|
+
const CheckboxCore = React__namespace.forwardRef(function CheckboxCore(props, ref) {
|
|
95
95
|
const {
|
|
96
96
|
checked,
|
|
97
97
|
disabled,
|
|
@@ -100,7 +100,7 @@ const CheckboxCore = React__namespace.forwardRef((props, ref) => {
|
|
|
100
100
|
id,
|
|
101
101
|
testId
|
|
102
102
|
} = props,
|
|
103
|
-
sharedProps = _objectWithoutPropertiesLoose(props, _excluded$
|
|
103
|
+
sharedProps = _objectWithoutPropertiesLoose(props, _excluded$5);
|
|
104
104
|
const innerRef = React__namespace.useRef(null);
|
|
105
105
|
React__namespace.useEffect(() => {
|
|
106
106
|
if (innerRef.current != null) {
|
|
@@ -238,7 +238,7 @@ const _generateStyles$1 = (checked, error) => {
|
|
|
238
238
|
return styles$5[styleKey];
|
|
239
239
|
};
|
|
240
240
|
|
|
241
|
-
const _excluded$
|
|
241
|
+
const _excluded$4 = ["checked", "disabled", "error", "groupName", "id", "testId"];
|
|
242
242
|
const {
|
|
243
243
|
blue,
|
|
244
244
|
red,
|
|
@@ -249,7 +249,7 @@ const {
|
|
|
249
249
|
offBlack50
|
|
250
250
|
} = Color__default["default"];
|
|
251
251
|
const StyledInput$1 = wonderBlocksCore.addStyle("input");
|
|
252
|
-
const RadioCore = React__namespace.forwardRef((props, ref)
|
|
252
|
+
const RadioCore = React__namespace.forwardRef(function RadioCore(props, ref) {
|
|
253
253
|
const handleChange = () => {
|
|
254
254
|
return;
|
|
255
255
|
};
|
|
@@ -261,7 +261,7 @@ const RadioCore = React__namespace.forwardRef((props, ref) => {
|
|
|
261
261
|
id,
|
|
262
262
|
testId
|
|
263
263
|
} = props,
|
|
264
|
-
sharedProps = _objectWithoutPropertiesLoose(props, _excluded$
|
|
264
|
+
sharedProps = _objectWithoutPropertiesLoose(props, _excluded$4);
|
|
265
265
|
const stateStyles = _generateStyles(checked, error);
|
|
266
266
|
const defaultStyle = [sharedStyles.inputReset, sharedStyles.default, !disabled && stateStyles.default, disabled && sharedStyles.disabled];
|
|
267
267
|
return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement(StyledInput$1, _extends({}, sharedProps, {
|
|
@@ -383,19 +383,21 @@ const _generateStyles = (checked, error) => {
|
|
|
383
383
|
return styles$4[styleKey];
|
|
384
384
|
};
|
|
385
385
|
|
|
386
|
-
const
|
|
386
|
+
const _excluded$3 = ["checked", "description", "disabled", "error", "id", "label", "onChange", "style", "className", "variant"];
|
|
387
|
+
const ChoiceInternal = React__namespace.forwardRef(function ChoiceInternal(props, ref) {
|
|
387
388
|
const {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
389
|
+
checked,
|
|
390
|
+
description,
|
|
391
|
+
disabled = false,
|
|
392
|
+
error = false,
|
|
393
|
+
id,
|
|
394
|
+
label,
|
|
395
|
+
onChange,
|
|
396
|
+
style,
|
|
397
|
+
className,
|
|
398
|
+
variant
|
|
399
|
+
} = props,
|
|
400
|
+
coreProps = _objectWithoutPropertiesLoose(props, _excluded$3);
|
|
399
401
|
const handleClick = () => {
|
|
400
402
|
if (variant === "radio" && checked) {
|
|
401
403
|
return;
|
|
@@ -435,8 +437,9 @@ const ChoiceInternal = React__namespace.forwardRef((props, ref) => {
|
|
|
435
437
|
}, React__namespace.createElement(wonderBlocksCore.View, {
|
|
436
438
|
style: styles$3.wrapper,
|
|
437
439
|
tabIndex: -1
|
|
438
|
-
}, React__namespace.createElement(ChoiceCore, _extends({},
|
|
440
|
+
}, React__namespace.createElement(ChoiceCore, _extends({}, coreProps, {
|
|
439
441
|
id: uniqueId,
|
|
442
|
+
checked: checked,
|
|
440
443
|
"aria-describedby": descriptionId,
|
|
441
444
|
onClick: handleClick,
|
|
442
445
|
disabled: disabled,
|
|
@@ -466,7 +469,7 @@ const styles$3 = aphrodite.StyleSheet.create({
|
|
|
466
469
|
}
|
|
467
470
|
});
|
|
468
471
|
|
|
469
|
-
const Checkbox = React__namespace.forwardRef((props, ref)
|
|
472
|
+
const Checkbox = React__namespace.forwardRef(function Checkbox(props, ref) {
|
|
470
473
|
const {
|
|
471
474
|
disabled = false,
|
|
472
475
|
error = false
|
|
@@ -480,7 +483,7 @@ const Checkbox = React__namespace.forwardRef((props, ref) => {
|
|
|
480
483
|
});
|
|
481
484
|
|
|
482
485
|
const _excluded$2 = ["disabled", "error"];
|
|
483
|
-
const Radio = React__namespace.forwardRef((props, ref)
|
|
486
|
+
const Radio = React__namespace.forwardRef(function Radio(props, ref) {
|
|
484
487
|
const {
|
|
485
488
|
disabled = false,
|
|
486
489
|
error = false
|
|
@@ -495,7 +498,7 @@ const Radio = React__namespace.forwardRef((props, ref) => {
|
|
|
495
498
|
});
|
|
496
499
|
|
|
497
500
|
const _excluded$1 = ["checked", "disabled", "onChange", "value", "variant"];
|
|
498
|
-
const Choice = React__namespace.forwardRef((props, ref)
|
|
501
|
+
const Choice = React__namespace.forwardRef(function Choice(props, ref) {
|
|
499
502
|
const {
|
|
500
503
|
checked = false,
|
|
501
504
|
disabled = false,
|
|
@@ -543,7 +546,7 @@ const styles$2 = aphrodite.StyleSheet.create({
|
|
|
543
546
|
|
|
544
547
|
const StyledFieldset$1 = wonderBlocksCore.addStyle("fieldset");
|
|
545
548
|
const StyledLegend$1 = wonderBlocksCore.addStyle("legend");
|
|
546
|
-
const CheckboxGroup = React__namespace.forwardRef((props, ref)
|
|
549
|
+
const CheckboxGroup = React__namespace.forwardRef(function CheckboxGroup(props, ref) {
|
|
547
550
|
const {
|
|
548
551
|
children,
|
|
549
552
|
label,
|
|
@@ -600,7 +603,7 @@ const CheckboxGroup = React__namespace.forwardRef((props, ref) => {
|
|
|
600
603
|
|
|
601
604
|
const StyledFieldset = wonderBlocksCore.addStyle("fieldset");
|
|
602
605
|
const StyledLegend = wonderBlocksCore.addStyle("legend");
|
|
603
|
-
const RadioGroup = React__namespace.forwardRef((props, ref)
|
|
606
|
+
const RadioGroup = React__namespace.forwardRef(function RadioGroup(props, ref) {
|
|
604
607
|
const {
|
|
605
608
|
children,
|
|
606
609
|
label,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-form",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.2",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"description": "Form components for Wonder Blocks.",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@babel/runtime": "^7.18.6",
|
|
19
|
-
"@khanacademy/wonder-blocks-clickable": "^3.1.
|
|
19
|
+
"@khanacademy/wonder-blocks-clickable": "^3.1.3",
|
|
20
20
|
"@khanacademy/wonder-blocks-color": "^2.0.1",
|
|
21
|
-
"@khanacademy/wonder-blocks-core": "^5.
|
|
22
|
-
"@khanacademy/wonder-blocks-icon": "^2.0
|
|
23
|
-
"@khanacademy/wonder-blocks-layout": "^2.0.
|
|
21
|
+
"@khanacademy/wonder-blocks-core": "^5.4.0",
|
|
22
|
+
"@khanacademy/wonder-blocks-icon": "^2.1.0",
|
|
23
|
+
"@khanacademy/wonder-blocks-layout": "^2.0.16",
|
|
24
24
|
"@khanacademy/wonder-blocks-spacing": "^4.0.1",
|
|
25
|
-
"@khanacademy/wonder-blocks-typography": "^2.1.
|
|
25
|
+
"@khanacademy/wonder-blocks-typography": "^2.1.2"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"aphrodite": "^1.2.5",
|
|
@@ -39,83 +39,77 @@ const indeterminatePath: IconAsset = {
|
|
|
39
39
|
/**
|
|
40
40
|
* The internal stateless ☑️ Checkbox
|
|
41
41
|
*/
|
|
42
|
-
const CheckboxCore = React.forwardRef(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
disabled
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
42
|
+
const CheckboxCore = React.forwardRef(function CheckboxCore(
|
|
43
|
+
props: ChoiceCoreProps,
|
|
44
|
+
ref: React.ForwardedRef<HTMLInputElement>,
|
|
45
|
+
) {
|
|
46
|
+
const {checked, disabled, error, groupName, id, testId, ...sharedProps} =
|
|
47
|
+
props;
|
|
48
|
+
|
|
49
|
+
const innerRef = React.useRef<HTMLInputElement>(null);
|
|
50
|
+
|
|
51
|
+
React.useEffect(() => {
|
|
52
|
+
// Keep the indeterminate state in sync with the checked prop
|
|
53
|
+
if (innerRef.current != null) {
|
|
54
|
+
innerRef.current.indeterminate = checked == null;
|
|
55
|
+
}
|
|
56
|
+
}, [checked, innerRef]);
|
|
57
|
+
|
|
58
|
+
const handleChange: () => void = () => {
|
|
59
|
+
// Empty because change is handled by ClickableBehavior
|
|
60
|
+
return;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const stateStyles = _generateStyles(checked, error);
|
|
64
|
+
|
|
65
|
+
const defaultStyle = [
|
|
66
|
+
sharedStyles.inputReset,
|
|
67
|
+
sharedStyles.default,
|
|
68
|
+
!disabled && stateStyles.default,
|
|
69
|
+
disabled && sharedStyles.disabled,
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
const checkboxIcon = (
|
|
73
|
+
<Icon
|
|
74
|
+
color={disabled ? offBlack32 : white}
|
|
75
|
+
icon={checked ? checkPath : indeterminatePath}
|
|
76
|
+
size="small"
|
|
77
|
+
style={sharedStyles.checkboxIcon}
|
|
78
|
+
/>
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const ariaChecked = mapCheckedToAriaChecked(checked);
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<React.Fragment>
|
|
85
|
+
<StyledInput
|
|
86
|
+
{...sharedProps}
|
|
87
|
+
ref={(node) => {
|
|
88
|
+
// @ts-expect-error: current is not actually read-only
|
|
89
|
+
innerRef.current = node;
|
|
90
|
+
if (typeof ref === "function") {
|
|
91
|
+
ref(node);
|
|
92
|
+
} else if (ref != null) {
|
|
93
|
+
ref.current = node;
|
|
94
|
+
}
|
|
95
|
+
}}
|
|
96
|
+
type="checkbox"
|
|
97
|
+
aria-checked={ariaChecked}
|
|
98
|
+
aria-invalid={error}
|
|
99
|
+
checked={checked ?? undefined}
|
|
100
|
+
disabled={disabled}
|
|
101
|
+
id={id}
|
|
102
|
+
name={groupName}
|
|
103
|
+
// Need to specify because this is a controlled React form
|
|
104
|
+
// component, but we handle the click via ClickableBehavior
|
|
105
|
+
onChange={handleChange}
|
|
106
|
+
style={defaultStyle}
|
|
107
|
+
data-test-id={testId}
|
|
83
108
|
/>
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return (
|
|
89
|
-
<React.Fragment>
|
|
90
|
-
<StyledInput
|
|
91
|
-
{...sharedProps}
|
|
92
|
-
ref={(node) => {
|
|
93
|
-
// @ts-expect-error: current is not actually read-only
|
|
94
|
-
innerRef.current = node;
|
|
95
|
-
if (typeof ref === "function") {
|
|
96
|
-
ref(node);
|
|
97
|
-
} else if (ref != null) {
|
|
98
|
-
ref.current = node;
|
|
99
|
-
}
|
|
100
|
-
}}
|
|
101
|
-
type="checkbox"
|
|
102
|
-
aria-checked={ariaChecked}
|
|
103
|
-
aria-invalid={error}
|
|
104
|
-
checked={checked ?? undefined}
|
|
105
|
-
disabled={disabled}
|
|
106
|
-
id={id}
|
|
107
|
-
name={groupName}
|
|
108
|
-
// Need to specify because this is a controlled React form
|
|
109
|
-
// component, but we handle the click via ClickableBehavior
|
|
110
|
-
onChange={handleChange}
|
|
111
|
-
style={defaultStyle}
|
|
112
|
-
data-test-id={testId}
|
|
113
|
-
/>
|
|
114
|
-
{checked || checked == null ? checkboxIcon : <></>}
|
|
115
|
-
</React.Fragment>
|
|
116
|
-
);
|
|
117
|
-
},
|
|
118
|
-
);
|
|
109
|
+
{checked || checked == null ? checkboxIcon : <></>}
|
|
110
|
+
</React.Fragment>
|
|
111
|
+
);
|
|
112
|
+
});
|
|
119
113
|
|
|
120
114
|
const size = 16;
|
|
121
115
|
|
|
@@ -95,88 +95,80 @@ const StyledLegend = addStyle("legend");
|
|
|
95
95
|
* </CheckboxGroup>
|
|
96
96
|
* ```
|
|
97
97
|
*/
|
|
98
|
-
const CheckboxGroup = React.forwardRef(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
} = props;
|
|
98
|
+
const CheckboxGroup = React.forwardRef(function CheckboxGroup(
|
|
99
|
+
props: CheckboxGroupProps,
|
|
100
|
+
ref: React.ForwardedRef<HTMLFieldSetElement>,
|
|
101
|
+
) {
|
|
102
|
+
const {
|
|
103
|
+
children,
|
|
104
|
+
label,
|
|
105
|
+
description,
|
|
106
|
+
errorMessage,
|
|
107
|
+
groupName,
|
|
108
|
+
onChange,
|
|
109
|
+
selectedValues,
|
|
110
|
+
style,
|
|
111
|
+
testId,
|
|
112
|
+
} = props;
|
|
114
113
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
114
|
+
const handleChange = (
|
|
115
|
+
changedValue: string,
|
|
116
|
+
originalCheckedState: boolean,
|
|
117
|
+
) => {
|
|
118
|
+
if (originalCheckedState) {
|
|
119
|
+
const index = selectedValues.indexOf(changedValue);
|
|
120
|
+
const updatedSelection = [
|
|
121
|
+
...selectedValues.slice(0, index),
|
|
122
|
+
...selectedValues.slice(index + 1),
|
|
123
|
+
];
|
|
124
|
+
onChange(updatedSelection);
|
|
125
|
+
} else {
|
|
126
|
+
onChange([...selectedValues, changedValue]);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
130
129
|
|
|
131
|
-
|
|
130
|
+
const allChildren = React.Children.toArray(children).filter(Boolean);
|
|
132
131
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
{
|
|
152
|
-
|
|
153
|
-
{errorMessage}
|
|
154
|
-
</LabelSmall>
|
|
155
|
-
)}
|
|
156
|
-
{(label || description || errorMessage) && (
|
|
157
|
-
<Strut size={Spacing.small_12} />
|
|
158
|
-
)}
|
|
132
|
+
return (
|
|
133
|
+
<StyledFieldset data-test-id={testId} style={styles.fieldset} ref={ref}>
|
|
134
|
+
{/* We have a View here because fieldset cannot be used with flexbox*/}
|
|
135
|
+
<View style={style}>
|
|
136
|
+
{label && (
|
|
137
|
+
<StyledLegend style={styles.legend}>
|
|
138
|
+
<LabelMedium>{label}</LabelMedium>
|
|
139
|
+
</StyledLegend>
|
|
140
|
+
)}
|
|
141
|
+
{description && (
|
|
142
|
+
<LabelSmall style={styles.description}>
|
|
143
|
+
{description}
|
|
144
|
+
</LabelSmall>
|
|
145
|
+
)}
|
|
146
|
+
{errorMessage && (
|
|
147
|
+
<LabelSmall style={styles.error}>{errorMessage}</LabelSmall>
|
|
148
|
+
)}
|
|
149
|
+
{(label || description || errorMessage) && (
|
|
150
|
+
<Strut size={Spacing.small_12} />
|
|
151
|
+
)}
|
|
159
152
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
);
|
|
153
|
+
{allChildren.map((child, index) => {
|
|
154
|
+
// @ts-expect-error [FEI-5019] - TS2339 - Property 'props' does not exist on type 'ReactChild | ReactFragment | ReactPortal'.
|
|
155
|
+
const {style, value} = child.props;
|
|
156
|
+
const checked = selectedValues.includes(value);
|
|
157
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
158
|
+
return React.cloneElement(child, {
|
|
159
|
+
checked: checked,
|
|
160
|
+
error: !!errorMessage,
|
|
161
|
+
groupName: groupName,
|
|
162
|
+
id: `${groupName}-${value}`,
|
|
163
|
+
key: value,
|
|
164
|
+
onChange: () => handleChange(value, checked),
|
|
165
|
+
style: [index > 0 && styles.defaultLineGap, style],
|
|
166
|
+
variant: "checkbox",
|
|
167
|
+
});
|
|
168
|
+
})}
|
|
169
|
+
</View>
|
|
170
|
+
</StyledFieldset>
|
|
171
|
+
);
|
|
172
|
+
});
|
|
181
173
|
|
|
182
174
|
export default CheckboxGroup;
|