@khanacademy/wonder-blocks-form 3.1.11 → 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 +30 -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} +8 -9
- package/src/components/__tests__/{checkbox-group.test.js → checkbox-group.test.tsx} +5 -5
- package/src/components/__tests__/{field-heading.test.js → field-heading.test.tsx} +0 -1
- package/src/components/__tests__/{labeled-text-field.test.js → labeled-text-field.test.tsx} +4 -5
- package/src/components/__tests__/{radio-group.test.js → radio-group.test.tsx} +8 -8
- package/src/components/__tests__/{text-field.test.js → text-field.test.tsx} +22 -18
- package/src/components/{checkbox-core.js → checkbox-core.tsx} +12 -15
- package/src/components/{checkbox-group.js → checkbox-group.tsx} +20 -23
- package/src/components/{checkbox.js → checkbox.tsx} +18 -32
- package/src/components/{choice-internal.js → choice-internal.tsx} +25 -39
- package/src/components/{choice.js → choice.tsx} +24 -37
- 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} +54 -69
- package/src/components/{radio-core.js → radio-core.tsx} +13 -16
- package/src/components/{radio-group.js → radio-group.tsx} +20 -23
- package/src/components/{radio.js → radio.tsx} +18 -32
- package/src/components/{text-field.js → text-field.tsx} +53 -64
- package/src/{index.js → index.ts} +0 -1
- 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/__tests__/__snapshots__/{custom-snapshot.test.js.snap → custom-snapshot.test.tsx.snap} +0 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for labeled-text-field
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import { StyleType } from "@khanacademy/wonder-blocks-core";
|
|
10
|
+
import { TextFieldType } from "./text-field";
|
|
11
|
+
declare type WithForwardRef = {
|
|
12
|
+
forwardedRef: React.ForwardedRef<HTMLInputElement>,
|
|
13
|
+
...
|
|
14
|
+
};
|
|
15
|
+
declare type Props = {
|
|
16
|
+
/**
|
|
17
|
+
* An optional unique identifier for the TextField.
|
|
18
|
+
* If no id is specified, a unique id will be auto-generated.
|
|
19
|
+
*/
|
|
20
|
+
id?: string,
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Determines the type of input. Defaults to text.
|
|
24
|
+
*/
|
|
25
|
+
type: TextFieldType,
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Provide a label for the TextField.
|
|
29
|
+
*/
|
|
30
|
+
label: React.Node,
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Provide a description for the TextField.
|
|
34
|
+
*/
|
|
35
|
+
description?: React.Node,
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The input value.
|
|
39
|
+
*/
|
|
40
|
+
value: string,
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Makes a read-only input field that cannot be focused. Defaults to false.
|
|
44
|
+
*/
|
|
45
|
+
disabled: boolean,
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Whether this field is required to to continue, or the error message to
|
|
49
|
+
* render if this field is left blank.
|
|
50
|
+
*
|
|
51
|
+
* This can be a boolean or a string.
|
|
52
|
+
*
|
|
53
|
+
* String:
|
|
54
|
+
* Please pass in a translated string to use as the error message that will
|
|
55
|
+
* render if the user leaves this field blank. If this field is required,
|
|
56
|
+
* and a string is not passed in, a default untranslated string will render
|
|
57
|
+
* upon error.
|
|
58
|
+
* Note: The string will not be used if a `validate` prop is passed in.
|
|
59
|
+
*
|
|
60
|
+
* Example message: i18n._("A password is required to log in.")
|
|
61
|
+
*
|
|
62
|
+
* Boolean:
|
|
63
|
+
* True/false indicating whether this field is required. Please do not pass
|
|
64
|
+
* in `true` if possible - pass in the error string instead.
|
|
65
|
+
* If `true` is passed, and a `validate` prop is not passed, that means
|
|
66
|
+
* there is no corresponding message and the default untranlsated message
|
|
67
|
+
* will be used.
|
|
68
|
+
*/
|
|
69
|
+
required?: boolean | string,
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Identifies the element or elements that describes this text field.
|
|
73
|
+
*/
|
|
74
|
+
ariaDescribedby?: string | void,
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Provide a validation for the input value.
|
|
78
|
+
* Return a string error message or null | void for a valid input.
|
|
79
|
+
*/
|
|
80
|
+
validate?: (value: string) => string | null | void,
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Called when the TextField input is validated.
|
|
84
|
+
*/
|
|
85
|
+
onValidate?: (errorMessage?: string | null | void) => mixed,
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Called when the value has changed.
|
|
89
|
+
*/
|
|
90
|
+
onChange: (newValue: string) => mixed,
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Called when a key is pressed.
|
|
94
|
+
*/
|
|
95
|
+
onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => mixed,
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Called when the element has been focused.
|
|
99
|
+
*/
|
|
100
|
+
onFocus?: (event: React.FocusEvent<HTMLInputElement>) => mixed,
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Called when the element has been blurred.
|
|
104
|
+
*/
|
|
105
|
+
onBlur?: (event: React.FocusEvent<HTMLInputElement>) => mixed,
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Provide hints or examples of what to enter.
|
|
109
|
+
*/
|
|
110
|
+
placeholder?: string,
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Change the field’s sub-components to fit a dark background.
|
|
114
|
+
*/
|
|
115
|
+
light: boolean,
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Custom styles for the container.
|
|
119
|
+
*
|
|
120
|
+
* Note: This style is passed to the field heading container
|
|
121
|
+
* due to scenarios where we would like to set a specific
|
|
122
|
+
* width for the text field. If we apply the style directly
|
|
123
|
+
* to the text field, the container would not be affected.
|
|
124
|
+
* For example, setting text field to "width: 50%" would not
|
|
125
|
+
* affect the container since text field is a child of the container.
|
|
126
|
+
* In this case, the container would maintain its width ocuppying
|
|
127
|
+
* unnecessary space when the text field is smaller.
|
|
128
|
+
*/
|
|
129
|
+
style?: StyleType,
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Optional test ID for e2e testing.
|
|
133
|
+
*/
|
|
134
|
+
testId?: string,
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Specifies if the TextField is read-only.
|
|
138
|
+
*/
|
|
139
|
+
readOnly?: boolean,
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Specifies if the TextField allows autocomplete.
|
|
143
|
+
*/
|
|
144
|
+
autoComplete?: string,
|
|
145
|
+
...
|
|
146
|
+
};
|
|
147
|
+
declare type PropsWithForwardRef = { ...Props, ...WithForwardRef };
|
|
148
|
+
declare type DefaultProps = {
|
|
149
|
+
type: $PropertyType<PropsWithForwardRef, "type">,
|
|
150
|
+
disabled: $PropertyType<PropsWithForwardRef, "disabled">,
|
|
151
|
+
light: $PropertyType<PropsWithForwardRef, "light">,
|
|
152
|
+
...
|
|
153
|
+
};
|
|
154
|
+
declare type State = {
|
|
155
|
+
/**
|
|
156
|
+
* Displayed when the validation fails.
|
|
157
|
+
*/
|
|
158
|
+
error: string | null | void,
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* The user focuses on the textfield.
|
|
162
|
+
*/
|
|
163
|
+
focused: boolean,
|
|
164
|
+
...
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* A LabeledTextField is an element used to accept a single line of text
|
|
168
|
+
* from the user paired with a label, description, and error field elements.
|
|
169
|
+
*/
|
|
170
|
+
declare class LabeledTextField
|
|
171
|
+
mixins React.Component<PropsWithForwardRef, State>
|
|
172
|
+
{
|
|
173
|
+
static defaultProps: DefaultProps;
|
|
174
|
+
constructor(props: PropsWithForwardRef): this;
|
|
175
|
+
handleValidate: (errorMessage?: string | null | void) => mixed;
|
|
176
|
+
handleFocus: (event: React.FocusEvent<HTMLInputElement>) => mixed;
|
|
177
|
+
handleBlur: (event: React.FocusEvent<HTMLInputElement>) => mixed;
|
|
178
|
+
render(): React.Element<>;
|
|
179
|
+
}
|
|
180
|
+
declare type ExportProps = $Diff<
|
|
181
|
+
JSX.LibraryManagedAttributes<
|
|
182
|
+
typeof LabeledTextField,
|
|
183
|
+
React.ComponentProps<typeof LabeledTextField>
|
|
184
|
+
>,
|
|
185
|
+
{ forwardedRef: any }
|
|
186
|
+
>;
|
|
187
|
+
/**
|
|
188
|
+
* A LabeledTextField is an element used to accept a single line of text
|
|
189
|
+
* from the user paired with a label, description, and error field elements.
|
|
190
|
+
*
|
|
191
|
+
* ### Usage
|
|
192
|
+
*
|
|
193
|
+
* ```jsx
|
|
194
|
+
* import {LabeledTextField} from "@khanacademy/wonder-blocks-form";
|
|
195
|
+
*
|
|
196
|
+
* const [value, setValue] = React.useState("");
|
|
197
|
+
*
|
|
198
|
+
* <LabeledTextField
|
|
199
|
+
* label="Label"
|
|
200
|
+
* description="Hello, this is the description for this field"
|
|
201
|
+
* placeholder="Placeholder"
|
|
202
|
+
* value={value}
|
|
203
|
+
* onChange={setValue}
|
|
204
|
+
* />
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
declare var _default: React.ForwardRefExoticComponent<{
|
|
208
|
+
...ExportProps,
|
|
209
|
+
...React.RefAttributes<HTMLInputElement>,
|
|
210
|
+
}>;
|
|
211
|
+
declare export default typeof _default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { ChoiceCoreProps } from "../util/types";
|
|
3
|
+
type Props = ChoiceCoreProps & {
|
|
4
|
+
hovered: boolean;
|
|
5
|
+
focused: boolean;
|
|
6
|
+
pressed: boolean;
|
|
7
|
+
waiting: boolean;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The internal stateless 🔘 Radio button
|
|
11
|
+
*/ export default class RadioCore extends React.Component<Props> {
|
|
12
|
+
handleChange: () => void;
|
|
13
|
+
render(): React.ReactElement;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for radio-core
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import type { ChoiceCoreProps } from "../util/types";
|
|
10
|
+
declare type Props = {
|
|
11
|
+
...ChoiceCoreProps,
|
|
12
|
+
...{
|
|
13
|
+
hovered: boolean,
|
|
14
|
+
focused: boolean,
|
|
15
|
+
pressed: boolean,
|
|
16
|
+
waiting: boolean,
|
|
17
|
+
...
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The internal stateless 🔘 Radio button
|
|
22
|
+
*/
|
|
23
|
+
declare export default class RadioCore mixins React.Component<Props> {
|
|
24
|
+
handleChange: () => void;
|
|
25
|
+
render(): React.Element<>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { StyleType } from "@khanacademy/wonder-blocks-core";
|
|
3
|
+
import Choice from "./choice";
|
|
4
|
+
type RadioGroupProps = {
|
|
5
|
+
/**
|
|
6
|
+
* Children should be Choice components.
|
|
7
|
+
*/
|
|
8
|
+
children: Array<React.ReactElement<React.ComponentProps<typeof Choice>> | false | null | undefined>;
|
|
9
|
+
/**
|
|
10
|
+
* Group name for this checkbox or radio group. Should be unique for all
|
|
11
|
+
* such groups displayed on a page.
|
|
12
|
+
*/
|
|
13
|
+
groupName: string;
|
|
14
|
+
/**
|
|
15
|
+
* Optional label for the group. This label is optional to allow for
|
|
16
|
+
* greater flexibility in implementing checkbox and radio groups.
|
|
17
|
+
*/
|
|
18
|
+
label?: React.ReactNode;
|
|
19
|
+
/**
|
|
20
|
+
* Optional description for the group.
|
|
21
|
+
*/
|
|
22
|
+
description?: React.ReactNode;
|
|
23
|
+
/**
|
|
24
|
+
* Optional error message. If supplied, the group will be displayed in an
|
|
25
|
+
* error state, along with this error message. If no error state is desired,
|
|
26
|
+
* simply do not supply this prop, or pass along null.
|
|
27
|
+
*/
|
|
28
|
+
errorMessage?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Custom styling for this group of checkboxes.
|
|
31
|
+
*/
|
|
32
|
+
style?: StyleType;
|
|
33
|
+
/**
|
|
34
|
+
* Callback for when the selected value of the radio group has changed.
|
|
35
|
+
*/
|
|
36
|
+
onChange: (selectedValue: string) => unknown;
|
|
37
|
+
/**
|
|
38
|
+
* Value of the selected radio item.
|
|
39
|
+
*/
|
|
40
|
+
selectedValue: string;
|
|
41
|
+
/**
|
|
42
|
+
* Test ID used for e2e testing.
|
|
43
|
+
*/
|
|
44
|
+
testId?: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* A radio group allows only single selection. Like CheckboxGroup, this
|
|
48
|
+
* component auto-populates many props for its children Choice components. The
|
|
49
|
+
* Choice component is exposed for the user to apply custom styles or to
|
|
50
|
+
* indicate which choices are disabled. The use of the groupName prop is
|
|
51
|
+
* important to maintain expected keyboard navigation behavior for
|
|
52
|
+
* accessibility.
|
|
53
|
+
*
|
|
54
|
+
* ### Usage
|
|
55
|
+
*
|
|
56
|
+
* ```jsx
|
|
57
|
+
* import {Choice, RadioGroup} from "@khanacademy/wonder-blocks-form";
|
|
58
|
+
*
|
|
59
|
+
* const [selectedValue, setSelectedValue] = React.useState("");
|
|
60
|
+
*
|
|
61
|
+
* <RadioGroup
|
|
62
|
+
* label="some-label"
|
|
63
|
+
* description="some-description"
|
|
64
|
+
* groupName="some-group-name"
|
|
65
|
+
* onChange={setSelectedValue}
|
|
66
|
+
* selectedValue={selectedValue}
|
|
67
|
+
* >
|
|
68
|
+
* // Add as many choices as necessary
|
|
69
|
+
* <Choice
|
|
70
|
+
* label="Choice 1"
|
|
71
|
+
* value="some-choice-value"
|
|
72
|
+
* />
|
|
73
|
+
* <Choice
|
|
74
|
+
* label="Choice 2"
|
|
75
|
+
* value="some-choice-value-2"
|
|
76
|
+
* description="Some choice description."
|
|
77
|
+
* />
|
|
78
|
+
* </RadioGroup>
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export default class RadioGroup extends React.Component<RadioGroupProps> {
|
|
82
|
+
handleChange(changedValue: string): void;
|
|
83
|
+
render(): React.ReactElement;
|
|
84
|
+
}
|
|
85
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for radio-group
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import type { StyleType } from "@khanacademy/wonder-blocks-core";
|
|
10
|
+
import Choice from "./choice";
|
|
11
|
+
declare type RadioGroupProps = {
|
|
12
|
+
/**
|
|
13
|
+
* Children should be Choice components.
|
|
14
|
+
*/
|
|
15
|
+
children: Array<
|
|
16
|
+
React.Element<React.ComponentProps<typeof Choice>> | false | null | void
|
|
17
|
+
>,
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Group name for this checkbox or radio group. Should be unique for all
|
|
21
|
+
* such groups displayed on a page.
|
|
22
|
+
*/
|
|
23
|
+
groupName: string,
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Optional label for the group. This label is optional to allow for
|
|
27
|
+
* greater flexibility in implementing checkbox and radio groups.
|
|
28
|
+
*/
|
|
29
|
+
label?: React.Node,
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Optional description for the group.
|
|
33
|
+
*/
|
|
34
|
+
description?: React.Node,
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Optional error message. If supplied, the group will be displayed in an
|
|
38
|
+
* error state, along with this error message. If no error state is desired,
|
|
39
|
+
* simply do not supply this prop, or pass along null.
|
|
40
|
+
*/
|
|
41
|
+
errorMessage?: string,
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Custom styling for this group of checkboxes.
|
|
45
|
+
*/
|
|
46
|
+
style?: StyleType,
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Callback for when the selected value of the radio group has changed.
|
|
50
|
+
*/
|
|
51
|
+
onChange: (selectedValue: string) => mixed,
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Value of the selected radio item.
|
|
55
|
+
*/
|
|
56
|
+
selectedValue: string,
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Test ID used for e2e testing.
|
|
60
|
+
*/
|
|
61
|
+
testId?: string,
|
|
62
|
+
...
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* A radio group allows only single selection. Like CheckboxGroup, this
|
|
66
|
+
* component auto-populates many props for its children Choice components. The
|
|
67
|
+
* Choice component is exposed for the user to apply custom styles or to
|
|
68
|
+
* indicate which choices are disabled. The use of the groupName prop is
|
|
69
|
+
* important to maintain expected keyboard navigation behavior for
|
|
70
|
+
* accessibility.
|
|
71
|
+
*
|
|
72
|
+
* ### Usage
|
|
73
|
+
*
|
|
74
|
+
* ```jsx
|
|
75
|
+
* import {Choice, RadioGroup} from "@khanacademy/wonder-blocks-form";
|
|
76
|
+
*
|
|
77
|
+
* const [selectedValue, setSelectedValue] = React.useState("");
|
|
78
|
+
*
|
|
79
|
+
* <RadioGroup
|
|
80
|
+
* label="some-label"
|
|
81
|
+
* description="some-description"
|
|
82
|
+
* groupName="some-group-name"
|
|
83
|
+
* onChange={setSelectedValue}
|
|
84
|
+
* selectedValue={selectedValue}
|
|
85
|
+
* >
|
|
86
|
+
* // Add as many choices as necessary
|
|
87
|
+
* <Choice
|
|
88
|
+
* label="Choice 1"
|
|
89
|
+
* value="some-choice-value"
|
|
90
|
+
* />
|
|
91
|
+
* <Choice
|
|
92
|
+
* label="Choice 2"
|
|
93
|
+
* value="some-choice-value-2"
|
|
94
|
+
* description="Some choice description."
|
|
95
|
+
* />
|
|
96
|
+
* </RadioGroup>
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
declare export default class RadioGroup
|
|
100
|
+
mixins React.Component<RadioGroupProps>
|
|
101
|
+
{
|
|
102
|
+
handleChange(changedValue: string): void;
|
|
103
|
+
render(): React.Element<>;
|
|
104
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { AriaProps, StyleType } from "@khanacademy/wonder-blocks-core";
|
|
3
|
+
type ChoiceComponentProps = AriaProps & {
|
|
4
|
+
/**
|
|
5
|
+
* Whether this component is checked
|
|
6
|
+
*/
|
|
7
|
+
checked: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Whether this component is disabled
|
|
10
|
+
*/
|
|
11
|
+
disabled: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Whether this component should show an error state
|
|
14
|
+
*/
|
|
15
|
+
error: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Callback when this component is selected. The newCheckedState is the
|
|
18
|
+
* new checked state of the component.
|
|
19
|
+
*/
|
|
20
|
+
onChange: (newCheckedState: boolean) => unknown;
|
|
21
|
+
/**
|
|
22
|
+
* Optional label for the field.
|
|
23
|
+
*/
|
|
24
|
+
label?: React.ReactNode;
|
|
25
|
+
/**
|
|
26
|
+
* Optional description for the field.
|
|
27
|
+
*/
|
|
28
|
+
description?: React.ReactNode;
|
|
29
|
+
/**
|
|
30
|
+
* Unique identifier attached to the HTML input element. If used, need to
|
|
31
|
+
* guarantee that the ID is unique within everything rendered on a page.
|
|
32
|
+
* Used to match `<label>` with `<input>` elements for screenreaders.
|
|
33
|
+
*/
|
|
34
|
+
id?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Optional styling for the container. Does not style the component.
|
|
37
|
+
*/
|
|
38
|
+
style?: StyleType;
|
|
39
|
+
/**
|
|
40
|
+
* Adds CSS classes to the Checkbox.
|
|
41
|
+
*/
|
|
42
|
+
className?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Optional test ID for e2e testing
|
|
45
|
+
*/
|
|
46
|
+
testId?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Name for the checkbox or radio button group. Only applicable for group
|
|
49
|
+
* contexts, auto-populated by group components via Choice.
|
|
50
|
+
* @ignore
|
|
51
|
+
*/
|
|
52
|
+
groupName?: string;
|
|
53
|
+
};
|
|
54
|
+
type DefaultProps = {
|
|
55
|
+
disabled: ChoiceComponentProps["disabled"];
|
|
56
|
+
error: ChoiceComponentProps["error"];
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* 🔘 A nicely styled radio button for all your non-AMFM radio button needs. Can
|
|
60
|
+
* optionally take label and description props.
|
|
61
|
+
*
|
|
62
|
+
* This component should not really be used by itself because radio buttons are
|
|
63
|
+
* often grouped together. See RadioGroup.
|
|
64
|
+
*/ export default class Radio extends React.Component<ChoiceComponentProps> {
|
|
65
|
+
static defaultProps: DefaultProps;
|
|
66
|
+
render(): React.ReactElement;
|
|
67
|
+
}
|
|
68
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for radio
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import type { AriaProps, StyleType } from "@khanacademy/wonder-blocks-core";
|
|
10
|
+
declare type ChoiceComponentProps = {
|
|
11
|
+
...AriaProps,
|
|
12
|
+
...{
|
|
13
|
+
/**
|
|
14
|
+
* Whether this component is checked
|
|
15
|
+
*/
|
|
16
|
+
checked: boolean,
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Whether this component is disabled
|
|
20
|
+
*/
|
|
21
|
+
disabled: boolean,
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Whether this component should show an error state
|
|
25
|
+
*/
|
|
26
|
+
error: boolean,
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Callback when this component is selected. The newCheckedState is the
|
|
30
|
+
* new checked state of the component.
|
|
31
|
+
*/
|
|
32
|
+
onChange: (newCheckedState: boolean) => mixed,
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Optional label for the field.
|
|
36
|
+
*/
|
|
37
|
+
label?: React.Node,
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Optional description for the field.
|
|
41
|
+
*/
|
|
42
|
+
description?: React.Node,
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Unique identifier attached to the HTML input element. If used, need to
|
|
46
|
+
* guarantee that the ID is unique within everything rendered on a page.
|
|
47
|
+
* Used to match `<label>` with `<input>` elements for screenreaders.
|
|
48
|
+
*/
|
|
49
|
+
id?: string,
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Optional styling for the container. Does not style the component.
|
|
53
|
+
*/
|
|
54
|
+
style?: StyleType,
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Adds CSS classes to the Checkbox.
|
|
58
|
+
*/
|
|
59
|
+
className?: string,
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Optional test ID for e2e testing
|
|
63
|
+
*/
|
|
64
|
+
testId?: string,
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Name for the checkbox or radio button group. Only applicable for group
|
|
68
|
+
* contexts, auto-populated by group components via Choice.
|
|
69
|
+
* @ignore
|
|
70
|
+
*/
|
|
71
|
+
groupName?: string,
|
|
72
|
+
...
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
declare type DefaultProps = {
|
|
76
|
+
disabled: $PropertyType<ChoiceComponentProps, "disabled">,
|
|
77
|
+
error: $PropertyType<ChoiceComponentProps, "error">,
|
|
78
|
+
...
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* 🔘 A nicely styled radio button for all your non-AMFM radio button needs. Can
|
|
82
|
+
* optionally take label and description props.
|
|
83
|
+
*
|
|
84
|
+
* This component should not really be used by itself because radio buttons are
|
|
85
|
+
* often grouped together. See RadioGroup.
|
|
86
|
+
*/
|
|
87
|
+
declare export default class Radio
|
|
88
|
+
mixins React.Component<ChoiceComponentProps>
|
|
89
|
+
{
|
|
90
|
+
static defaultProps: DefaultProps;
|
|
91
|
+
render(): React.Element<>;
|
|
92
|
+
}
|