@khanacademy/wonder-blocks-form 4.2.2 → 4.3.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/CHANGELOG.md +31 -0
- package/dist/components/checkbox-core.d.ts +13 -8
- package/dist/components/checkbox-core.js.flow +19 -10
- package/dist/components/checkbox-group.d.ts +2 -5
- package/dist/components/checkbox-group.js.flow +5 -6
- package/dist/components/checkbox.d.ts +33 -39
- package/dist/components/checkbox.js.flow +38 -41
- package/dist/components/choice-internal.d.ts +19 -31
- package/dist/components/choice-internal.js.flow +25 -32
- package/dist/components/choice.d.ts +50 -60
- package/dist/components/choice.js.flow +79 -84
- package/dist/components/radio-core.d.ts +13 -5
- package/dist/components/radio-core.js.flow +19 -7
- package/dist/components/radio-group.d.ts +2 -5
- package/dist/components/radio-group.js.flow +5 -6
- package/dist/components/radio.d.ts +18 -24
- package/dist/components/radio.js.flow +24 -27
- package/dist/es/index.js +262 -294
- package/dist/index.js +262 -294
- package/dist/util/types.d.ts +1 -1
- package/dist/util/types.js.flow +1 -1
- package/package.json +6 -6
- package/src/components/__tests__/{checkbox.test.js → checkbox.test.tsx} +55 -1
- package/src/components/checkbox-core.tsx +32 -31
- package/src/components/checkbox-group.tsx +33 -22
- package/src/components/checkbox.tsx +21 -16
- package/src/components/choice-internal.tsx +60 -58
- package/src/components/choice.tsx +39 -32
- package/src/components/radio-core.tsx +16 -14
- package/src/components/radio-group.tsx +14 -11
- package/src/components/radio.tsx +21 -16
- package/src/util/types.ts +1 -1
- package/tsconfig-build.tsbuildinfo +1 -1
package/dist/index.js
CHANGED
|
@@ -91,61 +91,55 @@ 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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (this.inputRef.current != null) {
|
|
109
|
-
this.inputRef.current.indeterminate = this.props.checked == null;
|
|
94
|
+
const CheckboxCore = React__namespace.forwardRef((props, ref) => {
|
|
95
|
+
const {
|
|
96
|
+
checked,
|
|
97
|
+
disabled,
|
|
98
|
+
error,
|
|
99
|
+
groupName,
|
|
100
|
+
id,
|
|
101
|
+
testId
|
|
102
|
+
} = props,
|
|
103
|
+
sharedProps = _objectWithoutPropertiesLoose(props, _excluded$4);
|
|
104
|
+
const innerRef = React__namespace.useRef(null);
|
|
105
|
+
React__namespace.useEffect(() => {
|
|
106
|
+
if (innerRef.current != null) {
|
|
107
|
+
innerRef.current.indeterminate = checked == null;
|
|
110
108
|
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
style: defaultStyle
|
|
146
|
-
}, props)), checked || checked == null ? checkboxIcon : React__namespace.createElement(React__namespace.Fragment, null));
|
|
147
|
-
}
|
|
148
|
-
}
|
|
109
|
+
}, [checked, innerRef]);
|
|
110
|
+
const handleChange = () => {
|
|
111
|
+
return;
|
|
112
|
+
};
|
|
113
|
+
const stateStyles = _generateStyles$1(checked, error);
|
|
114
|
+
const defaultStyle = [sharedStyles$1.inputReset, sharedStyles$1.default, !disabled && stateStyles.default, disabled && sharedStyles$1.disabled];
|
|
115
|
+
const checkboxIcon = React__namespace.createElement(Icon__default["default"], {
|
|
116
|
+
color: disabled ? offBlack32$1 : white$1,
|
|
117
|
+
icon: checked ? checkPath : indeterminatePath,
|
|
118
|
+
size: "small",
|
|
119
|
+
style: sharedStyles$1.checkboxIcon
|
|
120
|
+
});
|
|
121
|
+
const ariaChecked = mapCheckedToAriaChecked(checked);
|
|
122
|
+
return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement(StyledInput$2, _extends({}, sharedProps, {
|
|
123
|
+
ref: node => {
|
|
124
|
+
innerRef.current = node;
|
|
125
|
+
if (typeof ref === "function") {
|
|
126
|
+
ref(node);
|
|
127
|
+
} else if (ref != null) {
|
|
128
|
+
ref.current = node;
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
type: "checkbox",
|
|
132
|
+
"aria-checked": ariaChecked,
|
|
133
|
+
"aria-invalid": error,
|
|
134
|
+
checked: checked != null ? checked : undefined,
|
|
135
|
+
disabled: disabled,
|
|
136
|
+
id: id,
|
|
137
|
+
name: groupName,
|
|
138
|
+
onChange: handleChange,
|
|
139
|
+
style: defaultStyle,
|
|
140
|
+
"data-test-id": testId
|
|
141
|
+
})), checked || checked == null ? checkboxIcon : React__namespace.createElement(React__namespace.Fragment, null));
|
|
142
|
+
});
|
|
149
143
|
const size$1 = 16;
|
|
150
144
|
const sharedStyles$1 = aphrodite.StyleSheet.create({
|
|
151
145
|
inputReset: {
|
|
@@ -255,43 +249,36 @@ const {
|
|
|
255
249
|
offBlack50
|
|
256
250
|
} = Color__default["default"];
|
|
257
251
|
const StyledInput$1 = wonderBlocksCore.addStyle("input");
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
onChange: this.handleChange,
|
|
289
|
-
style: defaultStyle
|
|
290
|
-
}, props)), disabled && checked && React__namespace.createElement("span", {
|
|
291
|
-
style: disabledChecked
|
|
292
|
-
}));
|
|
293
|
-
}
|
|
294
|
-
}
|
|
252
|
+
const RadioCore = React__namespace.forwardRef((props, ref) => {
|
|
253
|
+
const handleChange = () => {
|
|
254
|
+
return;
|
|
255
|
+
};
|
|
256
|
+
const {
|
|
257
|
+
checked,
|
|
258
|
+
disabled,
|
|
259
|
+
error,
|
|
260
|
+
groupName,
|
|
261
|
+
id,
|
|
262
|
+
testId
|
|
263
|
+
} = props,
|
|
264
|
+
sharedProps = _objectWithoutPropertiesLoose(props, _excluded$3);
|
|
265
|
+
const stateStyles = _generateStyles(checked, error);
|
|
266
|
+
const defaultStyle = [sharedStyles.inputReset, sharedStyles.default, !disabled && stateStyles.default, disabled && sharedStyles.disabled];
|
|
267
|
+
return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement(StyledInput$1, _extends({}, sharedProps, {
|
|
268
|
+
type: "radio",
|
|
269
|
+
"aria-invalid": error,
|
|
270
|
+
checked: checked != null ? checked : undefined,
|
|
271
|
+
disabled: disabled,
|
|
272
|
+
id: id,
|
|
273
|
+
name: groupName,
|
|
274
|
+
onChange: handleChange,
|
|
275
|
+
style: defaultStyle,
|
|
276
|
+
"data-test-id": testId,
|
|
277
|
+
ref: ref
|
|
278
|
+
})), disabled && checked && React__namespace.createElement("span", {
|
|
279
|
+
style: disabledChecked
|
|
280
|
+
}));
|
|
281
|
+
});
|
|
295
282
|
const size = 16;
|
|
296
283
|
const disabledChecked = {
|
|
297
284
|
position: "absolute",
|
|
@@ -396,86 +383,70 @@ const _generateStyles = (checked, error) => {
|
|
|
396
383
|
return styles$4[styleKey];
|
|
397
384
|
};
|
|
398
385
|
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
386
|
+
const ChoiceInternal = React__namespace.forwardRef((props, ref) => {
|
|
387
|
+
const {
|
|
388
|
+
checked,
|
|
389
|
+
description,
|
|
390
|
+
disabled = false,
|
|
391
|
+
error = false,
|
|
392
|
+
id,
|
|
393
|
+
label,
|
|
394
|
+
onChange,
|
|
395
|
+
style,
|
|
396
|
+
className,
|
|
397
|
+
variant
|
|
398
|
+
} = props;
|
|
399
|
+
const handleClick = () => {
|
|
400
|
+
if (variant === "radio" && checked) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
onChange(!checked);
|
|
404
|
+
};
|
|
405
|
+
const getChoiceCoreComponent = () => {
|
|
406
|
+
if (variant === "radio") {
|
|
417
407
|
return RadioCore;
|
|
418
408
|
} else {
|
|
419
409
|
return CheckboxCore;
|
|
420
410
|
}
|
|
421
|
-
}
|
|
422
|
-
getLabel
|
|
423
|
-
const {
|
|
424
|
-
disabled,
|
|
425
|
-
label
|
|
426
|
-
} = this.props;
|
|
411
|
+
};
|
|
412
|
+
const getLabel = id => {
|
|
427
413
|
return React__namespace.createElement(wonderBlocksTypography.LabelMedium, {
|
|
428
414
|
style: [styles$3.label, disabled && styles$3.disabledLabel]
|
|
429
415
|
}, React__namespace.createElement("label", {
|
|
430
416
|
htmlFor: id
|
|
431
417
|
}, label));
|
|
432
|
-
}
|
|
433
|
-
getDescription
|
|
434
|
-
const {
|
|
435
|
-
description
|
|
436
|
-
} = this.props;
|
|
418
|
+
};
|
|
419
|
+
const getDescription = id => {
|
|
437
420
|
return React__namespace.createElement(wonderBlocksTypography.LabelSmall, {
|
|
438
421
|
style: styles$3.description,
|
|
439
422
|
id: id
|
|
440
423
|
}, description);
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
"aria-describedby": descriptionId,
|
|
468
|
-
onClick: this.handleClick
|
|
469
|
-
})), React__namespace.createElement(wonderBlocksLayout.Strut, {
|
|
470
|
-
size: Spacing__default["default"].xSmall_8
|
|
471
|
-
}), label && this.getLabel(uniqueId)), description && this.getDescription(descriptionId));
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
ChoiceInternal.defaultProps = {
|
|
476
|
-
disabled: false,
|
|
477
|
-
error: false
|
|
478
|
-
};
|
|
424
|
+
};
|
|
425
|
+
const ChoiceCore = getChoiceCoreComponent();
|
|
426
|
+
return React__namespace.createElement(wonderBlocksCore.UniqueIDProvider, {
|
|
427
|
+
mockOnFirstRender: true,
|
|
428
|
+
scope: "choice"
|
|
429
|
+
}, ids => {
|
|
430
|
+
const uniqueId = id || ids.get("main");
|
|
431
|
+
const descriptionId = description ? ids.get("description") : undefined;
|
|
432
|
+
return React__namespace.createElement(wonderBlocksCore.View, {
|
|
433
|
+
style: style,
|
|
434
|
+
className: className
|
|
435
|
+
}, React__namespace.createElement(wonderBlocksCore.View, {
|
|
436
|
+
style: styles$3.wrapper,
|
|
437
|
+
tabIndex: -1
|
|
438
|
+
}, React__namespace.createElement(ChoiceCore, _extends({}, props, {
|
|
439
|
+
id: uniqueId,
|
|
440
|
+
"aria-describedby": descriptionId,
|
|
441
|
+
onClick: handleClick,
|
|
442
|
+
disabled: disabled,
|
|
443
|
+
error: error,
|
|
444
|
+
ref: ref
|
|
445
|
+
})), React__namespace.createElement(wonderBlocksLayout.Strut, {
|
|
446
|
+
size: Spacing__default["default"].xSmall_8
|
|
447
|
+
}), label && getLabel(uniqueId)), description && getDescription(descriptionId));
|
|
448
|
+
});
|
|
449
|
+
});
|
|
479
450
|
const styles$3 = aphrodite.StyleSheet.create({
|
|
480
451
|
wrapper: {
|
|
481
452
|
flexDirection: "row",
|
|
@@ -495,54 +466,58 @@ const styles$3 = aphrodite.StyleSheet.create({
|
|
|
495
466
|
}
|
|
496
467
|
});
|
|
497
468
|
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
};
|
|
469
|
+
const Checkbox = React__namespace.forwardRef((props, ref) => {
|
|
470
|
+
const {
|
|
471
|
+
disabled = false,
|
|
472
|
+
error = false
|
|
473
|
+
} = props;
|
|
474
|
+
return React__namespace.createElement(ChoiceInternal, _extends({}, props, {
|
|
475
|
+
variant: "checkbox",
|
|
476
|
+
disabled: disabled,
|
|
477
|
+
error: error,
|
|
478
|
+
ref: ref
|
|
479
|
+
}));
|
|
480
|
+
});
|
|
509
481
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
482
|
+
const _excluded$2 = ["disabled", "error"];
|
|
483
|
+
const Radio = React__namespace.forwardRef((props, ref) => {
|
|
484
|
+
const {
|
|
485
|
+
disabled = false,
|
|
486
|
+
error = false
|
|
487
|
+
} = props,
|
|
488
|
+
otherProps = _objectWithoutPropertiesLoose(props, _excluded$2);
|
|
489
|
+
return React__namespace.createElement(ChoiceInternal, _extends({}, otherProps, {
|
|
490
|
+
variant: "radio",
|
|
491
|
+
disabled: disabled,
|
|
492
|
+
error: error,
|
|
493
|
+
ref: ref
|
|
494
|
+
}));
|
|
495
|
+
});
|
|
521
496
|
|
|
522
|
-
const _excluded$1 = ["value", "variant"];
|
|
523
|
-
|
|
524
|
-
|
|
497
|
+
const _excluded$1 = ["checked", "disabled", "onChange", "value", "variant"];
|
|
498
|
+
const Choice = React__namespace.forwardRef((props, ref) => {
|
|
499
|
+
const {
|
|
500
|
+
checked = false,
|
|
501
|
+
disabled = false,
|
|
502
|
+
onChange = () => {},
|
|
503
|
+
variant
|
|
504
|
+
} = props,
|
|
505
|
+
remainingProps = _objectWithoutPropertiesLoose(props, _excluded$1);
|
|
506
|
+
const getChoiceComponent = variant => {
|
|
525
507
|
if (variant === "checkbox") {
|
|
526
508
|
return Checkbox;
|
|
527
509
|
} else {
|
|
528
510
|
return Radio;
|
|
529
511
|
}
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
Choice.defaultProps = {
|
|
542
|
-
checked: false,
|
|
543
|
-
disabled: false,
|
|
544
|
-
onChange: () => {}
|
|
545
|
-
};
|
|
512
|
+
};
|
|
513
|
+
const ChoiceComponent = getChoiceComponent(variant);
|
|
514
|
+
return React__namespace.createElement(ChoiceComponent, _extends({}, remainingProps, {
|
|
515
|
+
checked: checked,
|
|
516
|
+
disabled: disabled,
|
|
517
|
+
onChange: onChange,
|
|
518
|
+
ref: ref
|
|
519
|
+
}));
|
|
520
|
+
});
|
|
546
521
|
|
|
547
522
|
const styles$2 = aphrodite.StyleSheet.create({
|
|
548
523
|
fieldset: {
|
|
@@ -568,12 +543,19 @@ const styles$2 = aphrodite.StyleSheet.create({
|
|
|
568
543
|
|
|
569
544
|
const StyledFieldset$1 = wonderBlocksCore.addStyle("fieldset");
|
|
570
545
|
const StyledLegend$1 = wonderBlocksCore.addStyle("legend");
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
546
|
+
const CheckboxGroup = React__namespace.forwardRef((props, ref) => {
|
|
547
|
+
const {
|
|
548
|
+
children,
|
|
549
|
+
label,
|
|
550
|
+
description,
|
|
551
|
+
errorMessage,
|
|
552
|
+
groupName,
|
|
553
|
+
onChange,
|
|
554
|
+
selectedValues,
|
|
555
|
+
style,
|
|
556
|
+
testId
|
|
557
|
+
} = props;
|
|
558
|
+
const handleChange = (changedValue, originalCheckedState) => {
|
|
577
559
|
if (originalCheckedState) {
|
|
578
560
|
const index = selectedValues.indexOf(changedValue);
|
|
579
561
|
const updatedSelection = [...selectedValues.slice(0, index), ...selectedValues.slice(index + 1)];
|
|
@@ -581,102 +563,88 @@ class CheckboxGroup extends React__namespace.Component {
|
|
|
581
563
|
} else {
|
|
582
564
|
onChange([...selectedValues, changedValue]);
|
|
583
565
|
}
|
|
584
|
-
}
|
|
585
|
-
|
|
566
|
+
};
|
|
567
|
+
const allChildren = React__namespace.Children.toArray(children).filter(Boolean);
|
|
568
|
+
return React__namespace.createElement(StyledFieldset$1, {
|
|
569
|
+
"data-test-id": testId,
|
|
570
|
+
style: styles$2.fieldset,
|
|
571
|
+
ref: ref
|
|
572
|
+
}, React__namespace.createElement(wonderBlocksCore.View, {
|
|
573
|
+
style: style
|
|
574
|
+
}, label && React__namespace.createElement(StyledLegend$1, {
|
|
575
|
+
style: styles$2.legend
|
|
576
|
+
}, React__namespace.createElement(wonderBlocksTypography.LabelMedium, null, label)), description && React__namespace.createElement(wonderBlocksTypography.LabelSmall, {
|
|
577
|
+
style: styles$2.description
|
|
578
|
+
}, description), errorMessage && React__namespace.createElement(wonderBlocksTypography.LabelSmall, {
|
|
579
|
+
style: styles$2.error
|
|
580
|
+
}, errorMessage), (label || description || errorMessage) && React__namespace.createElement(wonderBlocksLayout.Strut, {
|
|
581
|
+
size: Spacing__default["default"].small_12
|
|
582
|
+
}), allChildren.map((child, index) => {
|
|
586
583
|
const {
|
|
587
|
-
children,
|
|
588
|
-
label,
|
|
589
|
-
description,
|
|
590
|
-
errorMessage,
|
|
591
|
-
groupName,
|
|
592
|
-
selectedValues,
|
|
593
584
|
style,
|
|
594
|
-
|
|
595
|
-
} =
|
|
596
|
-
const
|
|
597
|
-
return React__namespace.
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
size: Spacing__default["default"].small_12
|
|
610
|
-
}), allChildren.map((child, index) => {
|
|
611
|
-
const {
|
|
612
|
-
style,
|
|
613
|
-
value
|
|
614
|
-
} = child.props;
|
|
615
|
-
const checked = selectedValues.includes(value);
|
|
616
|
-
return React__namespace.cloneElement(child, {
|
|
617
|
-
checked: checked,
|
|
618
|
-
error: !!errorMessage,
|
|
619
|
-
groupName: groupName,
|
|
620
|
-
id: `${groupName}-${value}`,
|
|
621
|
-
key: value,
|
|
622
|
-
onChange: () => this.handleChange(value, checked),
|
|
623
|
-
style: [index > 0 && styles$2.defaultLineGap, style],
|
|
624
|
-
variant: "checkbox"
|
|
625
|
-
});
|
|
626
|
-
})));
|
|
627
|
-
}
|
|
628
|
-
}
|
|
585
|
+
value
|
|
586
|
+
} = child.props;
|
|
587
|
+
const checked = selectedValues.includes(value);
|
|
588
|
+
return React__namespace.cloneElement(child, {
|
|
589
|
+
checked: checked,
|
|
590
|
+
error: !!errorMessage,
|
|
591
|
+
groupName: groupName,
|
|
592
|
+
id: `${groupName}-${value}`,
|
|
593
|
+
key: value,
|
|
594
|
+
onChange: () => handleChange(value, checked),
|
|
595
|
+
style: [index > 0 && styles$2.defaultLineGap, style],
|
|
596
|
+
variant: "checkbox"
|
|
597
|
+
});
|
|
598
|
+
})));
|
|
599
|
+
});
|
|
629
600
|
|
|
630
601
|
const StyledFieldset = wonderBlocksCore.addStyle("fieldset");
|
|
631
602
|
const StyledLegend = wonderBlocksCore.addStyle("legend");
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
603
|
+
const RadioGroup = React__namespace.forwardRef((props, ref) => {
|
|
604
|
+
const {
|
|
605
|
+
children,
|
|
606
|
+
label,
|
|
607
|
+
description,
|
|
608
|
+
errorMessage,
|
|
609
|
+
groupName,
|
|
610
|
+
onChange,
|
|
611
|
+
selectedValue,
|
|
612
|
+
style,
|
|
613
|
+
testId
|
|
614
|
+
} = props;
|
|
615
|
+
const allChildren = React__namespace.Children.toArray(children).filter(Boolean);
|
|
616
|
+
return React__namespace.createElement(StyledFieldset, {
|
|
617
|
+
"data-test-id": testId,
|
|
618
|
+
style: styles$2.fieldset,
|
|
619
|
+
ref: ref
|
|
620
|
+
}, React__namespace.createElement(wonderBlocksCore.View, {
|
|
621
|
+
style: style
|
|
622
|
+
}, label && React__namespace.createElement(StyledLegend, {
|
|
623
|
+
style: styles$2.legend
|
|
624
|
+
}, React__namespace.createElement(wonderBlocksTypography.LabelMedium, null, label)), description && React__namespace.createElement(wonderBlocksTypography.LabelSmall, {
|
|
625
|
+
style: styles$2.description
|
|
626
|
+
}, description), errorMessage && React__namespace.createElement(wonderBlocksTypography.LabelSmall, {
|
|
627
|
+
style: styles$2.error
|
|
628
|
+
}, errorMessage), (label || description || errorMessage) && React__namespace.createElement(wonderBlocksLayout.Strut, {
|
|
629
|
+
size: Spacing__default["default"].small_12
|
|
630
|
+
}), allChildren.map((child, index) => {
|
|
637
631
|
const {
|
|
638
|
-
children,
|
|
639
|
-
label,
|
|
640
|
-
description,
|
|
641
|
-
errorMessage,
|
|
642
|
-
groupName,
|
|
643
|
-
selectedValue,
|
|
644
632
|
style,
|
|
645
|
-
|
|
646
|
-
} =
|
|
647
|
-
const
|
|
648
|
-
return React__namespace.
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
size: Spacing__default["default"].small_12
|
|
661
|
-
}), allChildren.map((child, index) => {
|
|
662
|
-
const {
|
|
663
|
-
style,
|
|
664
|
-
value
|
|
665
|
-
} = child.props;
|
|
666
|
-
const checked = selectedValue === value;
|
|
667
|
-
return React__namespace.cloneElement(child, {
|
|
668
|
-
checked: checked,
|
|
669
|
-
error: !!errorMessage,
|
|
670
|
-
groupName: groupName,
|
|
671
|
-
id: `${groupName}-${value}`,
|
|
672
|
-
key: value,
|
|
673
|
-
onChange: () => this.handleChange(value),
|
|
674
|
-
style: [index > 0 && styles$2.defaultLineGap, style],
|
|
675
|
-
variant: "radio"
|
|
676
|
-
});
|
|
677
|
-
})));
|
|
678
|
-
}
|
|
679
|
-
}
|
|
633
|
+
value
|
|
634
|
+
} = child.props;
|
|
635
|
+
const checked = selectedValue === value;
|
|
636
|
+
return React__namespace.cloneElement(child, {
|
|
637
|
+
checked: checked,
|
|
638
|
+
error: !!errorMessage,
|
|
639
|
+
groupName: groupName,
|
|
640
|
+
id: `${groupName}-${value}`,
|
|
641
|
+
key: value,
|
|
642
|
+
onChange: () => onChange(value),
|
|
643
|
+
style: [index > 0 && styles$2.defaultLineGap, style],
|
|
644
|
+
variant: "radio"
|
|
645
|
+
});
|
|
646
|
+
})));
|
|
647
|
+
});
|
|
680
648
|
|
|
681
649
|
const _excluded = ["id", "type", "value", "disabled", "onKeyDown", "placeholder", "light", "style", "testId", "readOnly", "autoFocus", "autoComplete", "forwardedRef", "onFocus", "onBlur", "onValidate", "validate", "onChange", "required"];
|
|
682
650
|
const defaultErrorMessage = "This field is required.";
|
package/dist/util/types.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export type ChoiceComponentProps = ChoiceCoreProps & {
|
|
|
34
34
|
};
|
|
35
35
|
export type SharedGroupProps = {
|
|
36
36
|
/** Children should be Choice components. */
|
|
37
|
-
children: Choice;
|
|
37
|
+
children: typeof Choice;
|
|
38
38
|
/** Group name for this checkbox or radio group. Should be unique for all
|
|
39
39
|
* such groups displayed on a page. */
|
|
40
40
|
groupName: string;
|
package/dist/util/types.js.flow
CHANGED