@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.
- package/CHANGELOG.md +41 -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,146 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { StyleType, AriaProps } from "@khanacademy/wonder-blocks-core";
|
|
3
|
+
export type TextFieldType = "text" | "password" | "email" | "number" | "tel";
|
|
4
|
+
type WithForwardRef = {
|
|
5
|
+
forwardedRef: React.ForwardedRef<HTMLInputElement>;
|
|
6
|
+
};
|
|
7
|
+
type Props = AriaProps & {
|
|
8
|
+
/**
|
|
9
|
+
* The unique identifier for the input.
|
|
10
|
+
*/
|
|
11
|
+
id: string;
|
|
12
|
+
/**
|
|
13
|
+
* Determines the type of input. Defaults to text.
|
|
14
|
+
*/
|
|
15
|
+
type: TextFieldType;
|
|
16
|
+
/**
|
|
17
|
+
* The input value.
|
|
18
|
+
*/
|
|
19
|
+
value: string;
|
|
20
|
+
/**
|
|
21
|
+
* Makes a read-only input field that cannot be focused. Defaults to false.
|
|
22
|
+
*/
|
|
23
|
+
disabled: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Provide a validation for the input value.
|
|
26
|
+
* Return a string error message or null | void for a valid input.
|
|
27
|
+
*/
|
|
28
|
+
validate?: (value: string) => string | null | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Called right after the TextField input is validated.
|
|
31
|
+
*/
|
|
32
|
+
onValidate?: (errorMessage?: string | null | undefined) => unknown;
|
|
33
|
+
/**
|
|
34
|
+
* Called when the value has changed.
|
|
35
|
+
*/
|
|
36
|
+
onChange: (newValue: string) => unknown;
|
|
37
|
+
/**
|
|
38
|
+
* Called when a key is pressed.
|
|
39
|
+
*/
|
|
40
|
+
onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => unknown;
|
|
41
|
+
/**
|
|
42
|
+
* Called when the element has been focused.
|
|
43
|
+
*/
|
|
44
|
+
onFocus?: (event: React.FocusEvent<HTMLInputElement>) => unknown;
|
|
45
|
+
/**
|
|
46
|
+
* Called when the element has been blurred.
|
|
47
|
+
*/
|
|
48
|
+
onBlur?: (event: React.FocusEvent<HTMLInputElement>) => unknown;
|
|
49
|
+
/**
|
|
50
|
+
* Provide hints or examples of what to enter.
|
|
51
|
+
*/
|
|
52
|
+
placeholder?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Whether this field is required to to continue, or the error message to
|
|
55
|
+
* render if this field is left blank.
|
|
56
|
+
*
|
|
57
|
+
* This can be a boolean or a string.
|
|
58
|
+
*
|
|
59
|
+
* String:
|
|
60
|
+
* Please pass in a translated string to use as the error message that will
|
|
61
|
+
* render if the user leaves this field blank. If this field is required,
|
|
62
|
+
* and a string is not passed in, a default untranslated string will render
|
|
63
|
+
* upon error.
|
|
64
|
+
* Note: The string will not be used if a `validate` prop is passed in.
|
|
65
|
+
*
|
|
66
|
+
* Example message: i18n._("A password is required to log in.")
|
|
67
|
+
*
|
|
68
|
+
* Boolean:
|
|
69
|
+
* True/false indicating whether this field is required. Please do not pass
|
|
70
|
+
* in `true` if possible - pass in the error string instead.
|
|
71
|
+
* If `true` is passed, and a `validate` prop is not passed, that means
|
|
72
|
+
* there is no corresponding message and the default untranlsated message
|
|
73
|
+
* will be used.
|
|
74
|
+
*/
|
|
75
|
+
required?: boolean | string;
|
|
76
|
+
/**
|
|
77
|
+
* Change the default focus ring color to fit a dark background.
|
|
78
|
+
*/
|
|
79
|
+
light: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Custom styles for the input.
|
|
82
|
+
*/
|
|
83
|
+
style?: StyleType;
|
|
84
|
+
/**
|
|
85
|
+
* Optional test ID for e2e testing.
|
|
86
|
+
*/
|
|
87
|
+
testId?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Specifies if the input field is read-only.
|
|
90
|
+
*/
|
|
91
|
+
readOnly?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Specifies if the input field allows autocomplete.
|
|
94
|
+
*/
|
|
95
|
+
autoComplete?: string;
|
|
96
|
+
};
|
|
97
|
+
type PropsWithForwardRef = Props & WithForwardRef;
|
|
98
|
+
type DefaultProps = {
|
|
99
|
+
type: PropsWithForwardRef["type"];
|
|
100
|
+
disabled: PropsWithForwardRef["disabled"];
|
|
101
|
+
light: PropsWithForwardRef["light"];
|
|
102
|
+
};
|
|
103
|
+
type State = {
|
|
104
|
+
/**
|
|
105
|
+
* Displayed when the validation fails.
|
|
106
|
+
*/
|
|
107
|
+
error: string | null | undefined;
|
|
108
|
+
/**
|
|
109
|
+
* The user focuses on this field.
|
|
110
|
+
*/
|
|
111
|
+
focused: boolean;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* A TextField is an element used to accept a single line of text from the user.
|
|
115
|
+
*/
|
|
116
|
+
declare class TextField extends React.Component<PropsWithForwardRef, State> {
|
|
117
|
+
static defaultProps: DefaultProps;
|
|
118
|
+
constructor(props: PropsWithForwardRef);
|
|
119
|
+
state: State;
|
|
120
|
+
componentDidMount(): void;
|
|
121
|
+
maybeValidate: (newValue: string) => void;
|
|
122
|
+
handleChange: (event: React.ChangeEvent<HTMLInputElement>) => unknown;
|
|
123
|
+
handleFocus: (event: React.FocusEvent<HTMLInputElement>) => unknown;
|
|
124
|
+
handleBlur: (event: React.FocusEvent<HTMLInputElement>) => unknown;
|
|
125
|
+
render(): React.ReactElement;
|
|
126
|
+
}
|
|
127
|
+
type ExportProps = Omit<JSX.LibraryManagedAttributes<typeof TextField, React.ComponentProps<typeof TextField>>, "forwardedRef">;
|
|
128
|
+
/**
|
|
129
|
+
* A TextField is an element used to accept a single line of text from the user.
|
|
130
|
+
*
|
|
131
|
+
* ### Usage
|
|
132
|
+
*
|
|
133
|
+
* ```jsx
|
|
134
|
+
* import {TextField} from "@khanacademy/wonder-blocks-form";
|
|
135
|
+
*
|
|
136
|
+
* const [value, setValue] = React.useState("");
|
|
137
|
+
*
|
|
138
|
+
* <TextField
|
|
139
|
+
* id="some-unique-text-field-id"
|
|
140
|
+
* value={value}
|
|
141
|
+
* onChange={setValue}
|
|
142
|
+
* />
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
declare const _default: React.ForwardRefExoticComponent<ExportProps & React.RefAttributes<HTMLInputElement>>;
|
|
146
|
+
export default _default;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for text-field
|
|
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 { StyleType, AriaProps } from "@khanacademy/wonder-blocks-core";
|
|
10
|
+
export type TextFieldType = "text" | "password" | "email" | "number" | "tel";
|
|
11
|
+
declare type WithForwardRef = {
|
|
12
|
+
forwardedRef: React.ForwardedRef<HTMLInputElement>,
|
|
13
|
+
...
|
|
14
|
+
};
|
|
15
|
+
declare type Props = {
|
|
16
|
+
...AriaProps,
|
|
17
|
+
...{
|
|
18
|
+
/**
|
|
19
|
+
* The unique identifier for the input.
|
|
20
|
+
*/
|
|
21
|
+
id: string,
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Determines the type of input. Defaults to text.
|
|
25
|
+
*/
|
|
26
|
+
type: TextFieldType,
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The input value.
|
|
30
|
+
*/
|
|
31
|
+
value: string,
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Makes a read-only input field that cannot be focused. Defaults to false.
|
|
35
|
+
*/
|
|
36
|
+
disabled: boolean,
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Provide a validation for the input value.
|
|
40
|
+
* Return a string error message or null | void for a valid input.
|
|
41
|
+
*/
|
|
42
|
+
validate?: (value: string) => string | null | void,
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Called right after the TextField input is validated.
|
|
46
|
+
*/
|
|
47
|
+
onValidate?: (errorMessage?: string | null | void) => mixed,
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Called when the value has changed.
|
|
51
|
+
*/
|
|
52
|
+
onChange: (newValue: string) => mixed,
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Called when a key is pressed.
|
|
56
|
+
*/
|
|
57
|
+
onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => mixed,
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Called when the element has been focused.
|
|
61
|
+
*/
|
|
62
|
+
onFocus?: (event: React.FocusEvent<HTMLInputElement>) => mixed,
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Called when the element has been blurred.
|
|
66
|
+
*/
|
|
67
|
+
onBlur?: (event: React.FocusEvent<HTMLInputElement>) => mixed,
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Provide hints or examples of what to enter.
|
|
71
|
+
*/
|
|
72
|
+
placeholder?: string,
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Whether this field is required to to continue, or the error message to
|
|
76
|
+
* render if this field is left blank.
|
|
77
|
+
*
|
|
78
|
+
* This can be a boolean or a string.
|
|
79
|
+
*
|
|
80
|
+
* String:
|
|
81
|
+
* Please pass in a translated string to use as the error message that will
|
|
82
|
+
* render if the user leaves this field blank. If this field is required,
|
|
83
|
+
* and a string is not passed in, a default untranslated string will render
|
|
84
|
+
* upon error.
|
|
85
|
+
* Note: The string will not be used if a `validate` prop is passed in.
|
|
86
|
+
*
|
|
87
|
+
* Example message: i18n._("A password is required to log in.")
|
|
88
|
+
*
|
|
89
|
+
* Boolean:
|
|
90
|
+
* True/false indicating whether this field is required. Please do not pass
|
|
91
|
+
* in `true` if possible - pass in the error string instead.
|
|
92
|
+
* If `true` is passed, and a `validate` prop is not passed, that means
|
|
93
|
+
* there is no corresponding message and the default untranlsated message
|
|
94
|
+
* will be used.
|
|
95
|
+
*/
|
|
96
|
+
required?: boolean | string,
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Change the default focus ring color to fit a dark background.
|
|
100
|
+
*/
|
|
101
|
+
light: boolean,
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Custom styles for the input.
|
|
105
|
+
*/
|
|
106
|
+
style?: StyleType,
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Optional test ID for e2e testing.
|
|
110
|
+
*/
|
|
111
|
+
testId?: string,
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Specifies if the input field is read-only.
|
|
115
|
+
*/
|
|
116
|
+
readOnly?: boolean,
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Specifies if the input field allows autocomplete.
|
|
120
|
+
*/
|
|
121
|
+
autoComplete?: string,
|
|
122
|
+
...
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
declare type PropsWithForwardRef = { ...Props, ...WithForwardRef };
|
|
126
|
+
declare type DefaultProps = {
|
|
127
|
+
type: $PropertyType<PropsWithForwardRef, "type">,
|
|
128
|
+
disabled: $PropertyType<PropsWithForwardRef, "disabled">,
|
|
129
|
+
light: $PropertyType<PropsWithForwardRef, "light">,
|
|
130
|
+
...
|
|
131
|
+
};
|
|
132
|
+
declare type State = {
|
|
133
|
+
/**
|
|
134
|
+
* Displayed when the validation fails.
|
|
135
|
+
*/
|
|
136
|
+
error: string | null | void,
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The user focuses on this field.
|
|
140
|
+
*/
|
|
141
|
+
focused: boolean,
|
|
142
|
+
...
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* A TextField is an element used to accept a single line of text from the user.
|
|
146
|
+
*/
|
|
147
|
+
declare class TextField extends React.Component<PropsWithForwardRef, State> {
|
|
148
|
+
static defaultProps: DefaultProps;
|
|
149
|
+
constructor(props: PropsWithForwardRef): this;
|
|
150
|
+
state: State;
|
|
151
|
+
componentDidMount(): void;
|
|
152
|
+
maybeValidate: (newValue: string) => void;
|
|
153
|
+
handleChange: (event: React.ChangeEvent<HTMLInputElement>) => mixed;
|
|
154
|
+
handleFocus: (event: React.FocusEvent<HTMLInputElement>) => mixed;
|
|
155
|
+
handleBlur: (event: React.FocusEvent<HTMLInputElement>) => mixed;
|
|
156
|
+
render(): React.Element<>;
|
|
157
|
+
}
|
|
158
|
+
declare type ExportProps = $Diff<
|
|
159
|
+
JSX.LibraryManagedAttributes<
|
|
160
|
+
typeof TextField,
|
|
161
|
+
React.ComponentProps<typeof TextField>
|
|
162
|
+
>,
|
|
163
|
+
{ forwardedRef: any }
|
|
164
|
+
>;
|
|
165
|
+
/**
|
|
166
|
+
* A TextField is an element used to accept a single line of text from the user.
|
|
167
|
+
*
|
|
168
|
+
* ### Usage
|
|
169
|
+
*
|
|
170
|
+
* ```jsx
|
|
171
|
+
* import {TextField} from "@khanacademy/wonder-blocks-form";
|
|
172
|
+
*
|
|
173
|
+
* const [value, setValue] = React.useState("");
|
|
174
|
+
*
|
|
175
|
+
* <TextField
|
|
176
|
+
* id="some-unique-text-field-id"
|
|
177
|
+
* value={value}
|
|
178
|
+
* onChange={setValue}
|
|
179
|
+
* />
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
declare var _default: React.ForwardRefExoticComponent<{
|
|
183
|
+
...ExportProps,
|
|
184
|
+
...React.RefAttributes<HTMLInputElement>,
|
|
185
|
+
}>;
|
|
186
|
+
declare export default typeof _default;
|