@khanacademy/wonder-blocks-form 2.4.8 → 3.1.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.
- package/CHANGELOG.md +18 -0
- package/dist/es/index.js +15 -13
- package/dist/index.js +75 -77
- package/docs.md +5 -1
- package/package.json +2 -2
- package/src/__docs__/_overview_.stories.mdx +15 -0
- package/src/components/__docs__/checkbox-group.stories.js +35 -1
- package/src/components/__docs__/labeled-text-field.argtypes.js +2 -2
- package/src/components/__docs__/labeled-text-field.stories.js +25 -0
- package/src/components/__docs__/radio-group.stories.js +35 -0
- package/src/components/__docs__/radio.stories.js +3 -2
- package/src/components/__tests__/checkbox-group.test.js +144 -67
- package/src/components/__tests__/field-heading.test.js +40 -0
- package/src/components/__tests__/radio-group.test.js +155 -58
- package/src/components/checkbox-group.js +9 -15
- package/src/components/checkbox.js +2 -2
- package/src/components/choice-internal.js +5 -3
- package/src/components/choice.js +2 -2
- package/src/components/field-heading.js +27 -43
- package/src/components/labeled-text-field.js +2 -3
- package/src/components/radio-group.js +6 -4
- package/src/components/radio.js +2 -2
- package/src/index.js +0 -2
- package/src/__tests__/__snapshots__/generated-snapshot.test.js.snap +0 -6126
- package/src/__tests__/generated-snapshot.test.js +0 -654
- package/src/components/checkbox-group.md +0 -200
- package/src/components/checkbox.md +0 -134
- package/src/components/field-heading.md +0 -43
- package/src/components/labeled-text-field.md +0 -535
- package/src/components/radio-group.md +0 -129
- package/src/components/radio.md +0 -26
- package/src/components/text-field.md +0 -770
|
@@ -33,12 +33,12 @@ type ChoiceComponentProps = {|
|
|
|
33
33
|
/**
|
|
34
34
|
* Optional label for the field.
|
|
35
35
|
*/
|
|
36
|
-
label?:
|
|
36
|
+
label?: React.Node,
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* Optional description for the field.
|
|
40
40
|
*/
|
|
41
|
-
description?:
|
|
41
|
+
description?: React.Node,
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* Unique identifier attached to the HTML input element. If used, need to
|
|
@@ -52,10 +52,10 @@ type Props = {|
|
|
|
52
52
|
/**
|
|
53
53
|
* Label for the field.
|
|
54
54
|
*/
|
|
55
|
-
label?:
|
|
55
|
+
label?: React.Node,
|
|
56
56
|
|
|
57
57
|
/** Optional description for the field. */
|
|
58
|
-
description?:
|
|
58
|
+
description?: React.Node,
|
|
59
59
|
|
|
60
60
|
/** Auto-populated by parent's groupName prop if in a group. */
|
|
61
61
|
groupName?: string,
|
|
@@ -142,7 +142,9 @@ type DefaultProps = {|
|
|
|
142
142
|
return (
|
|
143
143
|
<UniqueIDProvider mockOnFirstRender={true} scope="choice">
|
|
144
144
|
{(ids) => {
|
|
145
|
-
const descriptionId = description
|
|
145
|
+
const descriptionId = description
|
|
146
|
+
? ids.get("description")
|
|
147
|
+
: undefined;
|
|
146
148
|
|
|
147
149
|
return (
|
|
148
150
|
<View style={style} className={className}>
|
package/src/components/choice.js
CHANGED
|
@@ -10,10 +10,10 @@ type Props = {|
|
|
|
10
10
|
...AriaProps,
|
|
11
11
|
|
|
12
12
|
/** User-defined. Label for the field. */
|
|
13
|
-
label:
|
|
13
|
+
label: React.Node,
|
|
14
14
|
|
|
15
15
|
/** User-defined. Optional description for the field. */
|
|
16
|
-
description?:
|
|
16
|
+
description?: React.Node,
|
|
17
17
|
|
|
18
18
|
/** User-defined. Should be distinct for each item in the group. */
|
|
19
19
|
value: string,
|
|
@@ -6,11 +6,7 @@ import {View, addStyle, type StyleType} from "@khanacademy/wonder-blocks-core";
|
|
|
6
6
|
import Color from "@khanacademy/wonder-blocks-color";
|
|
7
7
|
import {Strut} from "@khanacademy/wonder-blocks-layout";
|
|
8
8
|
import Spacing from "@khanacademy/wonder-blocks-spacing";
|
|
9
|
-
import {
|
|
10
|
-
type Typography,
|
|
11
|
-
LabelMedium,
|
|
12
|
-
LabelSmall,
|
|
13
|
-
} from "@khanacademy/wonder-blocks-typography";
|
|
9
|
+
import {LabelMedium, LabelSmall} from "@khanacademy/wonder-blocks-typography";
|
|
14
10
|
|
|
15
11
|
type Props = {|
|
|
16
12
|
/**
|
|
@@ -21,12 +17,12 @@ type Props = {|
|
|
|
21
17
|
/**
|
|
22
18
|
* The title for the label element.
|
|
23
19
|
*/
|
|
24
|
-
label:
|
|
20
|
+
label: React.Node,
|
|
25
21
|
|
|
26
22
|
/**
|
|
27
23
|
* The text for the description element.
|
|
28
24
|
*/
|
|
29
|
-
description?:
|
|
25
|
+
description?: React.Node,
|
|
30
26
|
|
|
31
27
|
/**
|
|
32
28
|
* Whether this field is required to continue.
|
|
@@ -36,7 +32,7 @@ type Props = {|
|
|
|
36
32
|
/**
|
|
37
33
|
* The message for the error element.
|
|
38
34
|
*/
|
|
39
|
-
error?:
|
|
35
|
+
error?: React.Node,
|
|
40
36
|
|
|
41
37
|
/**
|
|
42
38
|
* Custom styles for the field heading container.
|
|
@@ -76,19 +72,15 @@ export default class FieldHeading extends React.Component<Props> {
|
|
|
76
72
|
|
|
77
73
|
return (
|
|
78
74
|
<React.Fragment>
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
</LabelMedium>
|
|
89
|
-
) : (
|
|
90
|
-
label
|
|
91
|
-
)}
|
|
75
|
+
<LabelMedium
|
|
76
|
+
style={styles.label}
|
|
77
|
+
tag="label"
|
|
78
|
+
htmlFor={id && `${id}-field`}
|
|
79
|
+
testId={testId && `${testId}-label`}
|
|
80
|
+
>
|
|
81
|
+
{label}
|
|
82
|
+
{required && requiredIcon}
|
|
83
|
+
</LabelMedium>
|
|
92
84
|
<Strut size={Spacing.xxxSmall_4} />
|
|
93
85
|
</React.Fragment>
|
|
94
86
|
);
|
|
@@ -103,16 +95,12 @@ export default class FieldHeading extends React.Component<Props> {
|
|
|
103
95
|
|
|
104
96
|
return (
|
|
105
97
|
<React.Fragment>
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
</LabelSmall>
|
|
113
|
-
) : (
|
|
114
|
-
description
|
|
115
|
-
)}
|
|
98
|
+
<LabelSmall
|
|
99
|
+
style={styles.description}
|
|
100
|
+
testId={testId && `${testId}-description`}
|
|
101
|
+
>
|
|
102
|
+
{description}
|
|
103
|
+
</LabelSmall>
|
|
116
104
|
<Strut size={Spacing.xxxSmall_4} />
|
|
117
105
|
</React.Fragment>
|
|
118
106
|
);
|
|
@@ -128,18 +116,14 @@ export default class FieldHeading extends React.Component<Props> {
|
|
|
128
116
|
return (
|
|
129
117
|
<React.Fragment>
|
|
130
118
|
<Strut size={Spacing.small_12} />
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
</LabelSmall>
|
|
140
|
-
) : (
|
|
141
|
-
error
|
|
142
|
-
)}
|
|
119
|
+
<LabelSmall
|
|
120
|
+
style={styles.error}
|
|
121
|
+
role="alert"
|
|
122
|
+
id={id && `${id}-error`}
|
|
123
|
+
testId={testId && `${testId}-error`}
|
|
124
|
+
>
|
|
125
|
+
{error}
|
|
126
|
+
</LabelSmall>
|
|
143
127
|
</React.Fragment>
|
|
144
128
|
);
|
|
145
129
|
}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
|
|
4
4
|
import {IDProvider, type StyleType} from "@khanacademy/wonder-blocks-core";
|
|
5
|
-
import {type Typography} from "@khanacademy/wonder-blocks-typography";
|
|
6
5
|
|
|
7
6
|
import FieldHeading from "./field-heading.js";
|
|
8
7
|
import TextField, {type TextFieldType} from "./text-field.js";
|
|
@@ -24,12 +23,12 @@ type Props = {|
|
|
|
24
23
|
/**
|
|
25
24
|
* Provide a label for the TextField.
|
|
26
25
|
*/
|
|
27
|
-
label:
|
|
26
|
+
label: React.Node,
|
|
28
27
|
|
|
29
28
|
/**
|
|
30
29
|
* Provide a description for the TextField.
|
|
31
30
|
*/
|
|
32
|
-
description?:
|
|
31
|
+
description?: React.Node,
|
|
33
32
|
|
|
34
33
|
/**
|
|
35
34
|
* The input value.
|
|
@@ -16,7 +16,7 @@ type RadioGroupProps = {|
|
|
|
16
16
|
/**
|
|
17
17
|
* Children should be Choice components.
|
|
18
18
|
*/
|
|
19
|
-
children: Array
|
|
19
|
+
children: Array<?(React.Element<Choice> | false)>,
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Group name for this checkbox or radio group. Should be unique for all
|
|
@@ -28,12 +28,12 @@ type RadioGroupProps = {|
|
|
|
28
28
|
* Optional label for the group. This label is optional to allow for
|
|
29
29
|
* greater flexibility in implementing checkbox and radio groups.
|
|
30
30
|
*/
|
|
31
|
-
label?:
|
|
31
|
+
label?: React.Node,
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Optional description for the group.
|
|
35
35
|
*/
|
|
36
|
-
description?:
|
|
36
|
+
description?: React.Node,
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* Optional error message. If supplied, the group will be displayed in an
|
|
@@ -118,6 +118,8 @@ export default class RadioGroup extends React.Component<RadioGroupProps> {
|
|
|
118
118
|
testId,
|
|
119
119
|
} = this.props;
|
|
120
120
|
|
|
121
|
+
const allChildren = React.Children.toArray(children).filter(Boolean);
|
|
122
|
+
|
|
121
123
|
return (
|
|
122
124
|
<StyledFieldset data-test-id={testId} style={styles.fieldset}>
|
|
123
125
|
{/* We have a View here because fieldset cannot be used with flexbox*/}
|
|
@@ -141,7 +143,7 @@ export default class RadioGroup extends React.Component<RadioGroupProps> {
|
|
|
141
143
|
<Strut size={Spacing.small_12} />
|
|
142
144
|
)}
|
|
143
145
|
|
|
144
|
-
{
|
|
146
|
+
{allChildren.map((child, index) => {
|
|
145
147
|
const {style, value} = child.props;
|
|
146
148
|
const checked = selectedValue === value;
|
|
147
149
|
return (
|
package/src/components/radio.js
CHANGED
|
@@ -33,12 +33,12 @@ type ChoiceComponentProps = {|
|
|
|
33
33
|
/**
|
|
34
34
|
* Optional label for the field.
|
|
35
35
|
*/
|
|
36
|
-
label?:
|
|
36
|
+
label?: React.Node,
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* Optional description for the field.
|
|
40
40
|
*/
|
|
41
|
-
description?:
|
|
41
|
+
description?: React.Node,
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* Unique identifier attached to the HTML input element. If used, need to
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import Checkbox from "./components/checkbox.js";
|
|
3
|
-
import Radio from "./components/radio.js";
|
|
4
3
|
import Choice from "./components/choice.js";
|
|
5
4
|
import CheckboxGroup from "./components/checkbox-group.js";
|
|
6
5
|
import RadioGroup from "./components/radio-group.js";
|
|
@@ -9,7 +8,6 @@ import LabeledTextField from "./components/labeled-text-field.js";
|
|
|
9
8
|
|
|
10
9
|
export {
|
|
11
10
|
Checkbox,
|
|
12
|
-
Radio,
|
|
13
11
|
Choice,
|
|
14
12
|
CheckboxGroup,
|
|
15
13
|
RadioGroup,
|