@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,147 +0,0 @@
1
- import {Meta, Story, Canvas} from "@storybook/addon-docs";
2
- import {StyleSheet} from "aphrodite";
3
-
4
- import Color from "@khanacademy/wonder-blocks-color";
5
- import {Checkbox} from "@khanacademy/wonder-blocks-form";
6
- import {LabelSmall} from "@khanacademy/wonder-blocks-typography";
7
-
8
- <Meta
9
- title="Form/Checkbox/Accessibility"
10
- component={Checkbox}
11
- parameters={{
12
- previewTabs: {
13
- canvas: {hidden: true},
14
- },
15
- viewMode: "docs",
16
- chromatic: {
17
- // Disables chromatic testing for these stories.
18
- disableSnapshot: true,
19
- },
20
- }}
21
- />
22
-
23
- export const ErrorTemplate = (args) => {
24
- const [checked, setChecked] = React.useState(false);
25
- const errorState = !checked;
26
- return (
27
- <View>
28
- <Checkbox
29
- checked={checked}
30
- onChange={setChecked}
31
- error={errorState}
32
- aria-describedby={errorState && "error-message"}
33
- aria-required={true}
34
- {...args}
35
- />
36
- {errorState && (
37
- <LabelSmall style={styles.error} id="error-message">
38
- You must agree to the terms to continue
39
- </LabelSmall>
40
- )}
41
- </View>
42
- );
43
- };
44
-
45
- export const DisabledTemplate = (args) => {
46
- const [checked, setChecked] = React.useState(false);
47
- const errorState = !checked;
48
- return (
49
- <Checkbox
50
- checked={checked}
51
- onChange={setChecked}
52
- label="Some setting"
53
- description="You do not have permission to change this setting"
54
- disabled={true}
55
- />
56
- );
57
- };
58
-
59
- ## Accessibility
60
-
61
- ### ARIA
62
-
63
- `Checkbox` can take in all ARIA props defined in Wonder Blocks Core types.
64
-
65
- Elements with role `"checkbox"` can have an `aria-checked` property that
66
- exposes the checked state to assistive technology. The dev does not have
67
- to worry about this because the Wonder Blocks Checkbox component is an
68
- `input` element with type `"checkbox"`, as this has built-in semantics and
69
- does not require ARIA.
70
-
71
- The current implementation of `Checkbox` uses `aria-describedby` with the
72
- label and description that may be passed in as props.
73
-
74
- See the Error section for information about `aria-invalid` and
75
- `aria-required`.
76
-
77
- ### Error state
78
-
79
- The Wonder Blocks `Checkbox` component takes an `error` boolean prop. Setting
80
- this prop to true will set `aria-invalid` to true, and the color of the
81
- checkbox to red.
82
-
83
- When a form input is invalid, the user should provide a reason for why
84
- this is.
85
-
86
- Generally, it is also suggested this is the validation error message is
87
- passed to the checkbox's `aria-describedby` prop so assistive tech can
88
- read it. However, this is not possible with the current implementation of
89
- the Wonder Blocks Form Checkbox component.
90
-
91
- The error state can be used to signal that a required checkbox has not been
92
- checked. In cases where a checkbox is required, the checkbox component should
93
- set the `aria-required` prop to true for assistive tech.
94
- There should also be some sort of visual indication that checking
95
- the box is required, such as a "Required" label or an asterisk.
96
-
97
- <Canvas>
98
- <Story
99
- name="Error state"
100
- args={{
101
- label: "I accept the terms and conditions",
102
- }}
103
- >
104
- {ErrorTemplate.bind({})}
105
- </Story>
106
- </Canvas>
107
-
108
- ### Disabled state
109
-
110
- The Wonder Blocks `Checkbox` compoenent takes a `disabled` boolean prop.
111
- This sets the underlying `input` element's `disabled` prop to `true`.
112
- This makes is so that the checkbox is not interactable. Also, assistive
113
- tech will indicated that the checkbox is dimmed.
114
-
115
- A user will not be able to navigate to the checkbox with a keyboard.
116
- Screen reader users will be able to navigate to the checkbox with
117
- screen reader controls.
118
-
119
- It is suggested that if an element is disabled, an explanation as to why
120
- should to provided somewhere.
121
-
122
- <Canvas>
123
- <Story name="Disabled state">{DisabledTemplate.bind({})}</Story>
124
- </Canvas>
125
-
126
- ### Keyboard Interaction
127
-
128
- If a checkbox is not disabled, a user can tab to it using standard
129
- keyboard navigation. The Space key toggles the checked state of the checkbox.
130
-
131
- Note the the Space key triggers the `onChange` function of the
132
- Wonder Blocks Checkbox component. If the user does not specify an `onChange`
133
- funciton prop that in turn updates the value of `checked`, neither clicking
134
- nor the Space key will toggle the Checkbox.
135
-
136
- ### References
137
-
138
- - [Accessible validation of checkbox and radiobutton groups](https://blog.tenon.io/accessible-validation-of-checkbox-and-radiobutton-groups/)
139
- - [HTML: Validating a checkbox with HTML5](https://www.the-art-of-web.com/html/html5-checkbox-required/#example1)
140
- - [aria-checked MDN Docs](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-checked)
141
- - [ARIA: checkbox role MDN Docs](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/checkbox_role)
142
-
143
- export const styles = StyleSheet.create({
144
- error: {
145
- color: Color.red,
146
- },
147
- });
@@ -1,300 +0,0 @@
1
- // @flow
2
- import * as React from "react";
3
- import {StyleSheet} from "aphrodite";
4
-
5
- import {View} from "@khanacademy/wonder-blocks-core";
6
- import Color from "@khanacademy/wonder-blocks-color";
7
- import {Choice, CheckboxGroup} from "@khanacademy/wonder-blocks-form";
8
- import Spacing from "@khanacademy/wonder-blocks-spacing";
9
- import {LabelLarge, LabelXSmall} from "@khanacademy/wonder-blocks-typography";
10
-
11
- import type {StoryComponentType} from "@storybook/react";
12
-
13
- import ComponentInfo from "../../../../../.storybook/components/component-info";
14
- import {name, version} from "../../../package.json";
15
-
16
- export default {
17
- title: "Form / CheckboxGroup",
18
- component: CheckboxGroup,
19
- parameters: {
20
- componentSubtitle: ((
21
- <ComponentInfo name={name} version={version} />
22
- ): any),
23
- },
24
- };
25
-
26
- export const Default: StoryComponentType = (args) => {
27
- return (
28
- <CheckboxGroup {...args}>
29
- <Choice label="Pepperoni" value="pepperoni" />
30
- <Choice
31
- label="Sausage"
32
- value="sausage"
33
- description="Imported from Italy"
34
- />
35
- <Choice label="Extra cheese" value="cheese" />
36
- <Choice label="Green pepper" value="pepper" />
37
- <Choice label="Mushroom" value="mushroom" />
38
- </CheckboxGroup>
39
- );
40
- };
41
-
42
- Default.args = {
43
- // Required
44
- groupName: "toppings",
45
- selectedValues: ["pepperoni", "sausage"],
46
- onChange: () => {},
47
- // Optional
48
- label: "Pizza toppings",
49
- description: "Choose as many toppings as you would like.",
50
- };
51
-
52
- export const Basic: StoryComponentType = () => {
53
- const [selectedValues, setSelectedValues] = React.useState([]);
54
-
55
- return (
56
- <CheckboxGroup
57
- groupName="toppings"
58
- onChange={setSelectedValues}
59
- selectedValues={selectedValues}
60
- >
61
- <Choice label="Pepperoni" value="pepperoni" />
62
- <Choice
63
- label="Sausage"
64
- value="sausage"
65
- description="Imported from Italy"
66
- />
67
- <Choice label="Extra cheese" value="cheese" />
68
- <Choice label="Green pepper" value="pepper" />
69
- <Choice label="Mushroom" value="mushroom" />
70
- </CheckboxGroup>
71
- );
72
- };
73
-
74
- Basic.parameters = {
75
- docs: {
76
- storyDescription: `This is a basic example of a checkbox group.
77
- The Wonder Blocks \`CheckboxGroup\` component takes \`Choice\`
78
- components as children. One of the \`Choice\` components here
79
- includes a description.`,
80
- },
81
- };
82
-
83
- export const Error: StoryComponentType = () => {
84
- const toppingsError = "You have selected too many toppings";
85
- const [selectedValues, setSelectedValues] = React.useState([
86
- "pepperoni",
87
- "sausage",
88
- "cheese",
89
- "pepper",
90
- ]);
91
- const [error, setError] = React.useState(toppingsError);
92
-
93
- // Returns an error message if more than 3 items are selected,
94
- // and it returns undefined otherwise. We use undefined instead of
95
- // null here because null would result in a flow error, whereas
96
- // undefined would be the same as not passing in anything to the
97
- // checkbox group's `errorMessage` prop.
98
- const checkForError = (input) => {
99
- if (input.length > 3) {
100
- return toppingsError;
101
- }
102
- };
103
-
104
- const handleChange = (input) => {
105
- const errorMessage = checkForError(input);
106
- setSelectedValues(input);
107
- setError(errorMessage);
108
- };
109
-
110
- return (
111
- <CheckboxGroup
112
- label="Pizza order"
113
- groupName="toppings"
114
- description="You may choose at most three toppings"
115
- onChange={handleChange}
116
- errorMessage={error}
117
- selectedValues={selectedValues}
118
- >
119
- <Choice label="Pepperoni" value="pepperoni" />
120
- <Choice
121
- label="Sausage"
122
- value="sausage"
123
- description="Imported from Italy"
124
- />
125
- <Choice label="Extra cheese" value="cheese" />
126
- <Choice label="Green pepper" value="pepper" />
127
- <Choice label="Mushroom" value="mushroom" />
128
- </CheckboxGroup>
129
- );
130
- };
131
-
132
- Error.parameters = {
133
- docs: {
134
- storyDescription: `This is what a checkbox group looks like
135
- if it has an error. It displays the error that is passed into the
136
- \`errorMessage\` prop, provided the error is not null. It also
137
- uses the error styling for all the checkboxes. Here, the error
138
- message is saved as a state, updated in the change handler, and then
139
- passed in as the \`errorMessage\` prop.`,
140
- },
141
- };
142
-
143
- export const RowStyling: StoryComponentType = () => {
144
- const [selectedValues, setSelectedValues] = React.useState([]);
145
-
146
- return (
147
- <View style={styles.wrapper}>
148
- <LabelLarge style={styles.title}>Science</LabelLarge>
149
- <CheckboxGroup
150
- groupName="science-classes"
151
- onChange={setSelectedValues}
152
- selectedValues={selectedValues}
153
- style={styles.group}
154
- >
155
- <Choice label="Biology" value="1" style={styles.choice} />
156
- <Choice label="AP®︎ Biology" value="2" style={styles.choice} />
157
- <Choice
158
- label="High school biology"
159
- value="3"
160
- style={styles.choice}
161
- />
162
- <Choice
163
- label="Cosmology and astronomy"
164
- value="4"
165
- style={styles.choice}
166
- />
167
- <Choice
168
- label="Electrical engineering"
169
- value="5"
170
- style={styles.choice}
171
- />
172
- <Choice
173
- label="Health and medicine"
174
- value="6"
175
- style={styles.choice}
176
- />
177
- </CheckboxGroup>
178
- </View>
179
- );
180
- };
181
-
182
- RowStyling.parameters = {
183
- docs: {
184
- storyDescription: `This example shows how one can add custom styles
185
- to the checkbox group and to each component to achieve desired custom
186
- layouts. The context in this example is inspired by the class selector
187
- modal. The label is created separately because we are reflowing all
188
- the elements in the group to row. The checkboxes render
189
- horizontally when the style on the \`CheckboxGroup\` is set to
190
- \`{flexDirection: "row"}\`. Here, \`{flexWrap: "wrap"}\` is also
191
- used so the options continue on the next line.`,
192
- },
193
- };
194
-
195
- export const MultipleChoiceStyling: StoryComponentType = () => {
196
- const [selectedValues, setSelectedValues] = React.useState([]);
197
-
198
- return (
199
- <CheckboxGroup
200
- label={<LabelLarge>Select all prime numbers</LabelLarge>}
201
- description={
202
- <LabelXSmall style={styles.description}>
203
- Hint: There is at least one prime number
204
- </LabelXSmall>
205
- }
206
- groupName="science-classes"
207
- onChange={setSelectedValues}
208
- selectedValues={selectedValues}
209
- >
210
- <Choice label="1" value="1" style={styles.multipleChoice} />
211
- <Choice label="2" value="2" style={styles.multipleChoice} />
212
- <Choice label="3" value="3" style={styles.multipleChoice} />
213
- <Choice label="4" value="4" style={styles.multipleChoice} />
214
- <Choice
215
- label="5"
216
- value="5"
217
- style={[styles.multipleChoice, styles.last]}
218
- />
219
- </CheckboxGroup>
220
- );
221
- };
222
-
223
- MultipleChoiceStyling.parameters = {
224
- docs: {
225
- storyDescription: `This example shows how to use custom styling
226
- to change the appearance of the checkbox group to look more like
227
- a multiple choice question. You may also provide custom typography
228
- to the label and description. Here, there is a line in
229
- between each question, which is achieved using the
230
- \`{borderTop: "solid 1px #CCC"}\` style on each \`Choice\`
231
- component.`,
232
- },
233
- };
234
-
235
- export const FiltersOutFalsyChildren: StoryComponentType = () => {
236
- return (
237
- <CheckboxGroup
238
- groupName="pokemon"
239
- selectedValues={["pepperoni", "sausage"]}
240
- onChange={() => {}}
241
- label="Pokemon"
242
- description="Your first Pokemon."
243
- >
244
- <Choice label="Pepperoni" value="pepperoni" />
245
- <Choice
246
- label="Sausage"
247
- value="sausage"
248
- description="Imported from Italy"
249
- />
250
- <Choice label="Extra cheese" value="cheese" />
251
- <Choice label="Green pepper" value="pepper" />
252
- {false && <Choice label="Mushroom" value="mushroom" />}
253
- </CheckboxGroup>
254
- );
255
- };
256
-
257
- FiltersOutFalsyChildren.parameters = {
258
- docs: {
259
- storyDescription: `This example shows that children can be falsy values and
260
- that those falsy values are filtered out when rendering children. In this
261
- case, one of the children is \`{false && <Choice .../>}\` which results in
262
- that choice being filtered out.`,
263
- },
264
- chromatic: {
265
- // The unit tests already verify that false-y children aren't rendered.
266
- disableSnapshot: true,
267
- },
268
- };
269
-
270
- const styles = StyleSheet.create({
271
- // Row styling
272
- wrapper: {
273
- width: 650,
274
- },
275
- group: {
276
- flexDirection: "row",
277
- flexWrap: "wrap",
278
- },
279
- choice: {
280
- marginTop: Spacing.xSmall_8,
281
- width: 200,
282
- },
283
- title: {
284
- paddingBottom: Spacing.xSmall_8,
285
- borderBottom: `1px solid ${Color.offBlack64}`,
286
- },
287
- // Multiple choice styling
288
- multipleChoice: {
289
- margin: 0,
290
- height: 48,
291
- borderTop: "solid 1px #CCC",
292
- justifyContent: "center",
293
- },
294
- description: {
295
- color: Color.offBlack64,
296
- },
297
- last: {
298
- borderBottom: "solid 1px #CCC",
299
- },
300
- });
@@ -1,167 +0,0 @@
1
- // @flow
2
- import * as React from "react";
3
- import {StyleSheet} from "aphrodite";
4
-
5
- import {View} from "@khanacademy/wonder-blocks-core";
6
- import {LabelMedium, LabelSmall} from "@khanacademy/wonder-blocks-typography";
7
- import type {StoryComponentType} from "@storybook/react";
8
-
9
- import Checkbox from "../checkbox";
10
-
11
- import ComponentInfo from "../../../../../.storybook/components/component-info";
12
- import {name, version} from "../../../package.json";
13
-
14
- export default {
15
- title: "Form / Checkbox",
16
- component: Checkbox,
17
- parameters: {
18
- componentSubtitle: ((
19
- <ComponentInfo name={name} version={version} />
20
- ): any),
21
- },
22
- };
23
-
24
- export const Default: StoryComponentType = (args) => <Checkbox {...args} />;
25
-
26
- Default.args = {
27
- checked: false,
28
- onChange: () => {},
29
- };
30
-
31
- Default.parameters = {
32
- chromatic: {
33
- // We already have screenshots of another story that covers
34
- // this and more cases.
35
- disableSnapshot: true,
36
- },
37
- };
38
-
39
- export const Controlled: StoryComponentType = () => {
40
- const [checked, setChecked] = React.useState(false);
41
- return <Checkbox checked={checked} onChange={setChecked} />;
42
- };
43
-
44
- Controlled.parameters = {
45
- chromatic: {
46
- // Disabling because this doesn't test visuals, its for testing
47
- // that `state` works as expected.
48
- disableSnapshot: true,
49
- },
50
- docs: {
51
- storyDescription:
52
- "Use state to keep track of whether the checkbox is checked or not",
53
- },
54
- };
55
-
56
- export const Variants: StoryComponentType = () => (
57
- <View style={styles.row}>
58
- <Checkbox
59
- error={false}
60
- checked={false}
61
- style={styles.marginRight}
62
- onChange={() => {}}
63
- />
64
- <Checkbox
65
- error={false}
66
- checked={true}
67
- style={styles.marginRight}
68
- onChange={() => {}}
69
- />
70
- <Checkbox
71
- error={true}
72
- checked={false}
73
- style={styles.marginRight}
74
- onChange={() => {}}
75
- />
76
- <Checkbox
77
- error={true}
78
- checked={true}
79
- style={styles.marginRight}
80
- onChange={() => {}}
81
- />
82
- <Checkbox
83
- disabled={true}
84
- checked={false}
85
- style={styles.marginRight}
86
- onChange={() => {}}
87
- />
88
- <Checkbox
89
- disabled={true}
90
- checked={true}
91
- style={styles.marginRight}
92
- onChange={() => {}}
93
- />
94
- </View>
95
- );
96
-
97
- Variants.parameters = {
98
- docs: {
99
- storyDescription:
100
- "The checkbox has various styles for clickable states. Here are sets of default checkboxes, checkboxes in an error state, and disabled checkboxes.",
101
- },
102
- };
103
-
104
- export const WithLabel: StoryComponentType = () => {
105
- const [checked, setChecked] = React.useState(false);
106
-
107
- return (
108
- <Checkbox
109
- label="Receive assignment reminders for Algebra"
110
- description="You will receive a reminder 24 hours before each deadline"
111
- checked={checked}
112
- onChange={setChecked}
113
- />
114
- );
115
- };
116
-
117
- WithLabel.parameters = {
118
- docs: {
119
- storyDescription:
120
- "The checkbox can have an optional label and description. This allows it to be used as a settings-like item. The user of this component is responsible for keeping track of checked state and providing an onChange callback.",
121
- },
122
- };
123
-
124
- export const AdditionalClickTarget: StoryComponentType = () => {
125
- const [checked, setChecked] = React.useState(false);
126
- const headingText = "Functions";
127
- const descriptionText = `A great cook knows how to take basic
128
- ingredients and prepare a delicious meal. In this topic, you will
129
- become function-chefs! You will learn how to combine functions
130
- with arithmetic operations and how to compose functions.`;
131
-
132
- return (
133
- <View style={styles.wrapper}>
134
- <View style={styles.topic}>
135
- <label htmlFor="topic-123">
136
- <LabelMedium>{headingText}</LabelMedium>
137
- </label>
138
- <LabelSmall>{descriptionText}</LabelSmall>
139
- </View>
140
- <Checkbox checked={checked} id="topic-123" onChange={setChecked} />
141
- </View>
142
- );
143
- };
144
-
145
- AdditionalClickTarget.parameters = {
146
- docs: {
147
- storyDescription:
148
- "Sometimes one may wish to use a checkbox in a different context (label may not be right next to the checkbox), like in this example content item. Use a `<label htmlFor={id}>` element where the id matches the `id` prop of the Checkbox. This is for accessibility purposes, and doing this also automatically makes the label a click target for the checkbox.",
149
- },
150
- };
151
-
152
- const styles = StyleSheet.create({
153
- row: {
154
- flexDirection: "row",
155
- },
156
- marginRight: {
157
- marginRight: 16,
158
- },
159
- wrapper: {
160
- flexDirection: "row",
161
- alignItems: "center",
162
- justifyContent: "space-evenly",
163
- },
164
- topic: {
165
- maxWidth: 600,
166
- },
167
- });
@@ -1,86 +0,0 @@
1
- // @flow
2
- import * as React from "react";
3
- import {StyleSheet} from "aphrodite";
4
-
5
- import {View} from "@khanacademy/wonder-blocks-core";
6
- import {
7
- Choice,
8
- CheckboxGroup,
9
- RadioGroup,
10
- } from "@khanacademy/wonder-blocks-form";
11
- import {Strut} from "@khanacademy/wonder-blocks-layout";
12
- import Spacing from "@khanacademy/wonder-blocks-spacing";
13
-
14
- import type {StoryComponentType} from "@storybook/react";
15
-
16
- import ComponentInfo from "../../../../../.storybook/components/component-info";
17
- import {name, version} from "../../../package.json";
18
-
19
- export default {
20
- title: "Form / Choice",
21
- component: Choice,
22
- parameters: {
23
- componentSubtitle: ((
24
- <ComponentInfo name={name} version={version} />
25
- ): any),
26
- },
27
- };
28
-
29
- export const Default: StoryComponentType = (args) => {
30
- const [selectedValues, setSelectedValues] = React.useState([]);
31
- const [selectedValue, setSelectedValue] = React.useState("");
32
-
33
- return (
34
- <View style={styles.row}>
35
- <CheckboxGroup
36
- label="Pizza order"
37
- description="Choose as many toppings as you would like."
38
- groupName="Toppings"
39
- onChange={setSelectedValues}
40
- selectedValues={selectedValues}
41
- >
42
- <Choice label="Pepperoni" value="pepperoni" />
43
- <Choice
44
- label="Sausage"
45
- value="sausage"
46
- description="Imported from Italy"
47
- />
48
- <Choice label="Extra cheese" value="cheese" />
49
- <Choice label="Green pepper" value="pepper" />
50
- <Choice label="Mushroom" value="mushroom" />
51
- <Choice {...args} />
52
- </CheckboxGroup>
53
- <Strut size={Spacing.xLarge_32} />
54
- <RadioGroup
55
- label="Pizza order"
56
- description="Choose only one topping."
57
- groupName="Toppings"
58
- onChange={setSelectedValue}
59
- selectedValue={selectedValue}
60
- >
61
- <Choice label="Pepperoni" value="pepperoni" />
62
- <Choice
63
- label="Sausage"
64
- value="sausage"
65
- description="Imported from Italy"
66
- />
67
- <Choice label="Extra cheese" value="cheese" />
68
- <Choice label="Green pepper" value="pepper" />
69
- <Choice label="Mushroom" value="mushroom" />
70
- <Choice {...args} />
71
- </RadioGroup>
72
- </View>
73
- );
74
- };
75
-
76
- Default.args = {
77
- label: "Pineapple (Control)",
78
- value: "pineapple",
79
- description: "Does in fact belong on pizzas",
80
- };
81
-
82
- const styles = StyleSheet.create({
83
- row: {
84
- flexDirection: "row",
85
- },
86
- });