@khanacademy/wonder-blocks-form 3.1.10 → 3.1.12
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 +46 -0
- package/dist/components/checkbox-core.d.ts +16 -0
- package/dist/components/checkbox-core.js.flow +26 -0
- package/dist/components/checkbox-group.d.ts +84 -0
- package/dist/components/checkbox-group.js.flow +103 -0
- package/dist/components/checkbox.d.ts +83 -0
- package/dist/components/checkbox.js.flow +106 -0
- package/dist/components/choice-internal.d.ts +63 -0
- package/dist/components/choice-internal.js.flow +100 -0
- package/dist/components/choice.d.ts +127 -0
- package/dist/components/choice.js.flow +161 -0
- package/dist/components/field-heading.d.ts +50 -0
- package/dist/components/field-heading.js.flow +64 -0
- package/dist/components/group-styles.d.ts +3 -0
- package/dist/components/group-styles.js.flow +10 -0
- package/dist/components/labeled-text-field.d.ts +169 -0
- package/dist/components/labeled-text-field.js.flow +211 -0
- package/dist/components/radio-core.d.ts +15 -0
- package/dist/components/radio-core.js.flow +26 -0
- package/dist/components/radio-group.d.ts +85 -0
- package/dist/components/radio-group.js.flow +104 -0
- package/dist/components/radio.d.ts +68 -0
- package/dist/components/radio.js.flow +92 -0
- package/dist/components/text-field.d.ts +146 -0
- package/dist/components/text-field.js.flow +186 -0
- package/dist/es/index.js +258 -224
- package/dist/index.d.ts +7 -0
- package/dist/index.js +281 -249
- package/dist/index.js.flow +21 -2
- package/dist/util/types.d.ts +62 -0
- package/dist/util/types.js.flow +138 -0
- package/package.json +10 -10
- package/src/__tests__/{custom-snapshot.test.js → custom-snapshot.test.tsx} +10 -11
- package/src/components/__tests__/{checkbox-group.test.js → checkbox-group.test.tsx} +7 -7
- package/src/components/__tests__/{field-heading.test.js → field-heading.test.tsx} +2 -3
- package/src/components/__tests__/{labeled-text-field.test.js → labeled-text-field.test.tsx} +5 -6
- package/src/components/__tests__/{radio-group.test.js → radio-group.test.tsx} +10 -10
- package/src/components/__tests__/{text-field.test.js → text-field.test.tsx} +23 -19
- package/src/components/{checkbox-core.js → checkbox-core.tsx} +13 -16
- package/src/components/{checkbox-group.js → checkbox-group.tsx} +21 -24
- package/src/components/{checkbox.js → checkbox.tsx} +19 -33
- package/src/components/{choice-internal.js → choice-internal.tsx} +27 -41
- package/src/components/{choice.js → choice.tsx} +26 -39
- package/src/components/{field-heading.js → field-heading.tsx} +16 -23
- package/src/components/{group-styles.js → group-styles.ts} +0 -1
- package/src/components/{labeled-text-field.js → labeled-text-field.tsx} +55 -70
- package/src/components/{radio-core.js → radio-core.tsx} +14 -17
- package/src/components/{radio-group.js → radio-group.tsx} +21 -24
- package/src/components/{radio.js → radio.tsx} +19 -33
- package/src/components/{text-field.js → text-field.tsx} +53 -64
- package/src/index.ts +15 -0
- package/src/util/{types.js → types.ts} +32 -35
- package/tsconfig.json +19 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/src/__docs__/_overview_.stories.mdx +0 -15
- package/src/components/__docs__/checkbox-accessibility.stories.mdx +0 -147
- package/src/components/__docs__/checkbox-group.stories.js +0 -300
- package/src/components/__docs__/checkbox.stories.js +0 -167
- package/src/components/__docs__/choice.stories.js +0 -86
- package/src/components/__docs__/labeled-text-field.argtypes.js +0 -248
- package/src/components/__docs__/labeled-text-field.stories.js +0 -709
- package/src/components/__docs__/radio-group.stories.js +0 -217
- package/src/components/__docs__/radio.stories.js +0 -161
- package/src/components/__docs__/text-field.argtypes.js +0 -206
- package/src/components/__docs__/text-field.stories.js +0 -780
- package/src/index.js +0 -16
- /package/src/__tests__/__snapshots__/{custom-snapshot.test.js.snap → custom-snapshot.test.tsx.snap} +0 -0
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import * as React from "react";
|
|
4
2
|
|
|
5
3
|
import {View, addStyle} from "@khanacademy/wonder-blocks-core";
|
|
@@ -8,61 +6,58 @@ import Spacing from "@khanacademy/wonder-blocks-spacing";
|
|
|
8
6
|
import {LabelMedium, LabelSmall} from "@khanacademy/wonder-blocks-typography";
|
|
9
7
|
import type {StyleType} from "@khanacademy/wonder-blocks-core";
|
|
10
8
|
|
|
11
|
-
import styles from "./group-styles
|
|
12
|
-
import
|
|
9
|
+
import styles from "./group-styles";
|
|
10
|
+
import Choice from "./choice";
|
|
13
11
|
|
|
14
12
|
// Keep synced with CheckboxGroupProps in ../util/types.js
|
|
15
|
-
type CheckboxGroupProps = {
|
|
13
|
+
type CheckboxGroupProps = {
|
|
16
14
|
/**
|
|
17
15
|
* Children should be Choice components.
|
|
18
16
|
*/
|
|
19
|
-
children: Array
|
|
20
|
-
|
|
17
|
+
children: Array<
|
|
18
|
+
| React.ReactElement<React.ComponentProps<typeof Choice>>
|
|
19
|
+
| false
|
|
20
|
+
| null
|
|
21
|
+
| undefined
|
|
22
|
+
>;
|
|
21
23
|
/**
|
|
22
24
|
* Group name for this checkbox or radio group. Should be unique for all
|
|
23
25
|
* such groups displayed on a page.
|
|
24
26
|
*/
|
|
25
|
-
groupName: string
|
|
26
|
-
|
|
27
|
+
groupName: string;
|
|
27
28
|
/**
|
|
28
29
|
* Optional label for the group. This label is optional to allow for
|
|
29
30
|
* greater flexibility in implementing checkbox and radio groups.
|
|
30
31
|
*/
|
|
31
|
-
label?: React.
|
|
32
|
-
|
|
32
|
+
label?: React.ReactNode;
|
|
33
33
|
/**
|
|
34
34
|
* Optional description for the group.
|
|
35
35
|
*/
|
|
36
|
-
description?: React.
|
|
37
|
-
|
|
36
|
+
description?: React.ReactNode;
|
|
38
37
|
/**
|
|
39
38
|
* Optional error message. If supplied, the group will be displayed in an
|
|
40
39
|
* error state, along with this error message. If no error state is desired,
|
|
41
40
|
* simply do not supply this prop, or pass along null.
|
|
42
41
|
*/
|
|
43
|
-
errorMessage?:
|
|
44
|
-
|
|
42
|
+
errorMessage?: string | null | undefined;
|
|
45
43
|
/**
|
|
46
44
|
* Custom styling for this group of checkboxes.
|
|
47
45
|
*/
|
|
48
|
-
style?: StyleType
|
|
49
|
-
|
|
46
|
+
style?: StyleType;
|
|
50
47
|
/**
|
|
51
48
|
* Callback for when selection of the group has changed. Passes the newly
|
|
52
49
|
* selected values.
|
|
53
50
|
*/
|
|
54
|
-
onChange: (selectedValues: Array<string>) =>
|
|
55
|
-
|
|
51
|
+
onChange: (selectedValues: Array<string>) => unknown;
|
|
56
52
|
/**
|
|
57
53
|
* An array of the values of the selected values in this checkbox group.
|
|
58
54
|
*/
|
|
59
|
-
selectedValues: Array<string
|
|
60
|
-
|
|
55
|
+
selectedValues: Array<string>;
|
|
61
56
|
/**
|
|
62
57
|
* Test ID used for e2e testing.
|
|
63
58
|
*/
|
|
64
|
-
testId?: string
|
|
65
|
-
|
|
59
|
+
testId?: string;
|
|
60
|
+
};
|
|
66
61
|
|
|
67
62
|
const StyledFieldset = addStyle<"fieldset">("fieldset");
|
|
68
63
|
const StyledLegend = addStyle<"legend">("legend");
|
|
@@ -116,7 +111,7 @@ export default class CheckboxGroup extends React.Component<CheckboxGroupProps> {
|
|
|
116
111
|
}
|
|
117
112
|
}
|
|
118
113
|
|
|
119
|
-
render(): React.
|
|
114
|
+
render(): React.ReactElement {
|
|
120
115
|
const {
|
|
121
116
|
children,
|
|
122
117
|
label,
|
|
@@ -154,8 +149,10 @@ export default class CheckboxGroup extends React.Component<CheckboxGroupProps> {
|
|
|
154
149
|
)}
|
|
155
150
|
|
|
156
151
|
{allChildren.map((child, index) => {
|
|
152
|
+
// @ts-expect-error [FEI-5019] - TS2339 - Property 'props' does not exist on type 'ReactChild | ReactFragment | ReactPortal'.
|
|
157
153
|
const {style, value} = child.props;
|
|
158
154
|
const checked = selectedValues.includes(value);
|
|
155
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
159
156
|
return React.cloneElement(child, {
|
|
160
157
|
checked: checked,
|
|
161
158
|
error: !!errorMessage,
|
|
@@ -1,79 +1,65 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import * as React from "react";
|
|
4
2
|
|
|
5
3
|
import type {AriaProps, StyleType} from "@khanacademy/wonder-blocks-core";
|
|
6
|
-
import ChoiceInternal from "./choice-internal
|
|
4
|
+
import ChoiceInternal from "./choice-internal";
|
|
7
5
|
|
|
8
6
|
// Keep synced with ChoiceComponentProps in ../util/types.js
|
|
9
|
-
type ChoiceComponentProps = {
|
|
10
|
-
...AriaProps,
|
|
11
|
-
|
|
7
|
+
type ChoiceComponentProps = AriaProps & {
|
|
12
8
|
/**
|
|
13
9
|
* Whether this component is checked
|
|
14
10
|
*/
|
|
15
|
-
checked: boolean
|
|
16
|
-
|
|
11
|
+
checked: boolean;
|
|
17
12
|
/**
|
|
18
13
|
* Whether this component is disabled
|
|
19
14
|
*/
|
|
20
|
-
disabled: boolean
|
|
21
|
-
|
|
15
|
+
disabled: boolean;
|
|
22
16
|
/**
|
|
23
17
|
* Whether this component should show an error state
|
|
24
18
|
*/
|
|
25
|
-
error: boolean
|
|
26
|
-
|
|
19
|
+
error: boolean;
|
|
27
20
|
/**
|
|
28
21
|
* Callback when this component is selected. The newCheckedState is the
|
|
29
22
|
* new checked state of the component.
|
|
30
23
|
*/
|
|
31
|
-
onChange: (newCheckedState: boolean) =>
|
|
32
|
-
|
|
24
|
+
onChange: (newCheckedState: boolean) => unknown;
|
|
33
25
|
/**
|
|
34
26
|
* Optional label for the field.
|
|
35
27
|
*/
|
|
36
|
-
label?: React.
|
|
37
|
-
|
|
28
|
+
label?: React.ReactNode;
|
|
38
29
|
/**
|
|
39
30
|
* Optional description for the field.
|
|
40
31
|
*/
|
|
41
|
-
description?: React.
|
|
42
|
-
|
|
32
|
+
description?: React.ReactNode;
|
|
43
33
|
/**
|
|
44
34
|
* Unique identifier attached to the HTML input element. If used, need to
|
|
45
35
|
* guarantee that the ID is unique within everything rendered on a page.
|
|
46
36
|
* Used to match `<label>` with `<input>` elements for screenreaders.
|
|
47
37
|
*/
|
|
48
|
-
id?: string
|
|
49
|
-
|
|
38
|
+
id?: string;
|
|
50
39
|
/**
|
|
51
40
|
* Optional styling for the container. Does not style the component.
|
|
52
41
|
*/
|
|
53
|
-
style?: StyleType
|
|
54
|
-
|
|
42
|
+
style?: StyleType;
|
|
55
43
|
/**
|
|
56
44
|
* Adds CSS classes to the Checkbox.
|
|
57
45
|
*/
|
|
58
|
-
className?: string
|
|
59
|
-
|
|
46
|
+
className?: string;
|
|
60
47
|
/**
|
|
61
48
|
* Optional test ID for e2e testing
|
|
62
49
|
*/
|
|
63
|
-
testId?: string
|
|
64
|
-
|
|
50
|
+
testId?: string;
|
|
65
51
|
/**
|
|
66
52
|
* Name for the checkbox or radio button group. Only applicable for group
|
|
67
53
|
* contexts, auto-populated by group components via Choice.
|
|
68
54
|
* @ignore
|
|
69
55
|
*/
|
|
70
|
-
groupName?: string
|
|
71
|
-
|
|
56
|
+
groupName?: string;
|
|
57
|
+
};
|
|
72
58
|
|
|
73
|
-
type DefaultProps = {
|
|
74
|
-
disabled:
|
|
75
|
-
error:
|
|
76
|
-
|
|
59
|
+
type DefaultProps = {
|
|
60
|
+
disabled: ChoiceComponentProps["disabled"];
|
|
61
|
+
error: ChoiceComponentProps["error"];
|
|
62
|
+
};
|
|
77
63
|
|
|
78
64
|
/**
|
|
79
65
|
* ☑️ A nicely styled checkbox for all your checking needs. Can optionally take
|
|
@@ -102,7 +88,7 @@ export default class Checkbox extends React.Component<ChoiceComponentProps> {
|
|
|
102
88
|
error: false,
|
|
103
89
|
};
|
|
104
90
|
|
|
105
|
-
render(): React.
|
|
91
|
+
render(): React.ReactElement {
|
|
106
92
|
return <ChoiceInternal variant="checkbox" {...this.props} />;
|
|
107
93
|
}
|
|
108
94
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import * as React from "react";
|
|
4
2
|
import {StyleSheet} from "aphrodite";
|
|
5
3
|
|
|
@@ -10,65 +8,52 @@ import {Strut} from "@khanacademy/wonder-blocks-layout";
|
|
|
10
8
|
import Spacing from "@khanacademy/wonder-blocks-spacing";
|
|
11
9
|
import {LabelMedium, LabelSmall} from "@khanacademy/wonder-blocks-typography";
|
|
12
10
|
import type {AriaProps, StyleType} from "@khanacademy/wonder-blocks-core";
|
|
13
|
-
import CheckboxCore from "./checkbox-core
|
|
14
|
-
import RadioCore from "./radio-core
|
|
15
|
-
|
|
16
|
-
type Props = {|
|
|
17
|
-
...AriaProps,
|
|
11
|
+
import CheckboxCore from "./checkbox-core";
|
|
12
|
+
import RadioCore from "./radio-core";
|
|
18
13
|
|
|
14
|
+
type Props = AriaProps & {
|
|
19
15
|
/** Whether this choice is checked. */
|
|
20
|
-
checked: boolean
|
|
21
|
-
|
|
16
|
+
checked: boolean;
|
|
22
17
|
/** Whether this choice option is disabled. */
|
|
23
|
-
disabled: boolean
|
|
24
|
-
|
|
18
|
+
disabled: boolean;
|
|
25
19
|
/** Whether this choice is in error mode. */
|
|
26
|
-
error: boolean
|
|
27
|
-
|
|
20
|
+
error: boolean;
|
|
28
21
|
/** Returns the new checked state of the component. */
|
|
29
|
-
onChange: (newCheckedState: boolean) =>
|
|
30
|
-
|
|
22
|
+
onChange: (newCheckedState: boolean) => unknown;
|
|
31
23
|
/**
|
|
32
24
|
* Used for accessibility purposes, where the label id should match the
|
|
33
25
|
* input id.
|
|
34
26
|
*/
|
|
35
|
-
id?: string
|
|
36
|
-
|
|
27
|
+
id?: string;
|
|
37
28
|
/**
|
|
38
29
|
* Optional additional styling.
|
|
39
30
|
*/
|
|
40
|
-
style?: StyleType
|
|
41
|
-
|
|
31
|
+
style?: StyleType;
|
|
42
32
|
/**
|
|
43
33
|
* Adds CSS classes to the Button.
|
|
44
34
|
*/
|
|
45
|
-
className?: string
|
|
46
|
-
|
|
35
|
+
className?: string;
|
|
47
36
|
/**
|
|
48
37
|
* Optional id for testing purposes.
|
|
49
38
|
*/
|
|
50
|
-
testId?: string
|
|
51
|
-
|
|
39
|
+
testId?: string;
|
|
52
40
|
/**
|
|
53
41
|
* Label for the field.
|
|
54
42
|
*/
|
|
55
|
-
label?: React.
|
|
56
|
-
|
|
43
|
+
label?: React.ReactNode;
|
|
57
44
|
/** Optional description for the field. */
|
|
58
|
-
description?: React.
|
|
59
|
-
|
|
45
|
+
description?: React.ReactNode;
|
|
60
46
|
/** Auto-populated by parent's groupName prop if in a group. */
|
|
61
|
-
groupName?: string
|
|
62
|
-
|
|
47
|
+
groupName?: string;
|
|
63
48
|
/** Takes either "radio" or "checkbox" value. */
|
|
64
|
-
variant: "radio" | "checkbox"
|
|
65
|
-
|
|
49
|
+
variant: "radio" | "checkbox";
|
|
50
|
+
};
|
|
66
51
|
|
|
67
|
-
type DefaultProps = {
|
|
68
|
-
checked:
|
|
69
|
-
disabled:
|
|
70
|
-
error:
|
|
71
|
-
|
|
52
|
+
type DefaultProps = {
|
|
53
|
+
checked: Props["checked"];
|
|
54
|
+
disabled: Props["disabled"];
|
|
55
|
+
error: Props["error"];
|
|
56
|
+
};
|
|
72
57
|
|
|
73
58
|
/**
|
|
74
59
|
* This is a potentially labeled 🔘 or ☑️ item. This is an internal component
|
|
@@ -84,7 +69,7 @@ type DefaultProps = {|
|
|
|
84
69
|
error: false,
|
|
85
70
|
};
|
|
86
71
|
|
|
87
|
-
handleLabelClick: (event: SyntheticEvent
|
|
72
|
+
handleLabelClick: (event: React.SyntheticEvent) => void = (event) => {
|
|
88
73
|
// Browsers automatically use the for attribute to select the input,
|
|
89
74
|
// but we use ClickableBehavior to handle this.
|
|
90
75
|
event.preventDefault();
|
|
@@ -106,7 +91,7 @@ type DefaultProps = {|
|
|
|
106
91
|
return CheckboxCore;
|
|
107
92
|
}
|
|
108
93
|
}
|
|
109
|
-
getLabel(): React.
|
|
94
|
+
getLabel(): React.ReactNode {
|
|
110
95
|
const {disabled, id, label} = this.props;
|
|
111
96
|
return (
|
|
112
97
|
<LabelMedium
|
|
@@ -118,7 +103,7 @@ type DefaultProps = {|
|
|
|
118
103
|
</LabelMedium>
|
|
119
104
|
);
|
|
120
105
|
}
|
|
121
|
-
getDescription(id
|
|
106
|
+
getDescription(id?: string): React.ReactNode {
|
|
122
107
|
const {description} = this.props;
|
|
123
108
|
return (
|
|
124
109
|
<LabelSmall style={styles.description} id={id}>
|
|
@@ -126,11 +111,11 @@ type DefaultProps = {|
|
|
|
126
111
|
</LabelSmall>
|
|
127
112
|
);
|
|
128
113
|
}
|
|
129
|
-
render(): React.
|
|
114
|
+
render(): React.ReactElement {
|
|
130
115
|
const {
|
|
131
116
|
label,
|
|
132
117
|
description,
|
|
133
|
-
// eslint-disable-next-line no-unused-vars
|
|
118
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
134
119
|
onChange,
|
|
135
120
|
style,
|
|
136
121
|
className,
|
|
@@ -147,6 +132,7 @@ type DefaultProps = {|
|
|
|
147
132
|
: undefined;
|
|
148
133
|
|
|
149
134
|
return (
|
|
135
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
150
136
|
<View style={style} className={className}>
|
|
151
137
|
<ClickableBehavior
|
|
152
138
|
disabled={coreProps.disabled}
|
|
@@ -1,76 +1,61 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import * as React from "react";
|
|
4
2
|
|
|
5
3
|
import type {AriaProps, StyleType} from "@khanacademy/wonder-blocks-core";
|
|
6
|
-
import Checkbox from "./checkbox
|
|
7
|
-
import Radio from "./radio
|
|
8
|
-
|
|
9
|
-
type Props = {|
|
|
10
|
-
...AriaProps,
|
|
4
|
+
import Checkbox from "./checkbox";
|
|
5
|
+
import Radio from "./radio";
|
|
11
6
|
|
|
7
|
+
type Props = AriaProps & {
|
|
12
8
|
/** User-defined. Label for the field. */
|
|
13
|
-
label: React.
|
|
14
|
-
|
|
9
|
+
label: React.ReactNode;
|
|
15
10
|
/** User-defined. Optional description for the field. */
|
|
16
|
-
description?: React.
|
|
17
|
-
|
|
11
|
+
description?: React.ReactNode;
|
|
18
12
|
/** User-defined. Should be distinct for each item in the group. */
|
|
19
|
-
value: string
|
|
20
|
-
|
|
13
|
+
value: string;
|
|
21
14
|
/** User-defined. Whether this choice option is disabled. Default false. */
|
|
22
|
-
disabled: boolean
|
|
23
|
-
|
|
15
|
+
disabled: boolean;
|
|
24
16
|
/** User-defined. Optional id for testing purposes. */
|
|
25
|
-
testId?: string
|
|
26
|
-
|
|
17
|
+
testId?: string;
|
|
27
18
|
/** User-defined. Optional additional styling. */
|
|
28
|
-
style?: StyleType
|
|
29
|
-
|
|
19
|
+
style?: StyleType;
|
|
30
20
|
/**
|
|
31
21
|
* Auto-populated by parent. Whether this choice is checked.
|
|
32
22
|
* @ignore
|
|
33
23
|
*/
|
|
34
|
-
checked: boolean
|
|
35
|
-
|
|
24
|
+
checked: boolean;
|
|
36
25
|
/**
|
|
37
26
|
* Auto-populated by parent. Whether this choice is in error mode (everything
|
|
38
27
|
* in a choice group would be in error mode at the same time).
|
|
39
28
|
* @ignore
|
|
40
29
|
*/
|
|
41
|
-
error?: boolean
|
|
42
|
-
|
|
30
|
+
error?: boolean;
|
|
43
31
|
/**
|
|
44
32
|
* Auto-populated by parent. Used for accessibility purposes, where the label
|
|
45
33
|
* id should match the input id.
|
|
46
34
|
* @ignore
|
|
47
35
|
*/
|
|
48
|
-
id?: string
|
|
49
|
-
|
|
36
|
+
id?: string;
|
|
50
37
|
/**
|
|
51
38
|
* Auto-populated by parent's groupName prop.
|
|
52
39
|
* @ignore
|
|
53
40
|
*/
|
|
54
|
-
groupName?: string
|
|
55
|
-
|
|
41
|
+
groupName?: string;
|
|
56
42
|
/**
|
|
57
43
|
* Auto-populated by parent. Returns the new checked state of the component.
|
|
58
44
|
* @ignore
|
|
59
45
|
*/
|
|
60
|
-
onChange: (newCheckedState: boolean) =>
|
|
61
|
-
|
|
46
|
+
onChange: (newCheckedState: boolean) => unknown;
|
|
62
47
|
/**
|
|
63
48
|
* Auto-populated by parent.
|
|
64
49
|
* @ignore
|
|
65
50
|
*/
|
|
66
|
-
variant?: "radio" | "checkbox"
|
|
67
|
-
|
|
51
|
+
variant?: "radio" | "checkbox";
|
|
52
|
+
};
|
|
68
53
|
|
|
69
|
-
type DefaultProps = {
|
|
70
|
-
checked:
|
|
71
|
-
disabled:
|
|
72
|
-
onChange:
|
|
73
|
-
|
|
54
|
+
type DefaultProps = {
|
|
55
|
+
checked: Props["checked"];
|
|
56
|
+
disabled: Props["disabled"];
|
|
57
|
+
onChange: Props["onChange"];
|
|
58
|
+
};
|
|
74
59
|
|
|
75
60
|
/**
|
|
76
61
|
* This is a labeled 🔘 or ☑️ item. Choice is meant to be used as children of
|
|
@@ -145,16 +130,18 @@ export default class Choice extends React.Component<Props> {
|
|
|
145
130
|
onChange: () => {},
|
|
146
131
|
};
|
|
147
132
|
|
|
148
|
-
getChoiceComponent(
|
|
133
|
+
getChoiceComponent(
|
|
134
|
+
variant?: string | null,
|
|
135
|
+
): typeof Radio | typeof Checkbox {
|
|
149
136
|
if (variant === "checkbox") {
|
|
150
137
|
return Checkbox;
|
|
151
138
|
} else {
|
|
152
139
|
return Radio;
|
|
153
140
|
}
|
|
154
141
|
}
|
|
155
|
-
render(): React.
|
|
142
|
+
render(): React.ReactElement {
|
|
156
143
|
// we don't need this going into the ChoiceComponent
|
|
157
|
-
// eslint-disable-next-line no-unused-vars
|
|
144
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
158
145
|
const {value, variant, ...remainingProps} = this.props;
|
|
159
146
|
const ChoiceComponent = this.getChoiceComponent(variant);
|
|
160
147
|
return <ChoiceComponent {...remainingProps} />;
|
|
@@ -1,57 +1,49 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
import {StyleSheet} from "aphrodite";
|
|
4
3
|
|
|
5
|
-
import {View, addStyle,
|
|
4
|
+
import {View, addStyle, StyleType} from "@khanacademy/wonder-blocks-core";
|
|
6
5
|
import Color from "@khanacademy/wonder-blocks-color";
|
|
7
6
|
import {Strut} from "@khanacademy/wonder-blocks-layout";
|
|
8
7
|
import Spacing from "@khanacademy/wonder-blocks-spacing";
|
|
9
8
|
import {LabelMedium, LabelSmall} from "@khanacademy/wonder-blocks-typography";
|
|
10
9
|
|
|
11
|
-
type Props = {
|
|
10
|
+
type Props = {
|
|
12
11
|
/**
|
|
13
12
|
* The form field component.
|
|
14
13
|
*/
|
|
15
|
-
field: React.
|
|
16
|
-
|
|
14
|
+
field: React.ReactNode;
|
|
17
15
|
/**
|
|
18
16
|
* The title for the label element.
|
|
19
17
|
*/
|
|
20
|
-
label: React.
|
|
21
|
-
|
|
18
|
+
label: React.ReactNode;
|
|
22
19
|
/**
|
|
23
20
|
* The text for the description element.
|
|
24
21
|
*/
|
|
25
|
-
description?: React.
|
|
26
|
-
|
|
22
|
+
description?: React.ReactNode;
|
|
27
23
|
/**
|
|
28
24
|
* Whether this field is required to continue.
|
|
29
25
|
*/
|
|
30
|
-
required?: boolean
|
|
31
|
-
|
|
26
|
+
required?: boolean;
|
|
32
27
|
/**
|
|
33
28
|
* The message for the error element.
|
|
34
29
|
*/
|
|
35
|
-
error?: React.
|
|
36
|
-
|
|
30
|
+
error?: React.ReactNode;
|
|
37
31
|
/**
|
|
38
32
|
* Custom styles for the field heading container.
|
|
39
33
|
*/
|
|
40
|
-
style?: StyleType
|
|
41
|
-
|
|
34
|
+
style?: StyleType;
|
|
42
35
|
/**
|
|
43
36
|
* A unique id to link the label (and optional error) to the field.
|
|
44
37
|
*
|
|
45
38
|
* The label will assume that the field will have its id formatted as `${id}-field`.
|
|
46
39
|
* The field can assume that the error will have its id formatted as `${id}-error`.
|
|
47
40
|
*/
|
|
48
|
-
id?: string
|
|
49
|
-
|
|
41
|
+
id?: string;
|
|
50
42
|
/**
|
|
51
43
|
* Optional test ID for e2e testing.
|
|
52
44
|
*/
|
|
53
|
-
testId?: string
|
|
54
|
-
|
|
45
|
+
testId?: string;
|
|
46
|
+
};
|
|
55
47
|
|
|
56
48
|
const StyledSpan = addStyle("span");
|
|
57
49
|
|
|
@@ -60,7 +52,7 @@ const StyledSpan = addStyle("span");
|
|
|
60
52
|
* to present better context and hints to any type of form field component.
|
|
61
53
|
*/
|
|
62
54
|
export default class FieldHeading extends React.Component<Props> {
|
|
63
|
-
renderLabel(): React.
|
|
55
|
+
renderLabel(): React.ReactNode {
|
|
64
56
|
const {label, id, required, testId} = this.props;
|
|
65
57
|
|
|
66
58
|
const requiredIcon = (
|
|
@@ -75,6 +67,7 @@ export default class FieldHeading extends React.Component<Props> {
|
|
|
75
67
|
<LabelMedium
|
|
76
68
|
style={styles.label}
|
|
77
69
|
tag="label"
|
|
70
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
78
71
|
htmlFor={id && `${id}-field`}
|
|
79
72
|
testId={testId && `${testId}-label`}
|
|
80
73
|
>
|
|
@@ -86,7 +79,7 @@ export default class FieldHeading extends React.Component<Props> {
|
|
|
86
79
|
);
|
|
87
80
|
}
|
|
88
81
|
|
|
89
|
-
maybeRenderDescription():
|
|
82
|
+
maybeRenderDescription(): React.ReactNode | null | undefined {
|
|
90
83
|
const {description, testId} = this.props;
|
|
91
84
|
|
|
92
85
|
if (!description) {
|
|
@@ -106,7 +99,7 @@ export default class FieldHeading extends React.Component<Props> {
|
|
|
106
99
|
);
|
|
107
100
|
}
|
|
108
101
|
|
|
109
|
-
maybeRenderError():
|
|
102
|
+
maybeRenderError(): React.ReactNode | null | undefined {
|
|
110
103
|
const {error, id, testId} = this.props;
|
|
111
104
|
|
|
112
105
|
if (!error) {
|
|
@@ -128,7 +121,7 @@ export default class FieldHeading extends React.Component<Props> {
|
|
|
128
121
|
);
|
|
129
122
|
}
|
|
130
123
|
|
|
131
|
-
render(): React.
|
|
124
|
+
render(): React.ReactElement {
|
|
132
125
|
const {field, style} = this.props;
|
|
133
126
|
|
|
134
127
|
return (
|