@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.
Files changed (66) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/components/checkbox-core.d.ts +16 -0
  3. package/dist/components/checkbox-core.js.flow +26 -0
  4. package/dist/components/checkbox-group.d.ts +84 -0
  5. package/dist/components/checkbox-group.js.flow +103 -0
  6. package/dist/components/checkbox.d.ts +83 -0
  7. package/dist/components/checkbox.js.flow +106 -0
  8. package/dist/components/choice-internal.d.ts +63 -0
  9. package/dist/components/choice-internal.js.flow +100 -0
  10. package/dist/components/choice.d.ts +127 -0
  11. package/dist/components/choice.js.flow +161 -0
  12. package/dist/components/field-heading.d.ts +50 -0
  13. package/dist/components/field-heading.js.flow +64 -0
  14. package/dist/components/group-styles.d.ts +3 -0
  15. package/dist/components/group-styles.js.flow +10 -0
  16. package/dist/components/labeled-text-field.d.ts +169 -0
  17. package/dist/components/labeled-text-field.js.flow +211 -0
  18. package/dist/components/radio-core.d.ts +15 -0
  19. package/dist/components/radio-core.js.flow +26 -0
  20. package/dist/components/radio-group.d.ts +85 -0
  21. package/dist/components/radio-group.js.flow +104 -0
  22. package/dist/components/radio.d.ts +68 -0
  23. package/dist/components/radio.js.flow +92 -0
  24. package/dist/components/text-field.d.ts +146 -0
  25. package/dist/components/text-field.js.flow +186 -0
  26. package/dist/es/index.js +258 -224
  27. package/dist/index.d.ts +7 -0
  28. package/dist/index.js +281 -249
  29. package/dist/index.js.flow +21 -2
  30. package/dist/util/types.d.ts +62 -0
  31. package/dist/util/types.js.flow +138 -0
  32. package/package.json +10 -10
  33. package/src/__tests__/{custom-snapshot.test.js → custom-snapshot.test.tsx} +8 -9
  34. package/src/components/__tests__/{checkbox-group.test.js → checkbox-group.test.tsx} +5 -5
  35. package/src/components/__tests__/{field-heading.test.js → field-heading.test.tsx} +0 -1
  36. package/src/components/__tests__/{labeled-text-field.test.js → labeled-text-field.test.tsx} +4 -5
  37. package/src/components/__tests__/{radio-group.test.js → radio-group.test.tsx} +8 -8
  38. package/src/components/__tests__/{text-field.test.js → text-field.test.tsx} +22 -18
  39. package/src/components/{checkbox-core.js → checkbox-core.tsx} +12 -15
  40. package/src/components/{checkbox-group.js → checkbox-group.tsx} +20 -23
  41. package/src/components/{checkbox.js → checkbox.tsx} +18 -32
  42. package/src/components/{choice-internal.js → choice-internal.tsx} +25 -39
  43. package/src/components/{choice.js → choice.tsx} +24 -37
  44. package/src/components/{field-heading.js → field-heading.tsx} +16 -23
  45. package/src/components/{group-styles.js → group-styles.ts} +0 -1
  46. package/src/components/{labeled-text-field.js → labeled-text-field.tsx} +54 -69
  47. package/src/components/{radio-core.js → radio-core.tsx} +13 -16
  48. package/src/components/{radio-group.js → radio-group.tsx} +20 -23
  49. package/src/components/{radio.js → radio.tsx} +18 -32
  50. package/src/components/{text-field.js → text-field.tsx} +53 -64
  51. package/src/{index.js → index.ts} +0 -1
  52. package/src/util/{types.js → types.ts} +32 -35
  53. package/tsconfig.json +19 -0
  54. package/tsconfig.tsbuildinfo +1 -0
  55. package/src/__docs__/_overview_.stories.mdx +0 -15
  56. package/src/components/__docs__/checkbox-accessibility.stories.mdx +0 -147
  57. package/src/components/__docs__/checkbox-group.stories.js +0 -300
  58. package/src/components/__docs__/checkbox.stories.js +0 -167
  59. package/src/components/__docs__/choice.stories.js +0 -86
  60. package/src/components/__docs__/labeled-text-field.argtypes.js +0 -248
  61. package/src/components/__docs__/labeled-text-field.stories.js +0 -709
  62. package/src/components/__docs__/radio-group.stories.js +0 -217
  63. package/src/components/__docs__/radio.stories.js +0 -161
  64. package/src/components/__docs__/text-field.argtypes.js +0 -206
  65. package/src/components/__docs__/text-field.stories.js +0 -780
  66. /package/src/__tests__/__snapshots__/{custom-snapshot.test.js.snap → custom-snapshot.test.tsx.snap} +0 -0
@@ -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
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) => mixed,
32
-
24
+ onChange: (newCheckedState: boolean) => unknown;
33
25
  /**
34
26
  * Optional label for the field.
35
27
  */
36
- label?: React.Node,
37
-
28
+ label?: React.ReactNode;
38
29
  /**
39
30
  * Optional description for the field.
40
31
  */
41
- description?: React.Node,
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: $PropertyType<ChoiceComponentProps, "disabled">,
75
- error: $PropertyType<ChoiceComponentProps, "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.Node {
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
 
@@ -13,62 +11,49 @@ import type {AriaProps, StyleType} from "@khanacademy/wonder-blocks-core";
13
11
  import CheckboxCore from "./checkbox-core";
14
12
  import RadioCore from "./radio-core";
15
13
 
16
- type Props = {|
17
- ...AriaProps,
18
-
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) => mixed,
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.Node,
56
-
43
+ label?: React.ReactNode;
57
44
  /** Optional description for the field. */
58
- description?: React.Node,
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: $PropertyType<Props, "checked">,
69
- disabled: $PropertyType<Props, "disabled">,
70
- error: $PropertyType<Props, "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<>) => void = (event) => {
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.Node {
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: string | void): React.Node {
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.Node {
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
4
  import Checkbox from "./checkbox";
7
5
  import Radio from "./radio";
8
6
 
9
- type Props = {|
10
- ...AriaProps,
11
-
7
+ type Props = AriaProps & {
12
8
  /** User-defined. Label for the field. */
13
- label: React.Node,
14
-
9
+ label: React.ReactNode;
15
10
  /** User-defined. Optional description for the field. */
16
- description?: React.Node,
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) => mixed,
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: $PropertyType<Props, "checked">,
71
- disabled: $PropertyType<Props, "disabled">,
72
- onChange: $PropertyType<Props, "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(variant: ?string): typeof Radio | typeof Checkbox {
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.Node {
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, type StyleType} from "@khanacademy/wonder-blocks-core";
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.Node,
16
-
14
+ field: React.ReactNode;
17
15
  /**
18
16
  * The title for the label element.
19
17
  */
20
- label: React.Node,
21
-
18
+ label: React.ReactNode;
22
19
  /**
23
20
  * The text for the description element.
24
21
  */
25
- description?: React.Node,
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.Node,
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.Node {
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(): ?React.Node {
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(): ?React.Node {
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.Node {
124
+ render(): React.ReactElement {
132
125
  const {field, style} = this.props;
133
126
 
134
127
  return (
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import {StyleSheet} from "aphrodite";
3
2
 
4
3
  import Color from "@khanacademy/wonder-blocks-color";