@khanacademy/wonder-blocks-form 4.2.2 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/components/checkbox-core.d.ts +13 -8
  3. package/dist/components/checkbox-core.js.flow +19 -10
  4. package/dist/components/checkbox-group.d.ts +2 -5
  5. package/dist/components/checkbox-group.js.flow +5 -6
  6. package/dist/components/checkbox.d.ts +33 -39
  7. package/dist/components/checkbox.js.flow +38 -41
  8. package/dist/components/choice-internal.d.ts +19 -31
  9. package/dist/components/choice-internal.js.flow +25 -32
  10. package/dist/components/choice.d.ts +50 -60
  11. package/dist/components/choice.js.flow +79 -84
  12. package/dist/components/radio-core.d.ts +13 -5
  13. package/dist/components/radio-core.js.flow +19 -7
  14. package/dist/components/radio-group.d.ts +2 -5
  15. package/dist/components/radio-group.js.flow +5 -6
  16. package/dist/components/radio.d.ts +18 -24
  17. package/dist/components/radio.js.flow +24 -27
  18. package/dist/es/index.js +262 -294
  19. package/dist/index.js +262 -294
  20. package/dist/util/types.d.ts +1 -1
  21. package/dist/util/types.js.flow +1 -1
  22. package/package.json +6 -6
  23. package/src/components/__tests__/{checkbox.test.js → checkbox.test.tsx} +55 -1
  24. package/src/components/checkbox-core.tsx +32 -31
  25. package/src/components/checkbox-group.tsx +33 -22
  26. package/src/components/checkbox.tsx +21 -16
  27. package/src/components/choice-internal.tsx +60 -58
  28. package/src/components/choice.tsx +39 -32
  29. package/src/components/radio-core.tsx +16 -14
  30. package/src/components/radio-group.tsx +14 -11
  31. package/src/components/radio.tsx +21 -16
  32. package/src/util/types.ts +1 -1
  33. package/tsconfig-build.tsbuildinfo +1 -1
@@ -4,87 +4,10 @@
4
4
  * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
+ import * as $Flowgen$Import$_2e__2e__2f__2e__2e__2f__2e__2e__2f_wonder_2d_blocks_2d_core_2f_src_2f_util_2f_aria_2d_types from "../../../wonder-blocks-core/src/util/aria-types";
7
8
  import * as React from "react";
8
- import type { AriaProps, StyleType } from "@khanacademy/wonder-blocks-core";
9
- import Checkbox from "./checkbox";
10
- import Radio from "./radio";
11
- declare type Props = {|
12
- ...AriaProps,
13
- ...{|
14
- /**
15
- * User-defined. Label for the field.
16
- */
17
- label: React.Node,
18
-
19
- /**
20
- * User-defined. Optional description for the field.
21
- */
22
- description?: React.Node,
23
-
24
- /**
25
- * User-defined. Should be distinct for each item in the group.
26
- */
27
- value: string,
9
+ import type { StyleType } from "@khanacademy/wonder-blocks-core";
28
10
 
29
- /**
30
- * User-defined. Whether this choice option is disabled. Default false.
31
- */
32
- disabled: boolean,
33
-
34
- /**
35
- * User-defined. Optional id for testing purposes.
36
- */
37
- testId?: string,
38
-
39
- /**
40
- * User-defined. Optional additional styling.
41
- */
42
- style?: StyleType,
43
-
44
- /**
45
- * Auto-populated by parent. Whether this choice is checked.
46
- * @ignore
47
- */
48
- checked: boolean,
49
-
50
- /**
51
- * Auto-populated by parent. Whether this choice is in error mode (everything
52
- * in a choice group would be in error mode at the same time).
53
- * @ignore
54
- */
55
- error?: boolean,
56
-
57
- /**
58
- * Auto-populated by parent. Used for accessibility purposes, where the label
59
- * id should match the input id.
60
- * @ignore
61
- */
62
- id?: string,
63
-
64
- /**
65
- * Auto-populated by parent's groupName prop.
66
- * @ignore
67
- */
68
- groupName?: string,
69
-
70
- /**
71
- * Auto-populated by parent. Returns the new checked state of the component.
72
- * @ignore
73
- */
74
- onChange: (newCheckedState: boolean) => mixed,
75
-
76
- /**
77
- * Auto-populated by parent.
78
- * @ignore
79
- */
80
- variant?: "radio" | "checkbox",
81
- |},
82
- |};
83
- declare type DefaultProps = {|
84
- checked: $PropertyType<Props, "checked">,
85
- disabled: $PropertyType<Props, "disabled">,
86
- onChange: $PropertyType<Props, "onChange">,
87
- |};
88
11
  /**
89
12
  * This is a labeled 🔘 or ☑️ item. Choice is meant to be used as children of
90
13
  * CheckboxGroup and RadioGroup because many of its props are auto-populated
@@ -151,8 +74,80 @@ declare type DefaultProps = {|
151
74
  * </RadioGroup>
152
75
  * ```
153
76
  */
