@khanacademy/wonder-blocks-form 4.0.7 → 4.0.9
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 +24 -0
- package/dist/components/checkbox-core.d.ts +1 -8
- package/dist/components/checkbox-core.js.flow +4 -10
- package/dist/components/choice-internal.d.ts +1 -2
- package/dist/components/choice-internal.js.flow +1 -2
- package/dist/components/radio-core.d.ts +1 -8
- package/dist/components/radio-core.js.flow +4 -10
- package/dist/es/index.js +84 -85
- package/dist/index.js +83 -84
- package/dist/util/types.d.ts +2 -0
- package/dist/util/types.js.flow +5 -0
- package/package.json +7 -7
- package/src/__tests__/__snapshots__/custom-snapshot.test.tsx.snap +168 -958
- package/src/__tests__/custom-snapshot.test.tsx +28 -43
- package/src/components/__tests__/checkbox.test.js +84 -0
- package/src/components/__tests__/labeled-text-field.test.tsx +4 -1
- package/src/components/checkbox-core.tsx +37 -34
- package/src/components/checkbox-group.tsx +2 -2
- package/src/components/choice-internal.tsx +31 -39
- package/src/components/radio-core.tsx +37 -34
- package/src/components/radio-group.tsx +2 -2
- package/src/components/text-field.tsx +13 -8
- package/src/util/types.ts +2 -0
- package/tsconfig.tsbuildinfo +1 -1
package/dist/index.js
CHANGED
|
@@ -6,7 +6,6 @@ var React = require('react');
|
|
|
6
6
|
var aphrodite = require('aphrodite');
|
|
7
7
|
var Color = require('@khanacademy/wonder-blocks-color');
|
|
8
8
|
var wonderBlocksCore = require('@khanacademy/wonder-blocks-core');
|
|
9
|
-
var wonderBlocksClickable = require('@khanacademy/wonder-blocks-clickable');
|
|
10
9
|
var wonderBlocksLayout = require('@khanacademy/wonder-blocks-layout');
|
|
11
10
|
var Spacing = require('@khanacademy/wonder-blocks-spacing');
|
|
12
11
|
var wonderBlocksTypography = require('@khanacademy/wonder-blocks-typography');
|
|
@@ -65,7 +64,7 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
65
64
|
return target;
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
const _excluded$4 = ["checked", "disabled", "error", "groupName", "id", "testId"
|
|
67
|
+
const _excluded$4 = ["checked", "disabled", "error", "groupName", "id", "testId"];
|
|
69
68
|
const {
|
|
70
69
|
blue: blue$1,
|
|
71
70
|
red: red$1,
|
|
@@ -75,7 +74,7 @@ const {
|
|
|
75
74
|
offBlack32: offBlack32$1,
|
|
76
75
|
offBlack50: offBlack50$1
|
|
77
76
|
} = Color__default["default"];
|
|
78
|
-
const StyledInput$
|
|
77
|
+
const StyledInput$2 = wonderBlocksCore.addStyle("input");
|
|
79
78
|
const checkboxCheck = {
|
|
80
79
|
small: "M11.263 4.324a1 1 0 1 1 1.474 1.352l-5.5 6a1 1 0 0 1-1.505-.036l-2.5-3a1 1 0 1 1 1.536-1.28L6.536 9.48l4.727-5.157z"
|
|
81
80
|
};
|
|
@@ -94,18 +93,15 @@ class CheckboxCore extends React__namespace.Component {
|
|
|
94
93
|
error,
|
|
95
94
|
groupName,
|
|
96
95
|
id,
|
|
97
|
-
testId
|
|
98
|
-
hovered,
|
|
99
|
-
focused,
|
|
100
|
-
pressed
|
|
96
|
+
testId
|
|
101
97
|
} = _this$props,
|
|
102
98
|
sharedProps = _objectWithoutPropertiesLoose(_this$props, _excluded$4);
|
|
103
99
|
const stateStyles = _generateStyles$1(checked, error);
|
|
104
|
-
const defaultStyle = [sharedStyles$1.inputReset, sharedStyles$1.default,
|
|
100
|
+
const defaultStyle = [sharedStyles$1.inputReset, sharedStyles$1.default, !disabled && stateStyles.default, disabled && sharedStyles$1.disabled];
|
|
105
101
|
const props = {
|
|
106
102
|
"data-test-id": testId
|
|
107
103
|
};
|
|
108
|
-
return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement(StyledInput$
|
|
104
|
+
return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement(StyledInput$2, _extends({}, sharedProps, {
|
|
109
105
|
type: "checkbox",
|
|
110
106
|
"aria-invalid": error,
|
|
111
107
|
checked: checked,
|
|
@@ -180,31 +176,39 @@ const _generateStyles$1 = (checked, error) => {
|
|
|
180
176
|
newStyles = {
|
|
181
177
|
default: {
|
|
182
178
|
backgroundColor: palette.base,
|
|
183
|
-
borderWidth: 0
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
179
|
+
borderWidth: 0,
|
|
180
|
+
":focus-visible": {
|
|
181
|
+
boxShadow: `0 0 0 1px ${white$1}, 0 0 0 3px ${palette.base}`
|
|
182
|
+
},
|
|
183
|
+
":hover": {
|
|
184
|
+
boxShadow: `0 0 0 1px ${white$1}, 0 0 0 3px ${palette.base}`
|
|
185
|
+
},
|
|
186
|
+
":active": {
|
|
187
|
+
boxShadow: `0 0 0 1px ${white$1}, 0 0 0 3px ${palette.active}`,
|
|
188
|
+
background: palette.active
|
|
189
|
+
}
|
|
191
190
|
}
|
|
192
191
|
};
|
|
193
192
|
} else {
|
|
194
193
|
newStyles = {
|
|
195
194
|
default: {
|
|
196
195
|
backgroundColor: error ? fadedRed$1 : white$1,
|
|
197
|
-
borderColor: error ? red$1 : offBlack50$1
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
196
|
+
borderColor: error ? red$1 : offBlack50$1,
|
|
197
|
+
":focus-visible": {
|
|
198
|
+
backgroundColor: error ? fadedRed$1 : white$1,
|
|
199
|
+
borderColor: palette.base,
|
|
200
|
+
borderWidth: 2
|
|
201
|
+
},
|
|
202
|
+
":hover": {
|
|
203
|
+
backgroundColor: error ? fadedRed$1 : white$1,
|
|
204
|
+
borderColor: palette.base,
|
|
205
|
+
borderWidth: 2
|
|
206
|
+
},
|
|
207
|
+
":active": {
|
|
208
|
+
backgroundColor: palette.faded,
|
|
209
|
+
borderColor: error ? activeRed$1 : blue$1,
|
|
210
|
+
borderWidth: 2
|
|
211
|
+
}
|
|
208
212
|
}
|
|
209
213
|
};
|
|
210
214
|
}
|
|
@@ -212,7 +216,7 @@ const _generateStyles$1 = (checked, error) => {
|
|
|
212
216
|
return styles$5[styleKey];
|
|
213
217
|
};
|
|
214
218
|
|
|
215
|
-
const _excluded$3 = ["checked", "disabled", "error", "groupName", "id", "testId"
|
|
219
|
+
const _excluded$3 = ["checked", "disabled", "error", "groupName", "id", "testId"];
|
|
216
220
|
const {
|
|
217
221
|
blue,
|
|
218
222
|
red,
|
|
@@ -222,7 +226,7 @@ const {
|
|
|
222
226
|
offBlack32,
|
|
223
227
|
offBlack50
|
|
224
228
|
} = Color__default["default"];
|
|
225
|
-
const StyledInput = wonderBlocksCore.addStyle("input");
|
|
229
|
+
const StyledInput$1 = wonderBlocksCore.addStyle("input");
|
|
226
230
|
class RadioCore extends React__namespace.Component {
|
|
227
231
|
constructor(...args) {
|
|
228
232
|
super(...args);
|
|
@@ -238,18 +242,15 @@ class RadioCore extends React__namespace.Component {
|
|
|
238
242
|
error,
|
|
239
243
|
groupName,
|
|
240
244
|
id,
|
|
241
|
-
testId
|
|
242
|
-
hovered,
|
|
243
|
-
focused,
|
|
244
|
-
pressed
|
|
245
|
+
testId
|
|
245
246
|
} = _this$props,
|
|
246
247
|
sharedProps = _objectWithoutPropertiesLoose(_this$props, _excluded$3);
|
|
247
248
|
const stateStyles = _generateStyles(checked, error);
|
|
248
|
-
const defaultStyle = [sharedStyles.inputReset, sharedStyles.default,
|
|
249
|
+
const defaultStyle = [sharedStyles.inputReset, sharedStyles.default, !disabled && stateStyles.default, disabled && sharedStyles.disabled];
|
|
249
250
|
const props = {
|
|
250
251
|
"data-test-id": testId
|
|
251
252
|
};
|
|
252
|
-
return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement(StyledInput, _extends({}, sharedProps, {
|
|
253
|
+
return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement(StyledInput$1, _extends({}, sharedProps, {
|
|
253
254
|
type: "radio",
|
|
254
255
|
"aria-invalid": error,
|
|
255
256
|
checked: checked,
|
|
@@ -327,31 +328,39 @@ const _generateStyles = (checked, error) => {
|
|
|
327
328
|
default: {
|
|
328
329
|
backgroundColor: white,
|
|
329
330
|
borderColor: palette.base,
|
|
330
|
-
borderWidth: size / 4
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
331
|
+
borderWidth: size / 4,
|
|
332
|
+
":focus-visible": {
|
|
333
|
+
boxShadow: `0 0 0 1px ${white}, 0 0 0 3px ${palette.base}`
|
|
334
|
+
},
|
|
335
|
+
":hover": {
|
|
336
|
+
boxShadow: `0 0 0 1px ${white}, 0 0 0 3px ${palette.base}`
|
|
337
|
+
},
|
|
338
|
+
":active": {
|
|
339
|
+
boxShadow: `0 0 0 1px ${white}, 0 0 0 3px ${palette.active}`,
|
|
340
|
+
borderColor: palette.active
|
|
341
|
+
}
|
|
338
342
|
}
|
|
339
343
|
};
|
|
340
344
|
} else {
|
|
341
345
|
newStyles = {
|
|
342
346
|
default: {
|
|
343
347
|
backgroundColor: error ? fadedRed : white,
|
|
344
|
-
borderColor: error ? red : offBlack50
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
348
|
+
borderColor: error ? red : offBlack50,
|
|
349
|
+
":focus-visible": {
|
|
350
|
+
backgroundColor: error ? fadedRed : white,
|
|
351
|
+
borderColor: palette.base,
|
|
352
|
+
borderWidth: 2
|
|
353
|
+
},
|
|
354
|
+
":hover": {
|
|
355
|
+
backgroundColor: error ? fadedRed : white,
|
|
356
|
+
borderColor: palette.base,
|
|
357
|
+
borderWidth: 2
|
|
358
|
+
},
|
|
359
|
+
":active": {
|
|
360
|
+
backgroundColor: palette.faded,
|
|
361
|
+
borderColor: error ? activeRed : blue,
|
|
362
|
+
borderWidth: 2
|
|
363
|
+
}
|
|
355
364
|
}
|
|
356
365
|
};
|
|
357
366
|
}
|
|
@@ -359,13 +368,10 @@ const _generateStyles = (checked, error) => {
|
|
|
359
368
|
return styles$4[styleKey];
|
|
360
369
|
};
|
|
361
370
|
|
|
362
|
-
const _excluded$2 = ["label", "description", "onChange", "style", "className", "variant"];
|
|
371
|
+
const _excluded$2 = ["label", "description", "id", "onChange", "style", "className", "variant"];
|
|
363
372
|
class ChoiceInternal extends React__namespace.Component {
|
|
364
373
|
constructor(...args) {
|
|
365
374
|
super(...args);
|
|
366
|
-
this.handleLabelClick = event => {
|
|
367
|
-
event.preventDefault();
|
|
368
|
-
};
|
|
369
375
|
this.handleClick = () => {
|
|
370
376
|
const {
|
|
371
377
|
checked,
|
|
@@ -385,17 +391,15 @@ class ChoiceInternal extends React__namespace.Component {
|
|
|
385
391
|
return CheckboxCore;
|
|
386
392
|
}
|
|
387
393
|
}
|
|
388
|
-
getLabel() {
|
|
394
|
+
getLabel(id) {
|
|
389
395
|
const {
|
|
390
396
|
disabled,
|
|
391
|
-
id,
|
|
392
397
|
label
|
|
393
398
|
} = this.props;
|
|
394
399
|
return React__namespace.createElement(wonderBlocksTypography.LabelMedium, {
|
|
395
400
|
style: [styles$3.label, disabled && styles$3.disabledLabel]
|
|
396
401
|
}, React__namespace.createElement("label", {
|
|
397
|
-
htmlFor: id
|
|
398
|
-
onClick: this.handleLabelClick
|
|
402
|
+
htmlFor: id
|
|
399
403
|
}, label));
|
|
400
404
|
}
|
|
401
405
|
getDescription(id) {
|
|
@@ -412,36 +416,31 @@ class ChoiceInternal extends React__namespace.Component {
|
|
|
412
416
|
{
|
|
413
417
|
label,
|
|
414
418
|
description,
|
|
419
|
+
id,
|
|
415
420
|
style,
|
|
416
|
-
className
|
|
417
|
-
variant
|
|
421
|
+
className
|
|
418
422
|
} = _this$props,
|
|
419
423
|
coreProps = _objectWithoutPropertiesLoose(_this$props, _excluded$2);
|
|
420
424
|
const ChoiceCore = this.getChoiceCoreComponent();
|
|
421
|
-
const ClickableBehavior = wonderBlocksClickable.getClickableBehavior();
|
|
422
425
|
return React__namespace.createElement(wonderBlocksCore.UniqueIDProvider, {
|
|
423
426
|
mockOnFirstRender: true,
|
|
424
427
|
scope: "choice"
|
|
425
428
|
}, ids => {
|
|
429
|
+
const uniqueId = id || ids.get("main");
|
|
426
430
|
const descriptionId = description ? ids.get("description") : undefined;
|
|
427
431
|
return React__namespace.createElement(wonderBlocksCore.View, {
|
|
428
432
|
style: style,
|
|
429
433
|
className: className
|
|
430
|
-
}, React__namespace.createElement(
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
"aria-describedby": descriptionId
|
|
441
|
-
})), React__namespace.createElement(wonderBlocksLayout.Strut, {
|
|
442
|
-
size: Spacing__default["default"].xSmall_8
|
|
443
|
-
}), label && this.getLabel());
|
|
444
|
-
}), description && this.getDescription(descriptionId));
|
|
434
|
+
}, React__namespace.createElement(wonderBlocksCore.View, {
|
|
435
|
+
style: styles$3.wrapper,
|
|
436
|
+
tabIndex: -1
|
|
437
|
+
}, React__namespace.createElement(ChoiceCore, _extends({}, coreProps, {
|
|
438
|
+
id: uniqueId,
|
|
439
|
+
"aria-describedby": descriptionId,
|
|
440
|
+
onClick: this.handleClick
|
|
441
|
+
})), React__namespace.createElement(wonderBlocksLayout.Strut, {
|
|
442
|
+
size: Spacing__default["default"].xSmall_8
|
|
443
|
+
}), label && this.getLabel(uniqueId)), description && this.getDescription(descriptionId));
|
|
445
444
|
});
|
|
446
445
|
}
|
|
447
446
|
}
|
|
@@ -457,7 +456,6 @@ const styles$3 = aphrodite.StyleSheet.create({
|
|
|
457
456
|
outline: "none"
|
|
458
457
|
},
|
|
459
458
|
label: {
|
|
460
|
-
userSelect: "none",
|
|
461
459
|
marginTop: -2
|
|
462
460
|
},
|
|
463
461
|
disabledLabel: {
|
|
@@ -655,6 +653,7 @@ class RadioGroup extends React__namespace.Component {
|
|
|
655
653
|
|
|
656
654
|
const _excluded = ["id", "type", "value", "disabled", "onKeyDown", "placeholder", "light", "style", "testId", "readOnly", "autoComplete", "forwardedRef", "onFocus", "onBlur", "onValidate", "validate", "onChange", "required"];
|
|
657
655
|
const defaultErrorMessage = "This field is required.";
|
|
656
|
+
const StyledInput = wonderBlocksCore.addStyle("input");
|
|
658
657
|
class TextField extends React__namespace.Component {
|
|
659
658
|
constructor(props) {
|
|
660
659
|
super(props);
|
|
@@ -747,8 +746,8 @@ class TextField extends React__namespace.Component {
|
|
|
747
746
|
forwardedRef
|
|
748
747
|
} = _this$props,
|
|
749
748
|
otherProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
|
|
750
|
-
return React__namespace.createElement(
|
|
751
|
-
|
|
749
|
+
return React__namespace.createElement(StyledInput, _extends({
|
|
750
|
+
style: [styles$1.input, wonderBlocksTypography.styles.LabelMedium, styles$1.default, disabled ? styles$1.disabled : this.state.focused ? [styles$1.focused, light && styles$1.defaultLight] : !!this.state.error && [styles$1.error, light && styles$1.errorLight], !!this.state.error && styles$1.error, style && style],
|
|
752
751
|
id: id,
|
|
753
752
|
type: type,
|
|
754
753
|
placeholder: placeholder,
|
package/dist/util/types.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export type ChoiceCoreProps = AriaProps & {
|
|
|
15
15
|
id?: string;
|
|
16
16
|
/** Optional test ID for e2e testing */
|
|
17
17
|
testId?: string;
|
|
18
|
+
/** Function that executes when the choice is clicked. */
|
|
19
|
+
onClick: () => void;
|
|
18
20
|
};
|
|
19
21
|
export type ChoiceComponentProps = ChoiceCoreProps & {
|
|
20
22
|
/** Callback when this component is selected. The newCheckedState is the
|
package/dist/util/types.js.flow
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-form",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.9",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"description": "Form components for Wonder Blocks.",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,19 +16,19 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@babel/runtime": "^7.18.6",
|
|
19
|
-
"@khanacademy/wonder-blocks-clickable": "^3.0.
|
|
19
|
+
"@khanacademy/wonder-blocks-clickable": "^3.0.9",
|
|
20
20
|
"@khanacademy/wonder-blocks-color": "^2.0.1",
|
|
21
|
-
"@khanacademy/wonder-blocks-core": "^5.0
|
|
22
|
-
"@khanacademy/wonder-blocks-icon": "^2.0.
|
|
23
|
-
"@khanacademy/wonder-blocks-layout": "^2.0.
|
|
21
|
+
"@khanacademy/wonder-blocks-core": "^5.1.0",
|
|
22
|
+
"@khanacademy/wonder-blocks-icon": "^2.0.9",
|
|
23
|
+
"@khanacademy/wonder-blocks-layout": "^2.0.9",
|
|
24
24
|
"@khanacademy/wonder-blocks-spacing": "^4.0.1",
|
|
25
|
-
"@khanacademy/wonder-blocks-typography": "^2.0.
|
|
25
|
+
"@khanacademy/wonder-blocks-typography": "^2.0.9"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"aphrodite": "^1.2.5",
|
|
29
29
|
"react": "16.14.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"wb-dev-build-settings": "^0.9.
|
|
32
|
+
"wb-dev-build-settings": "^0.9.7"
|
|
33
33
|
}
|
|
34
34
|
}
|