@khanacademy/wonder-blocks-form 3.1.11 → 3.1.13
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 +41 -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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-form
|
|
2
2
|
|
|
3
|
+
## 3.1.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [779b031d]
|
|
8
|
+
- @khanacademy/wonder-blocks-core@4.9.0
|
|
9
|
+
- @khanacademy/wonder-blocks-clickable@2.4.7
|
|
10
|
+
- @khanacademy/wonder-blocks-icon@1.2.39
|
|
11
|
+
- @khanacademy/wonder-blocks-layout@1.4.18
|
|
12
|
+
- @khanacademy/wonder-blocks-typography@1.1.40
|
|
13
|
+
|
|
14
|
+
## 3.1.12
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- d816af08: Update build and test configs use TypeScript
|
|
19
|
+
- 3891f544: Update babel config to include plugins that Storybook needed
|
|
20
|
+
- 0d28bb1c: Configured TypeScript
|
|
21
|
+
- 3d05f764: Fix HOCs and other type errors
|
|
22
|
+
- c2ec4902: Update eslint configuration, fix lint
|
|
23
|
+
- 2983c05b: Include 'types' field in package.json
|
|
24
|
+
- 77ff6a66: Generate Flow types from TypeScript types
|
|
25
|
+
- ec8d4b7f: Fix miscellaneous TypeScript errors
|
|
26
|
+
- Updated dependencies [d816af08]
|
|
27
|
+
- Updated dependencies [3891f544]
|
|
28
|
+
- Updated dependencies [3813715d]
|
|
29
|
+
- Updated dependencies [0d28bb1c]
|
|
30
|
+
- Updated dependencies [873f4a14]
|
|
31
|
+
- Updated dependencies [3d05f764]
|
|
32
|
+
- Updated dependencies [c2ec4902]
|
|
33
|
+
- Updated dependencies [2983c05b]
|
|
34
|
+
- Updated dependencies [77ff6a66]
|
|
35
|
+
- Updated dependencies [ec8d4b7f]
|
|
36
|
+
- @khanacademy/wonder-blocks-clickable@2.4.6
|
|
37
|
+
- @khanacademy/wonder-blocks-color@1.2.2
|
|
38
|
+
- @khanacademy/wonder-blocks-core@4.8.0
|
|
39
|
+
- @khanacademy/wonder-blocks-icon@1.2.38
|
|
40
|
+
- @khanacademy/wonder-blocks-layout@1.4.17
|
|
41
|
+
- @khanacademy/wonder-blocks-spacing@3.0.6
|
|
42
|
+
- @khanacademy/wonder-blocks-typography@1.1.39
|
|
43
|
+
|
|
3
44
|
## 3.1.11
|
|
4
45
|
|
|
5
46
|
### Patch Changes
|
|
@@ -0,0 +1,16 @@
|
|
|
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 ☑️ Checkbox
|
|
11
|
+
*/
|
|
12
|
+
export default class CheckboxCore extends React.Component<Props> {
|
|
13
|
+
handleChange: () => void;
|
|
14
|
+
render(): React.ReactElement;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for checkbox-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 ☑️ Checkbox
|
|
22
|
+
*/
|
|
23
|
+
declare export default class CheckboxCore extends React.Component<Props> {
|
|
24
|
+
handleChange: () => void;
|
|
25
|
+
render(): React.Element<>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { StyleType } from "@khanacademy/wonder-blocks-core";
|
|
3
|
+
import Choice from "./choice";
|
|
4
|
+
type CheckboxGroupProps = {
|
|
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 | null | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Custom styling for this group of checkboxes.
|
|
31
|
+
*/
|
|
32
|
+
style?: StyleType;
|
|
33
|
+
/**
|
|
34
|
+
* Callback for when selection of the group has changed. Passes the newly
|
|
35
|
+
* selected values.
|
|
36
|
+
*/
|
|
37
|
+
onChange: (selectedValues: Array<string>) => unknown;
|
|
38
|
+
/**
|
|
39
|
+
* An array of the values of the selected values in this checkbox group.
|
|
40
|
+
*/
|
|
41
|
+
selectedValues: Array<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Test ID used for e2e testing.
|
|
44
|
+
*/
|
|
45
|
+
testId?: string;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* A checkbox group allows multiple selection. This component auto-populates
|
|
49
|
+
* many props for its children Choice components. The Choice component is
|
|
50
|
+
* exposed for the user to apply custom styles or to indicate which choices are
|
|
51
|
+
* disabled.
|
|
52
|
+
*
|
|
53
|
+
* ### Usage
|
|
54
|
+
*
|
|
55
|
+
* ```jsx
|
|
56
|
+
* import {Choice, CheckboxGroup} from "@khanacademy/wonder-blocks-form";
|
|
57
|
+
*
|
|
58
|
+
* const [selectedValues, setSelectedValues] = React.useState([]);
|
|
59
|
+
*
|
|
60
|
+
* <CheckboxGroup
|
|
61
|
+
* label="some-label"
|
|
62
|
+
* description="some-description"
|
|
63
|
+
* groupName="some-group-name"
|
|
64
|
+
* onChange={setSelectedValues}
|
|
65
|
+
* selectedValues={selectedValues}
|
|
66
|
+
* >
|
|
67
|
+
* // Add as many choices as necessary
|
|
68
|
+
* <Choice
|
|
69
|
+
* label="Choice 1"
|
|
70
|
+
* value="some-choice-value"
|
|
71
|
+
* />
|
|
72
|
+
* <Choice
|
|
73
|
+
* label="Choice 2"
|
|
74
|
+
* value="some-choice-value-2"
|
|
75
|
+
* description="Some choice description."
|
|
76
|
+
* />
|
|
77
|
+
* </CheckboxGroup>
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export default class CheckboxGroup extends React.Component<CheckboxGroupProps> {
|
|
81
|
+
handleChange(changedValue: string, originalCheckedState: boolean): void;
|
|
82
|
+
render(): React.ReactElement;
|
|
83
|
+
}
|
|
84
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for checkbox-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 CheckboxGroupProps = {
|
|
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 | null | void,
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Custom styling for this group of checkboxes.
|
|
45
|
+
*/
|
|
46
|
+
style?: StyleType,
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Callback for when selection of the group has changed. Passes the newly
|
|
50
|
+
* selected values.
|
|
51
|
+
*/
|
|
52
|
+
onChange: (selectedValues: Array<string>) => mixed,
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* An array of the values of the selected values in this checkbox group.
|
|
56
|
+
*/
|
|
57
|
+
selectedValues: Array<string>,
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Test ID used for e2e testing.
|
|
61
|
+
*/
|
|
62
|
+
testId?: string,
|
|
63
|
+
...
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* A checkbox group allows multiple selection. This component auto-populates
|
|
67
|
+
* many props for its children Choice components. The Choice component is
|
|
68
|
+
* exposed for the user to apply custom styles or to indicate which choices are
|
|
69
|
+
* disabled.
|
|
70
|
+
*
|
|
71
|
+
* ### Usage
|
|
72
|
+
*
|
|
73
|
+
* ```jsx
|
|
74
|
+
* import {Choice, CheckboxGroup} from "@khanacademy/wonder-blocks-form";
|
|
75
|
+
*
|
|
76
|
+
* const [selectedValues, setSelectedValues] = React.useState([]);
|
|
77
|
+
*
|
|
78
|
+
* <CheckboxGroup
|
|
79
|
+
* label="some-label"
|
|
80
|
+
* description="some-description"
|
|
81
|
+
* groupName="some-group-name"
|
|
82
|
+
* onChange={setSelectedValues}
|
|
83
|
+
* selectedValues={selectedValues}
|
|
84
|
+
* >
|
|
85
|
+
* // Add as many choices as necessary
|
|
86
|
+
* <Choice
|
|
87
|
+
* label="Choice 1"
|
|
88
|
+
* value="some-choice-value"
|
|
89
|
+
* />
|
|
90
|
+
* <Choice
|
|
91
|
+
* label="Choice 2"
|
|
92
|
+
* value="some-choice-value-2"
|
|
93
|
+
* description="Some choice description."
|
|
94
|
+
* />
|
|
95
|
+
* </CheckboxGroup>
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
declare export default class CheckboxGroup
|
|
99
|
+
extends React.Component<CheckboxGroupProps>
|
|
100
|
+
{
|
|
101
|
+
handleChange(changedValue: string, originalCheckedState: boolean): void;
|
|
102
|
+
render(): React.Element<>;
|
|
103
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
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 checkbox for all your checking needs. Can optionally take
|
|
60
|
+
* label and description props.
|
|
61
|
+
*
|
|
62
|
+
* If used by itself, a checkbox provides two options - checked and unchecked.
|
|
63
|
+
* A group of checkboxes can be used to allow a user to select multiple values
|
|
64
|
+
* from a list of options.
|
|
65
|
+
*
|
|
66
|
+
* If you want a whole group of Checkbox[es] that are related, see the Choice
|
|
67
|
+
* and CheckboxGroup components.
|
|
68
|
+
*
|
|
69
|
+
* ### Usage
|
|
70
|
+
*
|
|
71
|
+
* ```jsx
|
|
72
|
+
* import {Checkbox} from "@khanacademy/wonder-blocks-form";
|
|
73
|
+
*
|
|
74
|
+
* const [checked, setChecked] = React.useState(false);
|
|
75
|
+
*
|
|
76
|
+
* <Checkbox checked={checked} onChange={setChecked} />
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export default class Checkbox extends React.Component<ChoiceComponentProps> {
|
|
80
|
+
static defaultProps: DefaultProps;
|
|
81
|
+
render(): React.ReactElement;
|
|
82
|
+
}
|
|
83
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for checkbox
|
|
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 checkbox for all your checking needs. Can optionally take
|
|
82
|
+
* label and description props.
|
|
83
|
+
*
|
|
84
|
+
* If used by itself, a checkbox provides two options - checked and unchecked.
|
|
85
|
+
* A group of checkboxes can be used to allow a user to select multiple values
|
|
86
|
+
* from a list of options.
|
|
87
|
+
*
|
|
88
|
+
* If you want a whole group of Checkbox[es] that are related, see the Choice
|
|
89
|
+
* and CheckboxGroup components.
|
|
90
|
+
*
|
|
91
|
+
* ### Usage
|
|
92
|
+
*
|
|
93
|
+
* ```jsx
|
|
94
|
+
* import {Checkbox} from "@khanacademy/wonder-blocks-form";
|
|
95
|
+
*
|
|
96
|
+
* const [checked, setChecked] = React.useState(false);
|
|
97
|
+
*
|
|
98
|
+
* <Checkbox checked={checked} onChange={setChecked} />
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
declare export default class Checkbox
|
|
102
|
+
extends React.Component<ChoiceComponentProps>
|
|
103
|
+
{
|
|
104
|
+
static defaultProps: DefaultProps;
|
|
105
|
+
render(): React.Element<>;
|
|
106
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { AriaProps, StyleType } from "@khanacademy/wonder-blocks-core";
|
|
3
|
+
import CheckboxCore from "./checkbox-core";
|
|
4
|
+
import RadioCore from "./radio-core";
|
|
5
|
+
type Props = AriaProps & {
|
|
6
|
+
/** Whether this choice is checked. */
|
|
7
|
+
checked: boolean;
|
|
8
|
+
/** Whether this choice option is disabled. */
|
|
9
|
+
disabled: boolean;
|
|
10
|
+
/** Whether this choice is in error mode. */
|
|
11
|
+
error: boolean;
|
|
12
|
+
/** Returns the new checked state of the component. */
|
|
13
|
+
onChange: (newCheckedState: boolean) => unknown;
|
|
14
|
+
/**
|
|
15
|
+
* Used for accessibility purposes, where the label id should match the
|
|
16
|
+
* input id.
|
|
17
|
+
*/
|
|
18
|
+
id?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Optional additional styling.
|
|
21
|
+
*/
|
|
22
|
+
style?: StyleType;
|
|
23
|
+
/**
|
|
24
|
+
* Adds CSS classes to the Button.
|
|
25
|
+
*/
|
|
26
|
+
className?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Optional id for testing purposes.
|
|
29
|
+
*/
|
|
30
|
+
testId?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Label for the field.
|
|
33
|
+
*/
|
|
34
|
+
label?: React.ReactNode;
|
|
35
|
+
/** Optional description for the field. */
|
|
36
|
+
description?: React.ReactNode;
|
|
37
|
+
/** Auto-populated by parent's groupName prop if in a group. */
|
|
38
|
+
groupName?: string;
|
|
39
|
+
/** Takes either "radio" or "checkbox" value. */
|
|
40
|
+
variant: "radio" | "checkbox";
|
|
41
|
+
};
|
|
42
|
+
type DefaultProps = {
|
|
43
|
+
checked: Props["checked"];
|
|
44
|
+
disabled: Props["disabled"];
|
|
45
|
+
error: Props["error"];
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* This is a potentially labeled 🔘 or ☑️ item. This is an internal component
|
|
49
|
+
* that's wrapped by Checkbox and Radio. Choice is a wrapper for Checkbox and
|
|
50
|
+
* Radio with many of its props auto-populated, to be used with CheckboxGroup
|
|
51
|
+
* and RadioGroup. This design allows for more explicit prop typing. For
|
|
52
|
+
* example, we can make onChange a required prop on Checkbox but not on Choice
|
|
53
|
+
* (because for Choice, that prop would be auto-populated by CheckboxGroup).
|
|
54
|
+
*/ export default class ChoiceInternal extends React.Component<Props> {
|
|
55
|
+
static defaultProps: DefaultProps;
|
|
56
|
+
handleLabelClick: (event: React.SyntheticEvent) => void;
|
|
57
|
+
handleClick: () => void;
|
|
58
|
+
getChoiceCoreComponent(): typeof RadioCore | typeof CheckboxCore;
|
|
59
|
+
getLabel(): React.ReactNode;
|
|
60
|
+
getDescription(id?: string): React.ReactNode;
|
|
61
|
+
render(): React.ReactElement;
|
|
62
|
+
}
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for choice-internal
|
|
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
|
+
import CheckboxCore from "./checkbox-core";
|
|
11
|
+
import RadioCore from "./radio-core";
|
|
12
|
+
declare type Props = {
|
|
13
|
+
...AriaProps,
|
|
14
|
+
...{
|
|
15
|
+
/**
|
|
16
|
+
* Whether this choice is checked.
|
|
17
|
+
*/
|
|
18
|
+
checked: boolean,
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Whether this choice option is disabled.
|
|
22
|
+
*/
|
|
23
|
+
disabled: boolean,
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Whether this choice is in error mode.
|
|
27
|
+
*/
|
|
28
|
+
error: boolean,
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Returns the new checked state of the component.
|
|
32
|
+
*/
|
|
33
|
+
onChange: (newCheckedState: boolean) => mixed,
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Used for accessibility purposes, where the label id should match the
|
|
37
|
+
* input id.
|
|
38
|
+
*/
|
|
39
|
+
id?: string,
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Optional additional styling.
|
|
43
|
+
*/
|
|
44
|
+
style?: StyleType,
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Adds CSS classes to the Button.
|
|
48
|
+
*/
|
|
49
|
+
className?: string,
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Optional id for testing purposes.
|
|
53
|
+
*/
|
|
54
|
+
testId?: string,
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Label for the field.
|
|
58
|
+
*/
|
|
59
|
+
label?: React.Node,
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Optional description for the field.
|
|
63
|
+
*/
|
|
64
|
+
description?: React.Node,
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Auto-populated by parent's groupName prop if in a group.
|
|
68
|
+
*/
|
|
69
|
+
groupName?: string,
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Takes either "radio" or "checkbox" value.
|
|
73
|
+
*/
|
|
74
|
+
variant: "radio" | "checkbox",
|
|
75
|
+
...
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
declare type DefaultProps = {
|
|
79
|
+
checked: $PropertyType<Props, "checked">,
|
|
80
|
+
disabled: $PropertyType<Props, "disabled">,
|
|
81
|
+
error: $PropertyType<Props, "error">,
|
|
82
|
+
...
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* This is a potentially labeled 🔘 or ☑️ item. This is an internal component
|
|
86
|
+
* that's wrapped by Checkbox and Radio. Choice is a wrapper for Checkbox and
|
|
87
|
+
* Radio with many of its props auto-populated, to be used with CheckboxGroup
|
|
88
|
+
* and RadioGroup. This design allows for more explicit prop typing. For
|
|
89
|
+
* example, we can make onChange a required prop on Checkbox but not on Choice
|
|
90
|
+
* (because for Choice, that prop would be auto-populated by CheckboxGroup).
|
|
91
|
+
*/
|
|
92
|
+
declare export default class ChoiceInternal extends React.Component<Props> {
|
|
93
|
+
static defaultProps: DefaultProps;
|
|
94
|
+
handleLabelClick: (event: React.SyntheticEvent<>) => void;
|
|
95
|
+
handleClick: () => void;
|
|
96
|
+
getChoiceCoreComponent(): typeof RadioCore | typeof CheckboxCore;
|
|
97
|
+
getLabel(): React.Node;
|
|
98
|
+
getDescription(id?: string): React.Node;
|
|
99
|
+
render(): React.Element<>;
|
|
100
|
+
}
|