154
- declare export default class Choice extends React.Component<Props> {
155
- static defaultProps: DefaultProps;
156
- getChoiceComponent(variant?: string | null): typeof Radio | typeof Checkbox;
157
- render(): React.Node;
158
- }
77
+ declare var Choice: React.ForwardRefExoticComponent<{|
78
+ ...$ReadOnly<$Flowgen$Import$_2e__2e__2f__2e__2e__2f__2e__2e__2f_wonder_2d_blocks_2d_core_2f_src_2f_util_2f_aria_2d_types.AriaAttributes>,
79
+ ...$ReadOnly<{|
80
+ role?: $Flowgen$Import$_2e__2e__2f__2e__2e__2f__2e__2e__2f_wonder_2d_blocks_2d_core_2f_src_2f_util_2f_aria_2d_types.AriaRole | void,
81
+ |}>,
82
+ ...{|
83
+ /**
84
+ * User-defined. Label for the field.
85
+ */
86
+ label: React.Node,
87
+
88
+ /**
89
+ * User-defined. Optional description for the field.
90
+ */
91
+ description?: React.Node,
92
+
93
+ /**
94
+ * User-defined. Should be distinct for each item in the group.
95
+ */
96
+ value: string,
97
+
98
+ /**
99
+ * User-defined. Whether this choice option is disabled. Default false.
100
+ */
101
+ disabled?: boolean | void,
102
+
103
+ /**
104
+ * User-defined. Optional id for testing purposes.
105
+ */
106
+ testId?: string | void,
107
+
108
+ /**
109
+ * User-defined. Optional additional styling.
110
+ */
111
+ style?: StyleType,
112
+
113
+ /**
114
+ * Auto-populated by parent. Whether this choice is checked.
115
+ * @ignore
116
+ */
117
+ checked?: boolean | void,
118
+
119
+ /**
120
+ * Auto-populated by parent. Whether this choice is in error mode (everything
121
+ * in a choice group would be in error mode at the same time).
122
+ * @ignore
123
+ */
124
+ error?: boolean | void,
125
+
126
+ /**
127
+ * Auto-populated by parent. Used for accessibility purposes, where the label
128
+ * id should match the input id.
129
+ * @ignore
130
+ */
131
+ id?: string | void,
132
+
133
+ /**
134
+ * Auto-populated by parent's groupName prop.
135
+ * @ignore
136
+ */
137
+ groupName?: string | void,
138
+
139
+ /**
140
+ * Auto-populated by parent. Returns the new checked state of the component.
141
+ * @ignore
142
+ */
143
+ onChange?: ((newCheckedState: boolean) => mixed) | void,
144
+
145
+ /**
146
+ * Auto-populated by parent.
147
+ * @ignore
148
+ */
149
+ variant?: "checkbox" | "radio" | void,
150
+ |},
151
+ ...React.RefAttributes<HTMLInputElement>,
152
+ |}>;
153
+ declare export default typeof Choice;
@@ -1,8 +1,16 @@
1
1
  import * as React from "react";
2
- import type { ChoiceCoreProps } from "../util/types";
2
+ import type { Checked } from "../util/types";
3
3
  /**
4
4
  * The internal stateless 🔘 Radio button
5
- */ export default class RadioCore extends React.Component<ChoiceCoreProps> {
6
- handleChange: () => void;
7
- render(): React.ReactNode;
8
- }
5
+ */ declare const RadioCore: React.ForwardRefExoticComponent<Readonly<import("../../../wonder-blocks-core/src/util/aria-types").AriaAttributes> & Readonly<{
6
+ role?: import("../../../wonder-blocks-core/src/util/aria-types").AriaRole | undefined;
7
+ }> & {
8
+ checked: Checked;
9
+ disabled: boolean;
10
+ error: boolean;
11
+ groupName?: string | undefined;
12
+ id?: string | undefined;
13
+ testId?: string | undefined;
14
+ onClick: () => void;
15
+ } & React.RefAttributes<HTMLInputElement>>;
16
+ export default RadioCore;
@@ -4,15 +4,27 @@
4
4
  * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
+ import * as $Flowgen$Import$_2e__2e__2f__2e__2e__2f__2e__2e__2f_wonder_2d_blocks_2d_core_2f_src_2f_util_2f_aria_2d_types from "../../../wonder-blocks-core/src/util/aria-types";
7
8
  import * as React from "react";
