@khanacademy/wonder-blocks-form 3.1.11 → 3.1.12
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 +30 -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
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { AriaProps, StyleType } from "@khanacademy/wonder-blocks-core";
|
|
3
|
+
import Checkbox from "./checkbox";
|
|
4
|
+
import Radio from "./radio";
|
|
5
|
+
type Props = AriaProps & {
|
|
6
|
+
/** User-defined. Label for the field. */
|
|
7
|
+
label: React.ReactNode;
|
|
8
|
+
/** User-defined. Optional description for the field. */
|
|
9
|
+
description?: React.ReactNode;
|
|
10
|
+
/** User-defined. Should be distinct for each item in the group. */
|
|
11
|
+
value: string;
|
|
12
|
+
/** User-defined. Whether this choice option is disabled. Default false. */
|
|
13
|
+
disabled: boolean;
|
|
14
|
+
/** User-defined. Optional id for testing purposes. */
|
|
15
|
+
testId?: string;
|
|
16
|
+
/** User-defined. Optional additional styling. */
|
|
17
|
+
style?: StyleType;
|
|
18
|
+
/**
|
|
19
|
+
* Auto-populated by parent. Whether this choice is checked.
|
|
20
|
+
* @ignore
|
|
21
|
+
*/
|
|
22
|
+
checked: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Auto-populated by parent. Whether this choice is in error mode (everything
|
|
25
|
+
* in a choice group would be in error mode at the same time).
|
|
26
|
+
* @ignore
|
|
27
|
+
*/
|
|
28
|
+
error?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Auto-populated by parent. Used for accessibility purposes, where the label
|
|
31
|
+
* id should match the input id.
|
|
32
|
+
* @ignore
|
|
33
|
+
*/
|
|
34
|
+
id?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Auto-populated by parent's groupName prop.
|
|
37
|
+
* @ignore
|
|
38
|
+
*/
|
|
39
|
+
groupName?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Auto-populated by parent. Returns the new checked state of the component.
|
|
42
|
+
* @ignore
|
|
43
|
+
*/
|
|
44
|
+
onChange: (newCheckedState: boolean) => unknown;
|
|
45
|
+
/**
|
|
46
|
+
* Auto-populated by parent.
|
|
47
|
+
* @ignore
|
|
48
|
+
*/
|
|
49
|
+
variant?: "radio" | "checkbox";
|
|
50
|
+
};
|
|
51
|
+
type DefaultProps = {
|
|
52
|
+
checked: Props["checked"];
|
|
53
|
+
disabled: Props["disabled"];
|
|
54
|
+
onChange: Props["onChange"];
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* This is a labeled 🔘 or ☑️ item. Choice is meant to be used as children of
|
|
58
|
+
* CheckboxGroup and RadioGroup because many of its props are auto-populated
|
|
59
|
+
* and not shown in the documentation here. See those components for usage
|
|
60
|
+
* examples.
|
|
61
|
+
*
|
|
62
|
+
* If you wish to use just a single field, use Checkbox or Radio with the
|
|
63
|
+
* optional label and description props.
|
|
64
|
+
*
|
|
65
|
+
* ### Checkbox Usage
|
|
66
|
+
*
|
|
67
|
+
* ```jsx
|
|
68
|
+
* import {Choice, CheckboxGroup} from "@khanacademy/wonder-blocks-form";
|
|
69
|
+
*
|
|
70
|
+
* const [selectedValues, setSelectedValues] = React.useState([]);
|
|
71
|
+
*
|
|
72
|
+
* // Checkbox usage
|
|
73
|
+
* <CheckboxGroup
|
|
74
|
+
* label="some-label"
|
|
75
|
+
* description="some-description"
|
|
76
|
+
* groupName="some-group-name"
|
|
77
|
+
* onChange={setSelectedValues}
|
|
78
|
+
* selectedValues={selectedValues}
|
|
79
|
+
* />
|
|
80
|
+
* // Add as many choices as necessary
|
|
81
|
+
* <Choice
|
|
82
|
+
* label="Choice 1"
|
|
83
|
+
* value="some-choice-value"
|
|
84
|
+
* description="Some choice description."
|
|
85
|
+
* />
|
|
86
|
+
* <Choice
|
|
87
|
+
* label="Choice 2"
|
|
88
|
+
* value="some-choice-value-2"
|
|
89
|
+
* description="Some choice description."
|
|
90
|
+
* />
|
|
91
|
+
* </CheckboxGroup>
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* ### Radio Usage
|
|
95
|
+
*
|
|
96
|
+
* ```jsx
|
|
97
|
+
* import {Choice, RadioGroup} from "@khanacademy/wonder-blocks-form";
|
|
98
|
+
*
|
|
99
|
+
* const [selectedValue, setSelectedValue] = React.useState("");
|
|
100
|
+
*
|
|
101
|
+
* <RadioGroup
|
|
102
|
+
* label="some-label"
|
|
103
|
+
* description="some-description"
|
|
104
|
+
* groupName="some-group-name"
|
|
105
|
+
* onChange={setSelectedValue}>
|
|
106
|
+
* selectedValues={selectedValue}
|
|
107
|
+
* />
|
|
108
|
+
* // Add as many choices as necessary
|
|
109
|
+
* <Choice
|
|
110
|
+
* label="Choice 1"
|
|
111
|
+
* value="some-choice-value"
|
|
112
|
+
* description="Some choice description."
|
|
113
|
+
* />
|
|
114
|
+
* <Choice
|
|
115
|
+
* label="Choice 2"
|
|
116
|
+
* value="some-choice-value-2"
|
|
117
|
+
* description="Some choice description."
|
|
118
|
+
* />
|
|
119
|
+
* </RadioGroup>
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export default class Choice extends React.Component<Props> {
|
|
123
|
+
static defaultProps: DefaultProps;
|
|
124
|
+
getChoiceComponent(variant?: string | null): typeof Radio | typeof Checkbox;
|
|
125
|
+
render(): React.ReactElement;
|
|
126
|
+
}
|
|
127
|
+
export {};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for choice
|
|
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 Checkbox from "./checkbox";
|
|
11
|
+
import Radio from "./radio";
|
|
12
|
+
declare type Props = {
|
|
13
|
+
...AriaProps,
|
|
14
|
+
...{
|
|
15
|
+
/**
|
|
16
|
+
* User-defined. Label for the field.
|
|
17
|
+
*/
|
|
18
|
+
label: React.Node,
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* User-defined. Optional description for the field.
|
|
22
|
+
*/
|
|
23
|
+
description?: React.Node,
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* User-defined. Should be distinct for each item in the group.
|
|
27
|
+
*/
|
|
28
|
+
value: string,
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* User-defined. Whether this choice option is disabled. Default false.
|
|
32
|
+
*/
|
|
33
|
+
disabled: boolean,
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* User-defined. Optional id for testing purposes.
|
|
37
|
+
*/
|
|
38
|
+
testId?: string,
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* User-defined. Optional additional styling.
|
|
42
|
+
*/
|
|
43
|
+
style?: StyleType,
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Auto-populated by parent. Whether this choice is checked.
|
|
47
|
+
* @ignore
|
|
48
|
+
*/
|
|
49
|
+
checked: boolean,
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Auto-populated by parent. Whether this choice is in error mode (everything
|
|
53
|
+
* in a choice group would be in error mode at the same time).
|
|
54
|
+
* @ignore
|
|
55
|
+
*/
|
|
56
|
+
error?: boolean,
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Auto-populated by parent. Used for accessibility purposes, where the label
|
|
60
|
+
* id should match the input id.
|
|
61
|
+
* @ignore
|
|
62
|
+
*/
|
|
63
|
+
id?: string,
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Auto-populated by parent's groupName prop.
|
|
67
|
+
* @ignore
|
|
68
|
+
*/
|
|
69
|
+
groupName?: string,
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Auto-populated by parent. Returns the new checked state of the component.
|
|
73
|
+
* @ignore
|
|
74
|
+
*/
|
|
75
|
+
onChange: (newCheckedState: boolean) => mixed,
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Auto-populated by parent.
|
|
79
|
+
* @ignore
|
|
80
|
+
*/
|
|
81
|
+
variant?: "radio" | "checkbox",
|
|
82
|
+
...
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
declare type DefaultProps = {
|
|
86
|
+
checked: $PropertyType<Props, "checked">,
|
|
87
|
+
disabled: $PropertyType<Props, "disabled">,
|
|
88
|
+
onChange: $PropertyType<Props, "onChange">,
|
|
89
|
+
...
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* This is a labeled 🔘 or ☑️ item. Choice is meant to be used as children of
|
|
93
|
+
* CheckboxGroup and RadioGroup because many of its props are auto-populated
|
|
94
|
+
* and not shown in the documentation here. See those components for usage
|
|
95
|
+
* examples.
|
|
96
|
+
*
|
|
97
|
+
* If you wish to use just a single field, use Checkbox or Radio with the
|
|
98
|
+
* optional label and description props.
|
|
99
|
+
*
|
|
100
|
+
* ### Checkbox Usage
|
|
101
|
+
*
|
|
102
|
+
* ```jsx
|
|
103
|
+
* import {Choice, CheckboxGroup} from "@khanacademy/wonder-blocks-form";
|
|
104
|
+
*
|
|
105
|
+
* const [selectedValues, setSelectedValues] = React.useState([]);
|
|
106
|
+
*
|
|
107
|
+
* // Checkbox usage
|
|
108
|
+
* <CheckboxGroup
|
|
109
|
+
* label="some-label"
|
|
110
|
+
* description="some-description"
|
|
111
|
+
* groupName="some-group-name"
|
|
112
|
+
* onChange={setSelectedValues}
|
|
113
|
+
* selectedValues={selectedValues}
|
|
114
|
+
* />
|
|
115
|
+
* // Add as many choices as necessary
|
|
116
|
+
* <Choice
|
|
117
|
+
* label="Choice 1"
|
|
118
|
+
* value="some-choice-value"
|
|
119
|
+
* description="Some choice description."
|
|
120
|
+
* />
|
|
121
|
+
* <Choice
|
|
122
|
+
* label="Choice 2"
|
|
123
|
+
* value="some-choice-value-2"
|
|
124
|
+
* description="Some choice description."
|
|
125
|
+
* />
|
|
126
|
+
* </CheckboxGroup>
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* ### Radio Usage
|
|
130
|
+
*
|
|
131
|
+
* ```jsx
|
|
132
|
+
* import {Choice, RadioGroup} from "@khanacademy/wonder-blocks-form";
|
|
133
|
+
*
|
|
134
|
+
* const [selectedValue, setSelectedValue] = React.useState("");
|
|
135
|
+
*
|
|
136
|
+
* <RadioGroup
|
|
137
|
+
* label="some-label"
|
|
138
|
+
* description="some-description"
|
|
139
|
+
* groupName="some-group-name"
|
|
140
|
+
* onChange={setSelectedValue}>
|
|
141
|
+
* selectedValues={selectedValue}
|
|
142
|
+
* />
|
|
143
|
+
* // Add as many choices as necessary
|
|
144
|
+
* <Choice
|
|
145
|
+
* label="Choice 1"
|
|
146
|
+
* value="some-choice-value"
|
|
147
|
+
* description="Some choice description."
|
|
148
|
+
* />
|
|
149
|
+
* <Choice
|
|
150
|
+
* label="Choice 2"
|
|
151
|
+
* value="some-choice-value-2"
|
|
152
|
+
* description="Some choice description."
|
|
153
|
+
* />
|
|
154
|
+
* </RadioGroup>
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
declare export default class Choice mixins React.Component<Props> {
|
|
158
|
+
static defaultProps: DefaultProps;
|
|
159
|
+
getChoiceComponent(variant?: string | null): typeof Radio | typeof Checkbox;
|
|
160
|
+
render(): React.Element<>;
|
|
161
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { StyleType } from "@khanacademy/wonder-blocks-core";
|
|
3
|
+
type Props = {
|
|
4
|
+
/**
|
|
5
|
+
* The form field component.
|
|
6
|
+
*/
|
|
7
|
+
field: React.ReactNode;
|
|
8
|
+
/**
|
|
9
|
+
* The title for the label element.
|
|
10
|
+
*/
|
|
11
|
+
label: React.ReactNode;
|
|
12
|
+
/**
|
|
13
|
+
* The text for the description element.
|
|
14
|
+
*/
|
|
15
|
+
description?: React.ReactNode;
|
|
16
|
+
/**
|
|
17
|
+
* Whether this field is required to continue.
|
|
18
|
+
*/
|
|
19
|
+
required?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The message for the error element.
|
|
22
|
+
*/
|
|
23
|
+
error?: React.ReactNode;
|
|
24
|
+
/**
|
|
25
|
+
* Custom styles for the field heading container.
|
|
26
|
+
*/
|
|
27
|
+
style?: StyleType;
|
|
28
|
+
/**
|
|
29
|
+
* A unique id to link the label (and optional error) to the field.
|
|
30
|
+
*
|
|
31
|
+
* The label will assume that the field will have its id formatted as `${id}-field`.
|
|
32
|
+
* The field can assume that the error will have its id formatted as `${id}-error`.
|
|
33
|
+
*/
|
|
34
|
+
id?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Optional test ID for e2e testing.
|
|
37
|
+
*/
|
|
38
|
+
testId?: string;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* A FieldHeading is an element that provides a label, description, and error element
|
|
42
|
+
* to present better context and hints to any type of form field component.
|
|
43
|
+
*/
|
|
44
|
+
export default class FieldHeading extends React.Component<Props> {
|
|
45
|
+
renderLabel(): React.ReactNode;
|
|
46
|
+
maybeRenderDescription(): React.ReactNode | null | undefined;
|
|
47
|
+
maybeRenderError(): React.ReactNode | null | undefined;
|
|
48
|
+
render(): React.ReactElement;
|
|
49
|
+
}
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for field-heading
|
|
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 { StyleType } from "@khanacademy/wonder-blocks-core";
|
|
10
|
+
declare type Props = {
|
|
11
|
+
/**
|
|
12
|
+
* The form field component.
|
|
13
|
+
*/
|
|
14
|
+
field: React.Node,
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The title for the label element.
|
|
18
|
+
*/
|
|
19
|
+
label: React.Node,
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The text for the description element.
|
|
23
|
+
*/
|
|
24
|
+
description?: React.Node,
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Whether this field is required to continue.
|
|
28
|
+
*/
|
|
29
|
+
required?: boolean,
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The message for the error element.
|
|
33
|
+
*/
|
|
34
|
+
error?: React.Node,
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Custom styles for the field heading container.
|
|
38
|
+
*/
|
|
39
|
+
style?: StyleType,
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A unique id to link the label (and optional error) to the field.
|
|
43
|
+
*
|
|
44
|
+
* The label will assume that the field will have its id formatted as `${id}-field`.
|
|
45
|
+
* The field can assume that the error will have its id formatted as `${id}-error`.
|
|
46
|
+
*/
|
|
47
|
+
id?: string,
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Optional test ID for e2e testing.
|
|
51
|
+
*/
|
|
52
|
+
testId?: string,
|
|
53
|
+
...
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* A FieldHeading is an element that provides a label, description, and error element
|
|
57
|
+
* to present better context and hints to any type of form field component.
|
|
58
|
+
*/
|
|
59
|
+
declare export default class FieldHeading mixins React.Component<Props> {
|
|
60
|
+
renderLabel(): React.Node;
|
|
61
|
+
maybeRenderDescription(): React.Node | null | void;
|
|
62
|
+
maybeRenderError(): React.Node | null | void;
|
|
63
|
+
render(): React.Element<>;
|
|
64
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for group-styles
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { StyleDeclaration } from "aphrodite";
|
|
9
|
+
declare var styles: StyleDeclaration;
|
|
10
|
+
declare export default typeof styles;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { StyleType } from "@khanacademy/wonder-blocks-core";
|
|
3
|
+
import { TextFieldType } from "./text-field";
|
|
4
|
+
type WithForwardRef = {
|
|
5
|
+
forwardedRef: React.ForwardedRef<HTMLInputElement>;
|
|
6
|
+
};
|
|
7
|
+
type Props = {
|
|
8
|
+
/**
|
|
9
|
+
* An optional unique identifier for the TextField.
|
|
10
|
+
* If no id is specified, a unique id will be auto-generated.
|
|
11
|
+
*/
|
|
12
|
+
id?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Determines the type of input. Defaults to text.
|
|
15
|
+
*/
|
|
16
|
+
type: TextFieldType;
|
|
17
|
+
/**
|
|
18
|
+
* Provide a label for the TextField.
|
|
19
|
+
*/
|
|
20
|
+
label: React.ReactNode;
|
|
21
|
+
/**
|
|
22
|
+
* Provide a description for the TextField.
|
|
23
|
+
*/
|
|
24
|
+
description?: React.ReactNode;
|
|
25
|
+
/**
|
|
26
|
+
* The input value.
|
|
27
|
+
*/
|
|
28
|
+
value: string;
|
|
29
|
+
/**
|
|
30
|
+
* Makes a read-only input field that cannot be focused. Defaults to false.
|
|
31
|
+
*/
|
|
32
|
+
disabled: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Whether this field is required to to continue, or the error message to
|
|
35
|
+
* render if this field is left blank.
|
|
36
|
+
*
|
|
37
|
+
* This can be a boolean or a string.
|
|
38
|
+
*
|
|
39
|
+
* String:
|
|
40
|
+
* Please pass in a translated string to use as the error message that will
|
|
41
|
+
* render if the user leaves this field blank. If this field is required,
|
|
42
|
+
* and a string is not passed in, a default untranslated string will render
|
|
43
|
+
* upon error.
|
|
44
|
+
* Note: The string will not be used if a `validate` prop is passed in.
|
|
45
|
+
*
|
|
46
|
+
* Example message: i18n._("A password is required to log in.")
|
|
47
|
+
*
|
|
48
|
+
* Boolean:
|
|
49
|
+
* True/false indicating whether this field is required. Please do not pass
|
|
50
|
+
* in `true` if possible - pass in the error string instead.
|
|
51
|
+
* If `true` is passed, and a `validate` prop is not passed, that means
|
|
52
|
+
* there is no corresponding message and the default untranlsated message
|
|
53
|
+
* will be used.
|
|
54
|
+
*/
|
|
55
|
+
required?: boolean | string;
|
|
56
|
+
/**
|
|
57
|
+
* Identifies the element or elements that describes this text field.
|
|
58
|
+
*/
|
|
59
|
+
ariaDescribedby?: string | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Provide a validation for the input value.
|
|
62
|
+
* Return a string error message or null | void for a valid input.
|
|
63
|
+
*/
|
|
64
|
+
validate?: (value: string) => string | null | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Called when the TextField input is validated.
|
|
67
|
+
*/
|
|
68
|
+
onValidate?: (errorMessage?: string | null | undefined) => unknown;
|
|
69
|
+
/**
|
|
70
|
+
* Called when the value has changed.
|
|
71
|
+
*/
|
|
72
|
+
onChange: (newValue: string) => unknown;
|
|
73
|
+
/**
|
|
74
|
+
* Called when a key is pressed.
|
|
75
|
+
*/
|
|
76
|
+
onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => unknown;
|
|
77
|
+
/**
|
|
78
|
+
* Called when the element has been focused.
|
|
79
|
+
*/
|
|
80
|
+
onFocus?: (event: React.FocusEvent<HTMLInputElement>) => unknown;
|
|
81
|
+
/**
|
|
82
|
+
* Called when the element has been blurred.
|
|
83
|
+
*/
|
|
84
|
+
onBlur?: (event: React.FocusEvent<HTMLInputElement>) => unknown;
|
|
85
|
+
/**
|
|
86
|
+
* Provide hints or examples of what to enter.
|
|
87
|
+
*/
|
|
88
|
+
placeholder?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Change the field’s sub-components to fit a dark background.
|
|
91
|
+
*/
|
|
92
|
+
light: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Custom styles for the container.
|
|
95
|
+
*
|
|
96
|
+
* Note: This style is passed to the field heading container
|
|
97
|
+
* due to scenarios where we would like to set a specific
|
|
98
|
+
* width for the text field. If we apply the style directly
|
|
99
|
+
* to the text field, the container would not be affected.
|
|
100
|
+
* For example, setting text field to "width: 50%" would not
|
|
101
|
+
* affect the container since text field is a child of the container.
|
|
102
|
+
* In this case, the container would maintain its width ocuppying
|
|
103
|
+
* unnecessary space when the text field is smaller.
|
|
104
|
+
*/
|
|
105
|
+
style?: StyleType;
|
|
106
|
+
/**
|
|
107
|
+
* Optional test ID for e2e testing.
|
|
108
|
+
*/
|
|
109
|
+
testId?: string;
|
|
110
|
+
/**
|
|
111
|
+
* Specifies if the TextField is read-only.
|
|
112
|
+
*/
|
|
113
|
+
readOnly?: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Specifies if the TextField allows autocomplete.
|
|
116
|
+
*/
|
|
117
|
+
autoComplete?: string;
|
|
118
|
+
};
|
|
119
|
+
type PropsWithForwardRef = Props & WithForwardRef;
|
|
120
|
+
type DefaultProps = {
|
|
121
|
+
type: PropsWithForwardRef["type"];
|
|
122
|
+
disabled: PropsWithForwardRef["disabled"];
|
|
123
|
+
light: PropsWithForwardRef["light"];
|
|
124
|
+
};
|
|
125
|
+
type State = {
|
|
126
|
+
/**
|
|
127
|
+
* Displayed when the validation fails.
|
|
128
|
+
*/
|
|
129
|
+
error: string | null | undefined;
|
|
130
|
+
/**
|
|
131
|
+
* The user focuses on the textfield.
|
|
132
|
+
*/
|
|
133
|
+
focused: boolean;
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* A LabeledTextField is an element used to accept a single line of text
|
|
137
|
+
* from the user paired with a label, description, and error field elements.
|
|
138
|
+
*/
|
|
139
|
+
declare class LabeledTextField extends React.Component<PropsWithForwardRef, State> {
|
|
140
|
+
static defaultProps: DefaultProps;
|
|
141
|
+
constructor(props: PropsWithForwardRef);
|
|
142
|
+
handleValidate: (errorMessage?: string | null | undefined) => unknown;
|
|
143
|
+
handleFocus: (event: React.FocusEvent<HTMLInputElement>) => unknown;
|
|
144
|
+
handleBlur: (event: React.FocusEvent<HTMLInputElement>) => unknown;
|
|
145
|
+
render(): React.ReactElement;
|
|
146
|
+
}
|
|
147
|
+
type ExportProps = Omit<JSX.LibraryManagedAttributes<typeof LabeledTextField, React.ComponentProps<typeof LabeledTextField>>, "forwardedRef">;
|
|
148
|
+
/**
|
|
149
|
+
* A LabeledTextField is an element used to accept a single line of text
|
|
150
|
+
* from the user paired with a label, description, and error field elements.
|
|
151
|
+
*
|
|
152
|
+
* ### Usage
|
|
153
|
+
*
|
|
154
|
+
* ```jsx
|
|
155
|
+
* import {LabeledTextField} from "@khanacademy/wonder-blocks-form";
|
|
156
|
+
*
|
|
157
|
+
* const [value, setValue] = React.useState("");
|
|
158
|
+
*
|
|
159
|
+
* <LabeledTextField
|
|
160
|
+
* label="Label"
|
|
161
|
+
* description="Hello, this is the description for this field"
|
|
162
|
+
* placeholder="Placeholder"
|
|
163
|
+
* value={value}
|
|
164
|
+
* onChange={setValue}
|
|
165
|
+
* />
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
declare const _default: React.ForwardRefExoticComponent<ExportProps & React.RefAttributes<HTMLInputElement>>;
|
|
169
|
+
export default _default;
|