@khanacademy/wonder-blocks-form 4.3.19 → 4.4.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-form",
3
- "version": "4.3.19",
3
+ "version": "4.4.1",
4
4
  "design": "v1",
5
5
  "description": "Form components for Wonder Blocks.",
6
6
  "main": "dist/index.js",
@@ -16,12 +16,12 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@babel/runtime": "^7.18.6",
19
- "@khanacademy/wonder-blocks-clickable": "^4.0.12",
19
+ "@khanacademy/wonder-blocks-clickable": "^4.0.13",
20
20
  "@khanacademy/wonder-blocks-color": "^3.0.0",
21
21
  "@khanacademy/wonder-blocks-core": "^6.3.1",
22
22
  "@khanacademy/wonder-blocks-icon": "^4.0.1",
23
- "@khanacademy/wonder-blocks-layout": "^2.0.25",
24
- "@khanacademy/wonder-blocks-spacing": "^4.0.1",
23
+ "@khanacademy/wonder-blocks-layout": "^2.0.26",
24
+ "@khanacademy/wonder-blocks-tokens": "^0.2.0",
25
25
  "@khanacademy/wonder-blocks-typography": "^2.1.10"
26
26
  },
27
27
  "peerDependencies": {
@@ -3,7 +3,7 @@ import {render, screen, fireEvent} from "@testing-library/react";
3
3
  import userEvent from "@testing-library/user-event";
4
4
 
5
5
  import {StyleSheet} from "aphrodite";
6
- import Color from "@khanacademy/wonder-blocks-color";
6
+ import {color} from "@khanacademy/wonder-blocks-tokens";
7
7
  import LabeledTextField from "../labeled-text-field";
8
8
 
9
9
  describe("LabeledTextField", () => {
@@ -394,7 +394,7 @@ describe("LabeledTextField", () => {
394
394
 
395
395
  // Assert
396
396
  expect(textField).toHaveStyle({
397
- boxShadow: `0px 0px 0px 1px ${Color.blue}, 0px 0px 0px 2px ${Color.white}`,
397
+ boxShadow: `0px 0px 0px 1px ${color.blue}, 0px 0px 0px 2px ${color.white}`,
398
398
  });
399
399
  });
400
400
 
@@ -105,6 +105,20 @@ describe("TextField", () => {
105
105
  expect(input).toHaveAttribute("type", type);
106
106
  });
107
107
 
108
+ it("name prop is passed to the input element", () => {
109
+ // Arrange
110
+ const name = "some-name";
111
+
112
+ // Act
113
+ render(
114
+ <TextField id={"tf-1"} name={name} value="" onChange={() => {}} />,
115
+ );
116
+
117
+ // Assert
118
+ const input = screen.getByRole("textbox");
119
+ expect(input).toHaveAttribute("name", name);
120
+ });
121
+
108
122
  it("value prop is passed to the input element", () => {
109
123
  // Arrange
110
124
  const value = "Text";
@@ -1,10 +1,10 @@
1
1
  import * as React from "react";
2
2
  import {StyleSheet} from "aphrodite";
3
3
 
4
- import Color, {mix, fade} from "@khanacademy/wonder-blocks-color";
4
+ import {mix} from "@khanacademy/wonder-blocks-color";
5
5
  import {addStyle} from "@khanacademy/wonder-blocks-core";
6
6
  import {PhosphorIcon} from "@khanacademy/wonder-blocks-icon";
7
- import Spacing from "@khanacademy/wonder-blocks-spacing";
7
+ import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
8
8
  import checkIcon from "@phosphor-icons/core/bold/check-bold.svg";
9
9
  import minusIcon from "@phosphor-icons/core/bold/minus-bold.svg";
10
10
 
@@ -26,12 +26,12 @@ function mapCheckedToAriaChecked(value: Checked): AriaChecked {
26
26
  }
27
27
  }
28
28
 
29
- const {blue, red, white, offWhite, offBlack16, offBlack32, offBlack50} = Color;
29
+ const {blue, red, white, offWhite, offBlack16, offBlack32, offBlack50} = color;
30
30
 
31
31
  // The checkbox size
32
- const size = Spacing.medium_16;
32
+ const size = spacing.medium_16;
33
33
  // The check icon size
34
- const checkSize = Spacing.small_12;
34
+ const checkSize = spacing.small_12;
35
35
 
36
36
  const StyledInput = addStyle("input");
37
37
 
@@ -153,10 +153,10 @@ const sharedStyles = StyleSheet.create({
153
153
  },
154
154
  });
155
155
 
156
- const fadedBlue = mix(fade(blue, 0.16), white);
157
- const activeBlue = mix(offBlack32, blue);
158
- const fadedRed = mix(fade(red, 0.08), white);
159
- const activeRed = mix(offBlack32, red);
156
+ const fadedBlue = mix(color.fadedBlue16, white);
157
+ const activeBlue = color.activeBlue;
158
+ const fadedRed = mix(color.fadedRed8, white);
159
+ const activeRed = color.activeRed;
160
160
 
161
161
  const colors = {
162
162
  default: {
@@ -2,7 +2,7 @@ import * as React from "react";
2
2
 
3
3
  import {View, addStyle} from "@khanacademy/wonder-blocks-core";
4
4
  import {Strut} from "@khanacademy/wonder-blocks-layout";
5
- import Spacing from "@khanacademy/wonder-blocks-spacing";
5
+ import {spacing} from "@khanacademy/wonder-blocks-tokens";
6
6
  import {LabelMedium, LabelSmall} from "@khanacademy/wonder-blocks-typography";
7
7
  import type {StyleType} from "@khanacademy/wonder-blocks-core";
8
8
 
@@ -147,7 +147,7 @@ const CheckboxGroup = React.forwardRef(function CheckboxGroup(
147
147
  <LabelSmall style={styles.error}>{errorMessage}</LabelSmall>
148
148
  )}
149
149
  {(label || description || errorMessage) && (
150
- <Strut size={Spacing.small_12} />
150
+ <Strut size={spacing.small_12} />
151
151
  )}
152
152
 
153
153
  {allChildren.map((child, index) => {
@@ -1,10 +1,9 @@
1
1
  import * as React from "react";
2
2
  import {StyleSheet} from "aphrodite";
3
3
 
4
- import Color from "@khanacademy/wonder-blocks-color";
5
4
  import {View, UniqueIDProvider} from "@khanacademy/wonder-blocks-core";
6
5
  import {Strut} from "@khanacademy/wonder-blocks-layout";
7
- import Spacing from "@khanacademy/wonder-blocks-spacing";
6
+ import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
8
7
  import {LabelMedium, LabelSmall} from "@khanacademy/wonder-blocks-typography";
9
8
  import type {AriaProps, StyleType} from "@khanacademy/wonder-blocks-core";
10
9
  import CheckboxCore from "./checkbox-core";
@@ -147,7 +146,7 @@ type Props = AriaProps & {
147
146
  error={error}
148
147
  ref={ref}
149
148
  />
150
- <Strut size={Spacing.xSmall_8} />
149
+ <Strut size={spacing.xSmall_8} />
151
150
  {label && getLabel(uniqueId)}
152
151
  </View>
153
152
  {description && getDescription(descriptionId)}
@@ -172,13 +171,13 @@ const styles = StyleSheet.create({
172
171
  marginTop: -2,
173
172
  },
174
173
  disabledLabel: {
175
- color: Color.offBlack32,
174
+ color: color.offBlack32,
176
175
  },
177
176
  description: {
178
177
  // 16 for icon + 8 for spacing strut
179
- marginLeft: Spacing.medium_16 + Spacing.xSmall_8,
180
- marginTop: Spacing.xxxSmall_4,
181
- color: Color.offBlack64,
178
+ marginLeft: spacing.medium_16 + spacing.xSmall_8,
179
+ marginTop: spacing.xxxSmall_4,
180
+ color: color.offBlack64,
182
181
  },
183
182
  });
184
183
 
@@ -2,9 +2,8 @@ import * as React from "react";
2
2
  import {StyleSheet} from "aphrodite";
3
3
 
4
4
  import {View, addStyle, StyleType} from "@khanacademy/wonder-blocks-core";
5
- import Color from "@khanacademy/wonder-blocks-color";
6
5
  import {Strut} from "@khanacademy/wonder-blocks-layout";
7
- import Spacing from "@khanacademy/wonder-blocks-spacing";
6
+ import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
8
7
  import {LabelMedium, LabelSmall} from "@khanacademy/wonder-blocks-typography";
9
8
 
10
9
  type Props = {
@@ -73,7 +72,7 @@ export default class FieldHeading extends React.Component<Props> {
73
72
  {label}
74
73
  {required && requiredIcon}
75
74
  </LabelMedium>
76
- <Strut size={Spacing.xxxSmall_4} />
75
+ <Strut size={spacing.xxxSmall_4} />
77
76
  </React.Fragment>
78
77
  );
79
78
  }
@@ -93,7 +92,7 @@ export default class FieldHeading extends React.Component<Props> {
93
92
  >
94
93
  {description}
95
94
  </LabelSmall>
96
- <Strut size={Spacing.xxxSmall_4} />
95
+ <Strut size={spacing.xxxSmall_4} />
97
96
  </React.Fragment>
98
97
  );
99
98
  }
@@ -107,7 +106,7 @@ export default class FieldHeading extends React.Component<Props> {
107
106
 
108
107
  return (
109
108
  <React.Fragment>
110
- <Strut size={Spacing.small_12} />
109
+ <Strut size={spacing.small_12} />
111
110
  <LabelSmall
112
111
  style={styles.error}
113
112
  role="alert"
@@ -127,7 +126,7 @@ export default class FieldHeading extends React.Component<Props> {
127
126
  <View style={style}>
128
127
  {this.renderLabel()}
129
128
  {this.maybeRenderDescription()}
130
- <Strut size={Spacing.xSmall_8} />
129
+ <Strut size={spacing.xSmall_8} />
131
130
  {field}
132
131
  {this.maybeRenderError()}
133
132
  </View>
@@ -137,15 +136,15 @@ export default class FieldHeading extends React.Component<Props> {
137
136
 
138
137
  const styles = StyleSheet.create({
139
138
  label: {
140
- color: Color.offBlack,
139
+ color: color.offBlack,
141
140
  },
142
141
  description: {
143
- color: Color.offBlack64,
142
+ color: color.offBlack64,
144
143
  },
145
144
  error: {
146
- color: Color.red,
145
+ color: color.red,
147
146
  },
148
147
  required: {
149
- color: Color.red,
148
+ color: color.red,
150
149
  },
151
150
  });
@@ -1,7 +1,6 @@
1
1
  import {StyleSheet} from "aphrodite";
2
2
 
3
- import Color from "@khanacademy/wonder-blocks-color";
4
- import Spacing from "@khanacademy/wonder-blocks-spacing";
3
+ import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
5
4
 
6
5
  import type {StyleDeclaration} from "aphrodite";
7
6
 
@@ -17,17 +16,17 @@ const styles: StyleDeclaration = StyleSheet.create({
17
16
  },
18
17
 
19
18
  description: {
20
- marginTop: Spacing.xxxSmall_4,
21
- color: Color.offBlack64,
19
+ marginTop: spacing.xxxSmall_4,
20
+ color: color.offBlack64,
22
21
  },
23
22
 
24
23
  error: {
25
- marginTop: Spacing.xxxSmall_4,
26
- color: Color.red,
24
+ marginTop: spacing.xxxSmall_4,
25
+ color: color.red,
27
26
  },
28
27
 
29
28
  defaultLineGap: {
30
- marginTop: Spacing.xSmall_8,
29
+ marginTop: spacing.xSmall_8,
31
30
  },
32
31
  });
33
32
 
@@ -1,12 +1,13 @@
1
1
  import * as React from "react";
2
2
  import {StyleSheet} from "aphrodite";
3
3
 
4
- import Color, {mix, fade} from "@khanacademy/wonder-blocks-color";
4
+ import {mix} from "@khanacademy/wonder-blocks-color";
5
+ import {color} from "@khanacademy/wonder-blocks-tokens";
5
6
  import {addStyle} from "@khanacademy/wonder-blocks-core";
6
7
 
7
8
  import type {ChoiceCoreProps, Checked} from "../util/types";
8
9
 
9
- const {blue, red, white, offWhite, offBlack16, offBlack32, offBlack50} = Color;
10
+ const {blue, red, white, offWhite, offBlack16, offBlack32, offBlack50} = color;
10
11
 
11
12
  const StyledInput = addStyle("input");
12
13
 
@@ -90,20 +91,18 @@ const sharedStyles = StyleSheet.create({
90
91
  borderWidth: 1,
91
92
  },
92
93
  });
93
- const fadedBlue = mix(fade(blue, 0.16), white);
94
- const activeBlue = mix(offBlack32, blue);
95
- const fadedRed = mix(fade(red, 0.08), white);
96
- const activeRed = mix(offBlack32, red);
94
+ const fadedBlue = mix(color.fadedBlue16, white);
95
+ const fadedRed = mix(color.fadedRed8, white);
97
96
  const colors = {
98
97
  default: {
99
98
  faded: fadedBlue,
100
99
  base: blue,
101
- active: activeBlue,
100
+ active: color.activeBlue,
102
101
  },
103
102
  error: {
104
103
  faded: fadedRed,
105
104
  base: red,
106
- active: activeRed,
105
+ active: color.activeRed,
107
106
  },
108
107
  } as const;
109
108
  const styles: Record<string, any> = {};
@@ -160,7 +159,7 @@ const _generateStyles = (checked: Checked, error: boolean) => {
160
159
 
161
160
  ":active": {
162
161
  backgroundColor: palette.faded,
163
- borderColor: error ? activeRed : blue,
162
+ borderColor: error ? color.activeRed : blue,
164
163
  borderWidth: 2,
165
164
  },
166
165
  },
@@ -2,7 +2,7 @@ import * as React from "react";
2
2
 
3
3
  import {View, addStyle} from "@khanacademy/wonder-blocks-core";
4
4
  import {Strut} from "@khanacademy/wonder-blocks-layout";
5
- import Spacing from "@khanacademy/wonder-blocks-spacing";
5
+ import {spacing} from "@khanacademy/wonder-blocks-tokens";
6
6
  import {LabelMedium, LabelSmall} from "@khanacademy/wonder-blocks-typography";
7
7
  import type {StyleType} from "@khanacademy/wonder-blocks-core";
8
8
 
@@ -132,7 +132,7 @@ const RadioGroup = React.forwardRef(function RadioGroup(
132
132
  <LabelSmall style={styles.error}>{errorMessage}</LabelSmall>
133
133
  )}
134
134
  {(label || description || errorMessage) && (
135
- <Strut size={Spacing.small_12} />
135
+ <Strut size={spacing.small_12} />
136
136
  )}
137
137
 
138
138
  {allChildren.map((child, index) => {
@@ -1,9 +1,9 @@
1
1
  import * as React from "react";
2
2
  import {StyleSheet} from "aphrodite";
3
3
 
4
- import Color, {mix, fade} from "@khanacademy/wonder-blocks-color";
4
+ import {mix} from "@khanacademy/wonder-blocks-color";
5
5
  import {addStyle} from "@khanacademy/wonder-blocks-core";
6
- import Spacing from "@khanacademy/wonder-blocks-spacing";
6
+ import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
7
7
  import {styles as typographyStyles} from "@khanacademy/wonder-blocks-typography";
8
8
 
9
9
  import type {StyleType, AriaProps} from "@khanacademy/wonder-blocks-core";
@@ -31,6 +31,11 @@ type Props = AriaProps & {
31
31
  * The input value.
32
32
  */
33
33
  value: string;
34
+ /**
35
+ * The name for the input control. This is submitted along with
36
+ * the form data.
37
+ */
38
+ name?: string;
34
39
  /**
35
40
  * Makes a read-only input field that cannot be focused. Defaults to false.
36
41
  */
@@ -219,6 +224,7 @@ class TextField extends React.Component<PropsWithForwardRef, State> {
219
224
  id,
220
225
  type,
221
226
  value,
227
+ name,
222
228
  disabled,
223
229
  onKeyDown,
224
230
  placeholder,
@@ -267,6 +273,7 @@ class TextField extends React.Component<PropsWithForwardRef, State> {
267
273
  type={type}
268
274
  placeholder={placeholder}
269
275
  value={value}
276
+ name={name}
270
277
  disabled={disabled}
271
278
  onChange={this.handleChange}
272
279
  onKeyDown={onKeyDown}
@@ -289,48 +296,48 @@ const styles = StyleSheet.create({
289
296
  height: 40,
290
297
  borderRadius: 4,
291
298
  boxSizing: "border-box",
292
- paddingLeft: Spacing.medium_16,
299
+ paddingLeft: spacing.medium_16,
293
300
  margin: 0,
294
301
  outline: "none",
295
302
  boxShadow: "none",
296
303
  },
297
304
  default: {
298
- background: Color.white,
299
- border: `1px solid ${Color.offBlack16}`,
300
- color: Color.offBlack,
305
+ background: color.white,
306
+ border: `1px solid ${color.offBlack16}`,
307
+ color: color.offBlack,
301
308
  "::placeholder": {
302
- color: Color.offBlack64,
309
+ color: color.offBlack64,
303
310
  },
304
311
  },
305
312
  error: {
306
- background: `${mix(fade(Color.red, 0.06), Color.white)}`,
307
- border: `1px solid ${Color.red}`,
308
- color: Color.offBlack,
313
+ background: `${mix(color.fadedRed8, color.white)}`,
314
+ border: `1px solid ${color.red}`,
315
+ color: color.offBlack,
309
316
  "::placeholder": {
310
- color: Color.offBlack64,
317
+ color: color.offBlack64,
311
318
  },
312
319
  },
313
320
  disabled: {
314
- background: Color.offWhite,
315
- border: `1px solid ${Color.offBlack16}`,
316
- color: Color.offBlack64,
321
+ background: color.offWhite,
322
+ border: `1px solid ${color.offBlack16}`,
323
+ color: color.offBlack64,
317
324
  "::placeholder": {
318
- color: Color.offBlack32,
325
+ color: color.offBlack32,
319
326
  },
320
327
  },
321
328
  focused: {
322
- background: Color.white,
323
- border: `1px solid ${Color.blue}`,
324
- color: Color.offBlack,
329
+ background: color.white,
330
+ border: `1px solid ${color.blue}`,
331
+ color: color.offBlack,
325
332
  "::placeholder": {
326
- color: Color.offBlack64,
333
+ color: color.offBlack64,
327
334
  },
328
335
  },
329
336
  defaultLight: {
330
- boxShadow: `0px 0px 0px 1px ${Color.blue}, 0px 0px 0px 2px ${Color.white}`,
337
+ boxShadow: `0px 0px 0px 1px ${color.blue}, 0px 0px 0px 2px ${color.white}`,
331
338
  },
332
339
  errorLight: {
333
- boxShadow: `0px 0px 0px 1px ${Color.red}, 0px 0px 0px 2px ${Color.white}`,
340
+ boxShadow: `0px 0px 0px 1px ${color.red}, 0px 0px 0px 2px ${color.white}`,
334
341
  },
335
342
  });
336
343
 
@@ -14,7 +14,7 @@
14
14
  {"path": "../wonder-blocks-icon/tsconfig-build.json"},
15
15
  {"path": "../wonder-blocks-layout/tsconfig-build.json"},
16
16
  {"path": "../wonder-blocks-link/tsconfig-build.json"},
17
- {"path": "../wonder-blocks-spacing/tsconfig-build.json"},
17
+ {"path": "../wonder-blocks-tokens/tsconfig-build.json"},
18
18
  {"path": "../wonder-blocks-typography/tsconfig-build.json"},
19
19
  ]
20
20
  }