8
- import type { ChoiceCoreProps } from "../util/types";
9
+ import type { Checked } from "../util/types";
9
10
 
10
11
  /**
11
12
  * The internal stateless 🔘 Radio button
12
13
  */
13
- declare export default class RadioCore
14
- extends React.Component<ChoiceCoreProps>
15
- {
16
- handleChange: () => void;
17
- render(): React.Node;
18
- }
14
+ declare var RadioCore: React.ForwardRefExoticComponent<{|
15
+ ...$ReadOnly<$Flowgen$Import$_2e__2e__2f__2e__2e__2f__2e__2e__2f_wonder_2d_blocks_2d_core_2f_src_2f_util_2f_aria_2d_types.AriaAttributes>,
16
+ ...$ReadOnly<{|
17
+ role?: $Flowgen$Import$_2e__2e__2f__2e__2e__2f__2e__2e__2f_wonder_2d_blocks_2d_core_2f_src_2f_util_2f_aria_2d_types.AriaRole | void,
18
+ |}>,
19
+ ...{|
20
+ checked: Checked,
21
+ disabled: boolean,
22
+ error: boolean,
23
+ groupName?: string | void,
24
+ id?: string | void,
25
+ testId?: string | void,
26
+ onClick: () => void,
27
+ |},
28
+ ...React.RefAttributes<HTMLInputElement>,
29
+ |}>;
30
+ declare export default typeof RadioCore;
@@ -78,8 +78,5 @@ type RadioGroupProps = {
78
78
  * </RadioGroup>
79
79
  * ```
80
80
  */
81
- export default class RadioGroup extends React.Component<RadioGroupProps> {
82
- handleChange(changedValue: string): void;
83
- render(): React.ReactNode;
84
- }
85
- export {};
81
+ declare const RadioGroup: React.ForwardRefExoticComponent<RadioGroupProps & React.RefAttributes<HTMLFieldSetElement>>;
82
+ export default RadioGroup;
@@ -94,9 +94,8 @@ declare type RadioGroupProps = {|
94
94
  * </RadioGroup>
95
95
  * ```
96
96
  */
97
- declare export default class RadioGroup
98
- extends React.Component<RadioGroupProps>
99
- {
100
- handleChange(changedValue: string): void;
101
- render(): React.Node;
102
- }
97
+ declare var RadioGroup: React.AbstractComponent<
98
+ RadioGroupProps,
99
+ HTMLFieldSetElement
100
+ >;
101
+ declare export default typeof RadioGroup;
@@ -1,6 +1,14 @@
1
1
  import * as React from "react";
2
- import type { AriaProps, StyleType } from "@khanacademy/wonder-blocks-core";
3
- type ChoiceComponentProps = AriaProps & {
2
+ import type { StyleType } from "@khanacademy/wonder-blocks-core";
3
+ /**
4
+ * 🔘 A nicely styled radio button for all your non-AMFM radio button needs. Can
5
+ * optionally take label and description props.
6
+ *
7
+ * This component should not really be used by itself because radio buttons are
8
+ * often grouped together. See RadioGroup.
9
+ */ declare const Radio: React.ForwardRefExoticComponent<Readonly<import("../../../wonder-blocks-core/src/util/aria-types").AriaAttributes> & Readonly<{
10
+ role?: import("../../../wonder-blocks-core/src/util/aria-types").AriaRole | undefined;
11
+ }> & {
4
12
  /**
5
13
  * Whether this component is checked
6
14
  */
@@ -8,11 +16,11 @@ type ChoiceComponentProps = AriaProps & {
8
16
  /**
9
17
  * Whether this component is disabled
10
18
  */
11
- disabled: boolean;
19
+ disabled?: boolean | undefined;
12
20
  /**
13
21
  * Whether this component should show an error state
14
22
  */
15
- error: boolean;
23
+ error?: boolean | undefined;
16
24
  /**
17
25
  * Callback when this component is selected. The newCheckedState is the
18
26
  * new checked state of the component.
@@ -31,7 +39,7 @@ type ChoiceComponentProps = AriaProps & {
31
39
  * guarantee that the ID is unique within everything rendered on a page.
32
40
  * Used to match `<label>` with `<input>` elements for screenreaders.
33
41
  */
34
- id?: string;
42
+ id?: string | undefined;
35
43
  /**
36
44
  * Optional styling for the container. Does not style the component.
37
45
  */
@@ -39,30 +47,16 @@ type ChoiceComponentProps = AriaProps & {
39
47
  /**
40
48
  * Adds CSS classes to the Checkbox.
41
49
  */
42
- className?: string;
50
+ className?: string | undefined;
43
51
  /**
44
52
  * Optional test ID for e2e testing
45
53
  */
46
- testId?: string;
54
+ testId?: string | undefined;
47
55
  /**
48
56
  * Name for the checkbox or radio button group. Only applicable for group
49
57
  * contexts, auto-populated by group components via Choice.
50
58
  * @ignore
51
59
  */
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.ReactNode;
67
- }
68
- export {};
60
+ groupName?: string | undefined;
61
+ } & React.RefAttributes<HTMLInputElement>>;
62
+ export default Radio;
@@ -4,10 +4,22 @@
4
4
  * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
+ import * as $Flowgen$Import$_2e__2e__2f__2e__2e__2f__2e__2e__2f_wonder_2d_blocks_2d_core_2f_src_2f_util_2f_aria_2d_types from "../../../wonder-blocks-core/src/util/aria-types";
7
8
  import * as React from "react";
8
- import type { AriaProps, StyleType } from "@khanacademy/wonder-blocks-core";
9
- declare type ChoiceComponentProps = {|
10
- ...AriaProps,
9
+ import type { StyleType } from "@khanacademy/wonder-blocks-core";
10
+
11
+ /**
12
+ * 🔘 A nicely styled radio button for all your non-AMFM radio button needs. Can
13
+ * optionally take label and description props.
14
+ *
15
+ * This component should not really be used by itself because radio buttons are
16
+ * often grouped together. See RadioGroup.
17
+ */
18
+ declare var Radio: React.ForwardRefExoticComponent<{|
19
+ ...$ReadOnly<$Flowgen$Import$_2e__2e__2f__2e__2e__2f__2e__2e__2f_wonder_2d_blocks_2d_core_2f_src_2f_util_2f_aria_2d_types.AriaAttributes>,
20
+ ...$ReadOnly<{|
21
+ role?: $Flowgen$Import$_2e__2e__2f__2e__2e__2f__2e__2e__2f_wonder_2d_blocks_2d_core_2f_src_2f_util_2f_aria_2d_types.AriaRole | void,
22
+ |}>,
11
23
  ...{|
12
24
  /**
13
25
  * Whether this component is checked
@@ -17,12 +29,12 @@ declare type ChoiceComponentProps = {|
17
29
  /**
18
30
  * Whether this component is disabled
19
31
  */
20
- disabled: boolean,
32
+ disabled?: boolean | void,
21
33
 
22
34
  /**
23
35
  * Whether this component should show an error state
24
36
  */
25
- error: boolean,
37
+ error?: boolean | void,
26
38
 
27
39
  /**
28
40
  * Callback when this component is selected. The newCheckedState is the
@@ -45,7 +57,7 @@ declare type ChoiceComponentProps = {|
45
57
  * guarantee that the ID is unique within everything rendered on a page.
46
58
  * Used to match `<label>` with `<input>` elements for screenreaders.
47
59
  */
48
- id?: string,
60
+ id?: string | void,
49
61
 
50
62
  /**
51
63
  * Optional styling for the container. Does not style the component.
@@ -55,35 +67,20 @@ declare type ChoiceComponentProps = {|
55
67
  /**
56
68
  * Adds CSS classes to the Checkbox.
57
69
  */
58
- className?: string,
70
+ className?: string | void,
59
71
 
60
72
  /**
61
73
  * Optional test ID for e2e testing
62
74
  */
63
- testId?: string,
75
+ testId?: string | void,
64
76
 
65
77
  /**
66
78
  * Name for the checkbox or radio button group. Only applicable for group
67
79
  * contexts, auto-populated by group components via Choice.
68
80
  * @ignore
69
81
  */
70
- groupName?: string,
82
+ groupName?: string | void,
71
83
  |},
72
- |};
73
- declare type DefaultProps = {|
74
- disabled: $PropertyType<ChoiceComponentProps, "disabled">,
75
- error: $PropertyType<ChoiceComponentProps, "error">,
76
- |};
77
- /**
78
- * 🔘 A nicely styled radio button for all your non-AMFM radio button needs. Can
79
- * optionally take label and description props.
80
- *
81
- * This component should not really be used by itself because radio buttons are
82
- * often grouped together. See RadioGroup.
83
- */
84
- declare export default class Radio
85
- extends React.Component<ChoiceComponentProps>
86
- {
87
- static defaultProps: DefaultProps;
88
- render(): React.Node;
89
- }
84
+ ...React.RefAttributes<HTMLInputElement>,
85
+ |}>;
86
+ declare export default typeof Radio;