@khanacademy/wonder-blocks-form 2.3.0 → 2.4.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 +24 -0
- package/dist/es/index.js +216 -190
- package/dist/index.js +33 -7
- package/package.json +11 -12
- package/src/components/__tests__/checkbox-group.test.js +1 -0
- package/src/components/__tests__/field-heading.test.js +1 -0
- package/src/components/__tests__/labeled-text-field.test.js +140 -0
- package/src/components/__tests__/radio-group.test.js +1 -0
- package/src/components/__tests__/text-field.test.js +1 -18
- package/src/components/checkbox-core.js +1 -2
- package/src/components/field-heading.js +20 -2
- package/src/components/labeled-text-field.js +32 -6
- package/src/components/labeled-text-field.stories.js +98 -12
- package/src/components/text-field.js +43 -13
- package/src/components/text-field.stories.js +45 -18
- package/LICENSE +0 -21
package/dist/es/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _extends from '@babel/runtime/helpers/extends';
|
|
2
|
-
import
|
|
2
|
+
import * as React from 'react';
|
|
3
3
|
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose';
|
|
4
4
|
import { StyleSheet, css } from 'aphrodite';
|
|
5
5
|
import Color, { mix, fade } from '@khanacademy/wonder-blocks-color';
|
|
@@ -10,17 +10,17 @@ import Spacing from '@khanacademy/wonder-blocks-spacing';
|
|
|
10
10
|
import { LabelMedium, LabelSmall, styles as styles$6 } from '@khanacademy/wonder-blocks-typography';
|
|
11
11
|
import Icon from '@khanacademy/wonder-blocks-icon';
|
|
12
12
|
|
|
13
|
-
const _excluded = ["checked", "disabled", "error", "groupName", "id", "testId", "hovered", "focused", "pressed", "waiting"];
|
|
13
|
+
const _excluded$4 = ["checked", "disabled", "error", "groupName", "id", "testId", "hovered", "focused", "pressed", "waiting"];
|
|
14
14
|
const {
|
|
15
|
-
blue,
|
|
16
|
-
red,
|
|
17
|
-
white,
|
|
18
|
-
offWhite,
|
|
19
|
-
offBlack16,
|
|
20
|
-
offBlack32,
|
|
21
|
-
offBlack50
|
|
15
|
+
blue: blue$1,
|
|
16
|
+
red: red$1,
|
|
17
|
+
white: white$1,
|
|
18
|
+
offWhite: offWhite$1,
|
|
19
|
+
offBlack16: offBlack16$1,
|
|
20
|
+
offBlack32: offBlack32$1,
|
|
21
|
+
offBlack50: offBlack50$1
|
|
22
22
|
} = Color;
|
|
23
|
-
const StyledInput = addStyle("input");
|
|
23
|
+
const StyledInput$1 = addStyle("input");
|
|
24
24
|
const checkboxCheck = {
|
|
25
25
|
small: "M11.263 4.324a1 1 0 1 1 1.474 1.352l-5.5 6a1 1 0 0 1-1.505-.036l-2.5-3a1 1 0 1 1 1.536-1.28L6.536 9.48l4.727-5.157z"
|
|
26
26
|
};
|
|
@@ -28,7 +28,7 @@ const checkboxCheck = {
|
|
|
28
28
|
* The internal stateless ☑️ Checkbox
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
|
-
class CheckboxCore extends Component {
|
|
31
|
+
class CheckboxCore extends React.Component {
|
|
32
32
|
constructor(...args) {
|
|
33
33
|
super(...args);
|
|
34
34
|
|
|
@@ -51,15 +51,15 @@ class CheckboxCore extends Component {
|
|
|
51
51
|
focused,
|
|
52
52
|
pressed
|
|
53
53
|
} = _this$props,
|
|
54
|
-
sharedProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
|
|
54
|
+
sharedProps = _objectWithoutPropertiesLoose(_this$props, _excluded$4);
|
|
55
55
|
|
|
56
|
-
const stateStyles = _generateStyles(checked, error);
|
|
56
|
+
const stateStyles = _generateStyles$1(checked, error);
|
|
57
57
|
|
|
58
|
-
const defaultStyle = [sharedStyles.inputReset, sharedStyles.default, stateStyles.default, !disabled && (pressed ? stateStyles.active : (hovered || focused) && stateStyles.focus), disabled && sharedStyles.disabled];
|
|
58
|
+
const defaultStyle = [sharedStyles$1.inputReset, sharedStyles$1.default, stateStyles.default, !disabled && (pressed ? stateStyles.active : (hovered || focused) && stateStyles.focus), disabled && sharedStyles$1.disabled];
|
|
59
59
|
const props = {
|
|
60
60
|
"data-test-id": testId
|
|
61
61
|
};
|
|
62
|
-
return /*#__PURE__*/createElement(Fragment, null, /*#__PURE__*/createElement(StyledInput, _extends({}, sharedProps, {
|
|
62
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(StyledInput$1, _extends({}, sharedProps, {
|
|
63
63
|
type: "checkbox",
|
|
64
64
|
"aria-invalid": error,
|
|
65
65
|
checked: checked,
|
|
@@ -70,17 +70,17 @@ class CheckboxCore extends Component {
|
|
|
70
70
|
,
|
|
71
71
|
onChange: this.handleChange,
|
|
72
72
|
style: defaultStyle
|
|
73
|
-
}, props)), checked && /*#__PURE__*/createElement(Icon, {
|
|
74
|
-
color: disabled ? offBlack32 : white,
|
|
73
|
+
}, props)), checked && /*#__PURE__*/React.createElement(Icon, {
|
|
74
|
+
color: disabled ? offBlack32$1 : white$1,
|
|
75
75
|
icon: checkboxCheck,
|
|
76
76
|
size: "small",
|
|
77
|
-
style: sharedStyles.checkIcon
|
|
77
|
+
style: sharedStyles$1.checkIcon
|
|
78
78
|
}));
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
}
|
|
82
|
-
const size = 16;
|
|
83
|
-
const sharedStyles = StyleSheet.create({
|
|
82
|
+
const size$1 = 16;
|
|
83
|
+
const sharedStyles$1 = StyleSheet.create({
|
|
84
84
|
// Reset the default styled input element
|
|
85
85
|
inputReset: {
|
|
86
86
|
appearance: "none",
|
|
@@ -88,10 +88,10 @@ const sharedStyles = StyleSheet.create({
|
|
|
88
88
|
MozAppearance: "none"
|
|
89
89
|
},
|
|
90
90
|
default: {
|
|
91
|
-
height: size,
|
|
92
|
-
width: size,
|
|
93
|
-
minHeight: size,
|
|
94
|
-
minWidth: size,
|
|
91
|
+
height: size$1,
|
|
92
|
+
width: size$1,
|
|
93
|
+
minHeight: size$1,
|
|
94
|
+
minWidth: size$1,
|
|
95
95
|
margin: 0,
|
|
96
96
|
outline: "none",
|
|
97
97
|
boxSizing: "border-box",
|
|
@@ -101,8 +101,8 @@ const sharedStyles = StyleSheet.create({
|
|
|
101
101
|
},
|
|
102
102
|
disabled: {
|
|
103
103
|
cursor: "auto",
|
|
104
|
-
backgroundColor: offWhite,
|
|
105
|
-
borderColor: offBlack16,
|
|
104
|
+
backgroundColor: offWhite$1,
|
|
105
|
+
borderColor: offBlack16$1,
|
|
106
106
|
borderWidth: 1
|
|
107
107
|
},
|
|
108
108
|
checkIcon: {
|
|
@@ -110,33 +110,33 @@ const sharedStyles = StyleSheet.create({
|
|
|
110
110
|
pointerEvents: "none"
|
|
111
111
|
}
|
|
112
112
|
});
|
|
113
|
-
const fadedBlue = mix(fade(blue, 0.16), white);
|
|
114
|
-
const activeBlue = mix(offBlack32, blue);
|
|
115
|
-
const fadedRed = mix(fade(red, 0.08), white);
|
|
116
|
-
const activeRed = mix(offBlack32, red);
|
|
117
|
-
const colors = {
|
|
113
|
+
const fadedBlue$1 = mix(fade(blue$1, 0.16), white$1);
|
|
114
|
+
const activeBlue$1 = mix(offBlack32$1, blue$1);
|
|
115
|
+
const fadedRed$1 = mix(fade(red$1, 0.08), white$1);
|
|
116
|
+
const activeRed$1 = mix(offBlack32$1, red$1);
|
|
117
|
+
const colors$1 = {
|
|
118
118
|
default: {
|
|
119
|
-
faded: fadedBlue,
|
|
120
|
-
base: blue,
|
|
121
|
-
active: activeBlue
|
|
119
|
+
faded: fadedBlue$1,
|
|
120
|
+
base: blue$1,
|
|
121
|
+
active: activeBlue$1
|
|
122
122
|
},
|
|
123
123
|
error: {
|
|
124
|
-
faded: fadedRed,
|
|
125
|
-
base: red,
|
|
126
|
-
active: activeRed
|
|
124
|
+
faded: fadedRed$1,
|
|
125
|
+
base: red$1,
|
|
126
|
+
active: activeRed$1
|
|
127
127
|
}
|
|
128
128
|
};
|
|
129
|
-
const styles = {};
|
|
129
|
+
const styles$5 = {};
|
|
130
130
|
|
|
131
|
-
const _generateStyles = (checked, error) => {
|
|
131
|
+
const _generateStyles$1 = (checked, error) => {
|
|
132
132
|
// "hash" the parameters
|
|
133
133
|
const styleKey = `${String(checked)}-${String(error)}`;
|
|
134
134
|
|
|
135
|
-
if (styles[styleKey]) {
|
|
136
|
-
return styles[styleKey];
|
|
135
|
+
if (styles$5[styleKey]) {
|
|
136
|
+
return styles$5[styleKey];
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
const palette = error ? colors.error : colors.default;
|
|
139
|
+
const palette = error ? colors$1.error : colors$1.default;
|
|
140
140
|
let newStyles = {};
|
|
141
141
|
|
|
142
142
|
if (checked) {
|
|
@@ -146,52 +146,52 @@ const _generateStyles = (checked, error) => {
|
|
|
146
146
|
borderWidth: 0
|
|
147
147
|
},
|
|
148
148
|
focus: {
|
|
149
|
-
boxShadow: `0 0 0 1px ${white}, 0 0 0 3px ${palette.base}`
|
|
149
|
+
boxShadow: `0 0 0 1px ${white$1}, 0 0 0 3px ${palette.base}`
|
|
150
150
|
},
|
|
151
151
|
active: {
|
|
152
|
-
boxShadow: `0 0 0 1px ${white}, 0 0 0 3px ${palette.active}`,
|
|
152
|
+
boxShadow: `0 0 0 1px ${white$1}, 0 0 0 3px ${palette.active}`,
|
|
153
153
|
background: palette.active
|
|
154
154
|
}
|
|
155
155
|
};
|
|
156
156
|
} else {
|
|
157
157
|
newStyles = {
|
|
158
158
|
default: {
|
|
159
|
-
backgroundColor: error ? fadedRed : white,
|
|
160
|
-
borderColor: error ? red : offBlack50
|
|
159
|
+
backgroundColor: error ? fadedRed$1 : white$1,
|
|
160
|
+
borderColor: error ? red$1 : offBlack50$1
|
|
161
161
|
},
|
|
162
162
|
focus: {
|
|
163
|
-
backgroundColor: error ? fadedRed : white,
|
|
163
|
+
backgroundColor: error ? fadedRed$1 : white$1,
|
|
164
164
|
borderColor: palette.base,
|
|
165
165
|
borderWidth: 2
|
|
166
166
|
},
|
|
167
167
|
active: {
|
|
168
168
|
backgroundColor: palette.faded,
|
|
169
|
-
borderColor: error ? activeRed : blue,
|
|
169
|
+
borderColor: error ? activeRed$1 : blue$1,
|
|
170
170
|
borderWidth: 2
|
|
171
171
|
}
|
|
172
172
|
};
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
styles[styleKey] = StyleSheet.create(newStyles);
|
|
176
|
-
return styles[styleKey];
|
|
175
|
+
styles$5[styleKey] = StyleSheet.create(newStyles);
|
|
176
|
+
return styles$5[styleKey];
|
|
177
177
|
};
|
|
178
178
|
|
|
179
|
-
const _excluded$
|
|
179
|
+
const _excluded$3 = ["checked", "disabled", "error", "groupName", "id", "testId", "hovered", "focused", "pressed", "waiting"];
|
|
180
180
|
const {
|
|
181
|
-
blue
|
|
182
|
-
red
|
|
183
|
-
white
|
|
184
|
-
offWhite
|
|
185
|
-
offBlack16
|
|
186
|
-
offBlack32
|
|
187
|
-
offBlack50
|
|
181
|
+
blue,
|
|
182
|
+
red,
|
|
183
|
+
white,
|
|
184
|
+
offWhite,
|
|
185
|
+
offBlack16,
|
|
186
|
+
offBlack32,
|
|
187
|
+
offBlack50
|
|
188
188
|
} = Color;
|
|
189
|
-
const StyledInput
|
|
189
|
+
const StyledInput = addStyle("input");
|
|
190
190
|
/**
|
|
191
191
|
* The internal stateless 🔘 Radio button
|
|
192
192
|
*/
|
|
193
193
|
|
|
194
|
-
class RadioCore extends Component {
|
|
194
|
+
class RadioCore extends React.Component {
|
|
195
195
|
constructor(...args) {
|
|
196
196
|
super(...args);
|
|
197
197
|
|
|
@@ -214,15 +214,15 @@ class RadioCore extends Component {
|
|
|
214
214
|
focused,
|
|
215
215
|
pressed
|
|
216
216
|
} = _this$props,
|
|
217
|
-
sharedProps = _objectWithoutPropertiesLoose(_this$props, _excluded$
|
|
217
|
+
sharedProps = _objectWithoutPropertiesLoose(_this$props, _excluded$3);
|
|
218
218
|
|
|
219
|
-
const stateStyles = _generateStyles
|
|
219
|
+
const stateStyles = _generateStyles(checked, error);
|
|
220
220
|
|
|
221
|
-
const defaultStyle = [sharedStyles
|
|
221
|
+
const defaultStyle = [sharedStyles.inputReset, sharedStyles.default, stateStyles.default, !disabled && (pressed ? stateStyles.active : (hovered || focused) && stateStyles.focus), disabled && sharedStyles.disabled];
|
|
222
222
|
const props = {
|
|
223
223
|
"data-test-id": testId
|
|
224
224
|
};
|
|
225
|
-
return /*#__PURE__*/createElement(Fragment, null, /*#__PURE__*/createElement(StyledInput
|
|
225
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(StyledInput, _extends({}, sharedProps, {
|
|
226
226
|
type: "radio",
|
|
227
227
|
"aria-invalid": error,
|
|
228
228
|
checked: checked,
|
|
@@ -233,24 +233,24 @@ class RadioCore extends Component {
|
|
|
233
233
|
,
|
|
234
234
|
onChange: this.handleChange,
|
|
235
235
|
style: defaultStyle
|
|
236
|
-
}, props)), disabled && checked && /*#__PURE__*/createElement("span", {
|
|
236
|
+
}, props)), disabled && checked && /*#__PURE__*/React.createElement("span", {
|
|
237
237
|
style: disabledChecked
|
|
238
238
|
}));
|
|
239
239
|
}
|
|
240
240
|
|
|
241
241
|
}
|
|
242
|
-
const size
|
|
242
|
+
const size = 16; // circle with a different color. Here, we add that center circle. // If the checkbox is disabled and selected, it has a border but also an inner
|
|
243
243
|
|
|
244
244
|
const disabledChecked = {
|
|
245
245
|
position: "absolute",
|
|
246
|
-
top: size
|
|
247
|
-
left: size
|
|
248
|
-
height: size
|
|
249
|
-
width: size
|
|
246
|
+
top: size / 4,
|
|
247
|
+
left: size / 4,
|
|
248
|
+
height: size / 2,
|
|
249
|
+
width: size / 2,
|
|
250
250
|
borderRadius: "50%",
|
|
251
|
-
backgroundColor: offBlack32
|
|
251
|
+
backgroundColor: offBlack32
|
|
252
252
|
};
|
|
253
|
-
const sharedStyles
|
|
253
|
+
const sharedStyles = StyleSheet.create({
|
|
254
254
|
// Reset the default styled input element
|
|
255
255
|
inputReset: {
|
|
256
256
|
appearance: "none",
|
|
@@ -258,10 +258,10 @@ const sharedStyles$1 = StyleSheet.create({
|
|
|
258
258
|
MozAppearance: "none"
|
|
259
259
|
},
|
|
260
260
|
default: {
|
|
261
|
-
height: size
|
|
262
|
-
width: size
|
|
263
|
-
minHeight: size
|
|
264
|
-
minWidth: size
|
|
261
|
+
height: size,
|
|
262
|
+
width: size,
|
|
263
|
+
minHeight: size,
|
|
264
|
+
minWidth: size,
|
|
265
265
|
margin: 0,
|
|
266
266
|
outline: "none",
|
|
267
267
|
boxSizing: "border-box",
|
|
@@ -271,76 +271,76 @@ const sharedStyles$1 = StyleSheet.create({
|
|
|
271
271
|
},
|
|
272
272
|
disabled: {
|
|
273
273
|
cursor: "auto",
|
|
274
|
-
backgroundColor: offWhite
|
|
275
|
-
borderColor: offBlack16
|
|
274
|
+
backgroundColor: offWhite,
|
|
275
|
+
borderColor: offBlack16,
|
|
276
276
|
borderWidth: 1
|
|
277
277
|
}
|
|
278
278
|
});
|
|
279
|
-
const fadedBlue
|
|
280
|
-
const activeBlue
|
|
281
|
-
const fadedRed
|
|
282
|
-
const activeRed
|
|
283
|
-
const colors
|
|
279
|
+
const fadedBlue = mix(fade(blue, 0.16), white);
|
|
280
|
+
const activeBlue = mix(offBlack32, blue);
|
|
281
|
+
const fadedRed = mix(fade(red, 0.08), white);
|
|
282
|
+
const activeRed = mix(offBlack32, red);
|
|
283
|
+
const colors = {
|
|
284
284
|
default: {
|
|
285
|
-
faded: fadedBlue
|
|
286
|
-
base: blue
|
|
287
|
-
active: activeBlue
|
|
285
|
+
faded: fadedBlue,
|
|
286
|
+
base: blue,
|
|
287
|
+
active: activeBlue
|
|
288
288
|
},
|
|
289
289
|
error: {
|
|
290
|
-
faded: fadedRed
|
|
291
|
-
base: red
|
|
292
|
-
active: activeRed
|
|
290
|
+
faded: fadedRed,
|
|
291
|
+
base: red,
|
|
292
|
+
active: activeRed
|
|
293
293
|
}
|
|
294
294
|
};
|
|
295
|
-
const styles$
|
|
295
|
+
const styles$4 = {};
|
|
296
296
|
|
|
297
|
-
const _generateStyles
|
|
297
|
+
const _generateStyles = (checked, error) => {
|
|
298
298
|
// "hash" the parameters
|
|
299
299
|
const styleKey = `${String(checked)}-${String(error)}`;
|
|
300
300
|
|
|
301
|
-
if (styles$
|
|
302
|
-
return styles$
|
|
301
|
+
if (styles$4[styleKey]) {
|
|
302
|
+
return styles$4[styleKey];
|
|
303
303
|
}
|
|
304
304
|
|
|
305
|
-
const palette = error ? colors
|
|
305
|
+
const palette = error ? colors.error : colors.default;
|
|
306
306
|
let newStyles = {};
|
|
307
307
|
|
|
308
308
|
if (checked) {
|
|
309
309
|
newStyles = {
|
|
310
310
|
default: {
|
|
311
|
-
backgroundColor: white
|
|
311
|
+
backgroundColor: white,
|
|
312
312
|
borderColor: palette.base,
|
|
313
|
-
borderWidth: size
|
|
313
|
+
borderWidth: size / 4
|
|
314
314
|
},
|
|
315
315
|
focus: {
|
|
316
|
-
boxShadow: `0 0 0 1px ${white
|
|
316
|
+
boxShadow: `0 0 0 1px ${white}, 0 0 0 3px ${palette.base}`
|
|
317
317
|
},
|
|
318
318
|
active: {
|
|
319
|
-
boxShadow: `0 0 0 1px ${white
|
|
319
|
+
boxShadow: `0 0 0 1px ${white}, 0 0 0 3px ${palette.active}`,
|
|
320
320
|
borderColor: palette.active
|
|
321
321
|
}
|
|
322
322
|
};
|
|
323
323
|
} else {
|
|
324
324
|
newStyles = {
|
|
325
325
|
default: {
|
|
326
|
-
backgroundColor: error ? fadedRed
|
|
327
|
-
borderColor: error ? red
|
|
326
|
+
backgroundColor: error ? fadedRed : white,
|
|
327
|
+
borderColor: error ? red : offBlack50
|
|
328
328
|
},
|
|
329
329
|
focus: {
|
|
330
|
-
backgroundColor: error ? fadedRed
|
|
330
|
+
backgroundColor: error ? fadedRed : white,
|
|
331
331
|
borderColor: palette.base,
|
|
332
332
|
borderWidth: 2
|
|
333
333
|
},
|
|
334
334
|
active: {
|
|
335
335
|
backgroundColor: palette.faded,
|
|
336
|
-
borderColor: error ? activeRed
|
|
336
|
+
borderColor: error ? activeRed : blue,
|
|
337
337
|
borderWidth: 2
|
|
338
338
|
}
|
|
339
339
|
};
|
|
340
340
|
}
|
|
341
341
|
|
|
342
|
-
styles$
|
|
343
|
-
return styles$
|
|
342
|
+
styles$4[styleKey] = StyleSheet.create(newStyles);
|
|
343
|
+
return styles$4[styleKey];
|
|
344
344
|
};
|
|
345
345
|
|
|
346
346
|
const _excluded$2 = ["label", "description", "onChange", "style", "className", "variant"];
|
|
@@ -353,7 +353,7 @@ const _excluded$2 = ["label", "description", "onChange", "style", "className", "
|
|
|
353
353
|
* example, we can make onChange a required prop on Checkbox but not on Choice
|
|
354
354
|
* (because for Choice, that prop would be auto-populated by CheckboxGroup).
|
|
355
355
|
*/
|
|
356
|
-
class ChoiceInternal extends Component {
|
|
356
|
+
class ChoiceInternal extends React.Component {
|
|
357
357
|
constructor(...args) {
|
|
358
358
|
super(...args);
|
|
359
359
|
|
|
@@ -392,9 +392,9 @@ class ChoiceInternal extends Component {
|
|
|
392
392
|
id,
|
|
393
393
|
label
|
|
394
394
|
} = this.props;
|
|
395
|
-
return /*#__PURE__*/createElement(LabelMedium, {
|
|
396
|
-
style: [styles$
|
|
397
|
-
}, /*#__PURE__*/createElement("label", {
|
|
395
|
+
return /*#__PURE__*/React.createElement(LabelMedium, {
|
|
396
|
+
style: [styles$3.label, disabled && styles$3.disabledLabel]
|
|
397
|
+
}, /*#__PURE__*/React.createElement("label", {
|
|
398
398
|
htmlFor: id,
|
|
399
399
|
onClick: this.handleLabelClick
|
|
400
400
|
}, label));
|
|
@@ -404,8 +404,8 @@ class ChoiceInternal extends Component {
|
|
|
404
404
|
const {
|
|
405
405
|
description
|
|
406
406
|
} = this.props;
|
|
407
|
-
return /*#__PURE__*/createElement(LabelSmall, {
|
|
408
|
-
style: styles$
|
|
407
|
+
return /*#__PURE__*/React.createElement(LabelSmall, {
|
|
408
|
+
style: styles$3.description,
|
|
409
409
|
id: id
|
|
410
410
|
}, description);
|
|
411
411
|
}
|
|
@@ -423,29 +423,29 @@ class ChoiceInternal extends Component {
|
|
|
423
423
|
|
|
424
424
|
const ChoiceCore = this.getChoiceCoreComponent();
|
|
425
425
|
const ClickableBehavior = getClickableBehavior();
|
|
426
|
-
return /*#__PURE__*/createElement(UniqueIDProvider, {
|
|
426
|
+
return /*#__PURE__*/React.createElement(UniqueIDProvider, {
|
|
427
427
|
mockOnFirstRender: true,
|
|
428
428
|
scope: "choice"
|
|
429
429
|
}, ids => {
|
|
430
430
|
const descriptionId = description && ids.get("description");
|
|
431
|
-
return /*#__PURE__*/createElement(View, {
|
|
431
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
432
432
|
style: style,
|
|
433
433
|
className: className
|
|
434
|
-
}, /*#__PURE__*/createElement(ClickableBehavior, {
|
|
434
|
+
}, /*#__PURE__*/React.createElement(ClickableBehavior, {
|
|
435
435
|
disabled: coreProps.disabled,
|
|
436
436
|
onClick: this.handleClick,
|
|
437
437
|
role: variant
|
|
438
438
|
}, (state, childrenProps) => {
|
|
439
|
-
return /*#__PURE__*/createElement(View, _extends({
|
|
440
|
-
style: styles$
|
|
439
|
+
return /*#__PURE__*/React.createElement(View, _extends({
|
|
440
|
+
style: styles$3.wrapper
|
|
441
441
|
}, childrenProps, {
|
|
442
442
|
// We are resetting the tabIndex=0 from handlers
|
|
443
443
|
// because the ChoiceCore component will receive
|
|
444
444
|
// focus on basis of it being an input element.
|
|
445
445
|
tabIndex: -1
|
|
446
|
-
}), /*#__PURE__*/createElement(ChoiceCore, _extends({}, coreProps, state, {
|
|
446
|
+
}), /*#__PURE__*/React.createElement(ChoiceCore, _extends({}, coreProps, state, {
|
|
447
447
|
"aria-describedby": descriptionId
|
|
448
|
-
})), /*#__PURE__*/createElement(Strut, {
|
|
448
|
+
})), /*#__PURE__*/React.createElement(Strut, {
|
|
449
449
|
size: Spacing.xSmall_8
|
|
450
450
|
}), label && this.getLabel());
|
|
451
451
|
}), description && this.getDescription(descriptionId));
|
|
@@ -458,7 +458,7 @@ ChoiceInternal.defaultProps = {
|
|
|
458
458
|
disabled: false,
|
|
459
459
|
error: false
|
|
460
460
|
};
|
|
461
|
-
const styles$
|
|
461
|
+
const styles$3 = StyleSheet.create({
|
|
462
462
|
wrapper: {
|
|
463
463
|
flexDirection: "row",
|
|
464
464
|
alignItems: "flex-start",
|
|
@@ -490,9 +490,9 @@ const styles$2 = StyleSheet.create({
|
|
|
490
490
|
* If you want a whole group of Checkbox[es] that are related, see the Choice
|
|
491
491
|
* and CheckboxGroup components.
|
|
492
492
|
*/
|
|
493
|
-
class Checkbox extends Component {
|
|
493
|
+
class Checkbox extends React.Component {
|
|
494
494
|
render() {
|
|
495
|
-
return /*#__PURE__*/createElement(ChoiceInternal, _extends({
|
|
495
|
+
return /*#__PURE__*/React.createElement(ChoiceInternal, _extends({
|
|
496
496
|
variant: "checkbox"
|
|
497
497
|
}, this.props));
|
|
498
498
|
}
|
|
@@ -510,9 +510,9 @@ Checkbox.defaultProps = {
|
|
|
510
510
|
* This component should not really be used by itself because radio buttons are
|
|
511
511
|
* often grouped together. See RadioGroup.
|
|
512
512
|
*/
|
|
513
|
-
class Radio extends Component {
|
|
513
|
+
class Radio extends React.Component {
|
|
514
514
|
render() {
|
|
515
|
-
return /*#__PURE__*/createElement(ChoiceInternal, _extends({
|
|
515
|
+
return /*#__PURE__*/React.createElement(ChoiceInternal, _extends({
|
|
516
516
|
variant: "radio"
|
|
517
517
|
}, this.props));
|
|
518
518
|
}
|
|
@@ -523,7 +523,7 @@ Radio.defaultProps = {
|
|
|
523
523
|
error: false
|
|
524
524
|
};
|
|
525
525
|
|
|
526
|
-
const _excluded$
|
|
526
|
+
const _excluded$1 = ["value", "variant"];
|
|
527
527
|
|
|
528
528
|
/**
|
|
529
529
|
* This is a labeled 🔘 or ☑️ item. Choice is meant to be used as children of
|
|
@@ -534,7 +534,7 @@ const _excluded$3 = ["value", "variant"];
|
|
|
534
534
|
* If you wish to use just a single field, use Checkbox or Radio with the
|
|
535
535
|
* optional label and description props.
|
|
536
536
|
*/
|
|
537
|
-
class Choice extends Component {
|
|
537
|
+
class Choice extends React.Component {
|
|
538
538
|
getChoiceComponent(variant) {
|
|
539
539
|
if (variant === "checkbox") {
|
|
540
540
|
return Checkbox;
|
|
@@ -550,10 +550,10 @@ class Choice extends Component {
|
|
|
550
550
|
{
|
|
551
551
|
variant
|
|
552
552
|
} = _this$props,
|
|
553
|
-
remainingProps = _objectWithoutPropertiesLoose(_this$props, _excluded$
|
|
553
|
+
remainingProps = _objectWithoutPropertiesLoose(_this$props, _excluded$1);
|
|
554
554
|
|
|
555
555
|
const ChoiceComponent = this.getChoiceComponent(variant);
|
|
556
|
-
return /*#__PURE__*/createElement(ChoiceComponent, remainingProps);
|
|
556
|
+
return /*#__PURE__*/React.createElement(ChoiceComponent, remainingProps);
|
|
557
557
|
}
|
|
558
558
|
|
|
559
559
|
}
|
|
@@ -563,7 +563,7 @@ Choice.defaultProps = {
|
|
|
563
563
|
onChange: () => {}
|
|
564
564
|
};
|
|
565
565
|
|
|
566
|
-
const styles$
|
|
566
|
+
const styles$2 = StyleSheet.create({
|
|
567
567
|
fieldset: {
|
|
568
568
|
border: "none",
|
|
569
569
|
padding: 0,
|
|
@@ -585,8 +585,8 @@ const styles$3 = StyleSheet.create({
|
|
|
585
585
|
}
|
|
586
586
|
});
|
|
587
587
|
|
|
588
|
-
const StyledFieldset = addStyle("fieldset");
|
|
589
|
-
const StyledLegend = addStyle("legend");
|
|
588
|
+
const StyledFieldset$1 = addStyle("fieldset");
|
|
589
|
+
const StyledLegend$1 = addStyle("legend");
|
|
590
590
|
/**
|
|
591
591
|
* A checkbox group allows multiple selection. This component auto-populates
|
|
592
592
|
* many props for its children Choice components. The Choice component is
|
|
@@ -594,7 +594,7 @@ const StyledLegend = addStyle("legend");
|
|
|
594
594
|
* disabled.
|
|
595
595
|
*/
|
|
596
596
|
|
|
597
|
-
class CheckboxGroup extends Component {
|
|
597
|
+
class CheckboxGroup extends React.Component {
|
|
598
598
|
handleChange(changedValue, originalCheckedState) {
|
|
599
599
|
const {
|
|
600
600
|
onChange,
|
|
@@ -621,33 +621,33 @@ class CheckboxGroup extends Component {
|
|
|
621
621
|
style,
|
|
622
622
|
testId
|
|
623
623
|
} = this.props;
|
|
624
|
-
return /*#__PURE__*/createElement(StyledFieldset, {
|
|
624
|
+
return /*#__PURE__*/React.createElement(StyledFieldset$1, {
|
|
625
625
|
"data-test-id": testId,
|
|
626
|
-
style: styles$
|
|
627
|
-
}, /*#__PURE__*/createElement(View, {
|
|
626
|
+
style: styles$2.fieldset
|
|
627
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
628
628
|
style: style
|
|
629
|
-
}, typeof label === "string" ? /*#__PURE__*/createElement(StyledLegend, {
|
|
630
|
-
style: styles$
|
|
631
|
-
}, /*#__PURE__*/createElement(LabelMedium, null, label)) : label && label, typeof description === "string" ? /*#__PURE__*/createElement(LabelSmall, {
|
|
632
|
-
style: styles$
|
|
633
|
-
}, description) : description && description, errorMessage && /*#__PURE__*/createElement(LabelSmall, {
|
|
634
|
-
style: styles$
|
|
635
|
-
}, errorMessage), (label || description || errorMessage) && /*#__PURE__*/createElement(Strut, {
|
|
629
|
+
}, typeof label === "string" ? /*#__PURE__*/React.createElement(StyledLegend$1, {
|
|
630
|
+
style: styles$2.legend
|
|
631
|
+
}, /*#__PURE__*/React.createElement(LabelMedium, null, label)) : label && label, typeof description === "string" ? /*#__PURE__*/React.createElement(LabelSmall, {
|
|
632
|
+
style: styles$2.description
|
|
633
|
+
}, description) : description && description, errorMessage && /*#__PURE__*/React.createElement(LabelSmall, {
|
|
634
|
+
style: styles$2.error
|
|
635
|
+
}, errorMessage), (label || description || errorMessage) && /*#__PURE__*/React.createElement(Strut, {
|
|
636
636
|
size: Spacing.small_12
|
|
637
|
-
}), Children.map(children, (child, index) => {
|
|
637
|
+
}), React.Children.map(children, (child, index) => {
|
|
638
638
|
const {
|
|
639
639
|
style,
|
|
640
640
|
value
|
|
641
641
|
} = child.props;
|
|
642
642
|
const checked = selectedValues.includes(value);
|
|
643
|
-
return /*#__PURE__*/createElement(Fragment, null, /*#__PURE__*/cloneElement(child, {
|
|
643
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.cloneElement(child, {
|
|
644
644
|
checked: checked,
|
|
645
645
|
error: !!errorMessage,
|
|
646
646
|
groupName: groupName,
|
|
647
647
|
id: `${groupName}-${value}`,
|
|
648
648
|
key: value,
|
|
649
649
|
onChange: () => this.handleChange(value, checked),
|
|
650
|
-
style: [index > 0 && styles$
|
|
650
|
+
style: [index > 0 && styles$2.defaultLineGap, style],
|
|
651
651
|
variant: "checkbox"
|
|
652
652
|
}));
|
|
653
653
|
})));
|
|
@@ -655,8 +655,8 @@ class CheckboxGroup extends Component {
|
|
|
655
655
|
|
|
656
656
|
}
|
|
657
657
|
|
|
658
|
-
const StyledFieldset
|
|
659
|
-
const StyledLegend
|
|
658
|
+
const StyledFieldset = addStyle("fieldset");
|
|
659
|
+
const StyledLegend = addStyle("legend");
|
|
660
660
|
/**
|
|
661
661
|
* A radio group allows only single selection. Like CheckboxGroup, this
|
|
662
662
|
* component auto-populates many props for its children Choice components. The
|
|
@@ -666,7 +666,7 @@ const StyledLegend$1 = addStyle("legend");
|
|
|
666
666
|
* accessibility.
|
|
667
667
|
*/
|
|
668
668
|
|
|
669
|
-
class RadioGroup extends Component {
|
|
669
|
+
class RadioGroup extends React.Component {
|
|
670
670
|
handleChange(changedValue) {
|
|
671
671
|
this.props.onChange(changedValue);
|
|
672
672
|
}
|
|
@@ -682,33 +682,33 @@ class RadioGroup extends Component {
|
|
|
682
682
|
style,
|
|
683
683
|
testId
|
|
684
684
|
} = this.props;
|
|
685
|
-
return /*#__PURE__*/createElement(StyledFieldset
|
|
685
|
+
return /*#__PURE__*/React.createElement(StyledFieldset, {
|
|
686
686
|
"data-test-id": testId,
|
|
687
|
-
style: styles$
|
|
688
|
-
}, /*#__PURE__*/createElement(View, {
|
|
687
|
+
style: styles$2.fieldset
|
|
688
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
689
689
|
style: style
|
|
690
|
-
}, label && /*#__PURE__*/createElement(StyledLegend
|
|
691
|
-
style: styles$
|
|
692
|
-
}, /*#__PURE__*/createElement(LabelMedium, null, label)), description && /*#__PURE__*/createElement(LabelSmall, {
|
|
693
|
-
style: styles$
|
|
694
|
-
}, description), errorMessage && /*#__PURE__*/createElement(LabelSmall, {
|
|
695
|
-
style: styles$
|
|
696
|
-
}, errorMessage), (label || description || errorMessage) && /*#__PURE__*/createElement(Strut, {
|
|
690
|
+
}, label && /*#__PURE__*/React.createElement(StyledLegend, {
|
|
691
|
+
style: styles$2.legend
|
|
692
|
+
}, /*#__PURE__*/React.createElement(LabelMedium, null, label)), description && /*#__PURE__*/React.createElement(LabelSmall, {
|
|
693
|
+
style: styles$2.description
|
|
694
|
+
}, description), errorMessage && /*#__PURE__*/React.createElement(LabelSmall, {
|
|
695
|
+
style: styles$2.error
|
|
696
|
+
}, errorMessage), (label || description || errorMessage) && /*#__PURE__*/React.createElement(Strut, {
|
|
697
697
|
size: Spacing.small_12
|
|
698
|
-
}), Children.map(children, (child, index) => {
|
|
698
|
+
}), React.Children.map(children, (child, index) => {
|
|
699
699
|
const {
|
|
700
700
|
style,
|
|
701
701
|
value
|
|
702
702
|
} = child.props;
|
|
703
703
|
const checked = selectedValue === value;
|
|
704
|
-
return /*#__PURE__*/createElement(Fragment, null, /*#__PURE__*/cloneElement(child, {
|
|
704
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.cloneElement(child, {
|
|
705
705
|
checked: checked,
|
|
706
706
|
error: !!errorMessage,
|
|
707
707
|
groupName: groupName,
|
|
708
708
|
id: `${groupName}-${value}`,
|
|
709
709
|
key: value,
|
|
710
710
|
onChange: () => this.handleChange(value),
|
|
711
|
-
style: [index > 0 && styles$
|
|
711
|
+
style: [index > 0 && styles$2.defaultLineGap, style],
|
|
712
712
|
variant: "radio"
|
|
713
713
|
}));
|
|
714
714
|
})));
|
|
@@ -716,14 +716,15 @@ class RadioGroup extends Component {
|
|
|
716
716
|
|
|
717
717
|
}
|
|
718
718
|
|
|
719
|
-
const _excluded
|
|
719
|
+
const _excluded = ["id", "type", "value", "disabled", "onKeyDown", "placeholder", "light", "style", "testId", "readOnly", "autoComplete", "forwardedRef", "onFocus", "onBlur", "onValidate", "validate", "onChange", "required"];
|
|
720
|
+
const defaultErrorMessage = "This field is required.";
|
|
720
721
|
|
|
721
722
|
// TODO(WB-1081): Change class name back to TextField after Styleguidist is gone.
|
|
722
723
|
|
|
723
724
|
/**
|
|
724
725
|
* A TextField is an element used to accept a single line of text from the user.
|
|
725
726
|
*/
|
|
726
|
-
class TextFieldInternal extends Component {
|
|
727
|
+
class TextFieldInternal extends React.Component {
|
|
727
728
|
constructor(props) {
|
|
728
729
|
super(props);
|
|
729
730
|
this.state = {
|
|
@@ -734,7 +735,8 @@ class TextFieldInternal extends Component {
|
|
|
734
735
|
this.maybeValidate = newValue => {
|
|
735
736
|
const {
|
|
736
737
|
validate,
|
|
737
|
-
onValidate
|
|
738
|
+
onValidate,
|
|
739
|
+
required
|
|
738
740
|
} = this.props;
|
|
739
741
|
|
|
740
742
|
if (validate) {
|
|
@@ -746,6 +748,16 @@ class TextFieldInternal extends Component {
|
|
|
746
748
|
onValidate(maybeError);
|
|
747
749
|
}
|
|
748
750
|
});
|
|
751
|
+
} else if (required) {
|
|
752
|
+
const requiredString = typeof required === "string" ? required : defaultErrorMessage;
|
|
753
|
+
const maybeError = newValue ? null : requiredString;
|
|
754
|
+
this.setState({
|
|
755
|
+
error: maybeError
|
|
756
|
+
}, () => {
|
|
757
|
+
if (onValidate) {
|
|
758
|
+
onValidate(maybeError);
|
|
759
|
+
}
|
|
760
|
+
});
|
|
749
761
|
}
|
|
750
762
|
};
|
|
751
763
|
|
|
@@ -784,14 +796,16 @@ class TextFieldInternal extends Component {
|
|
|
784
796
|
});
|
|
785
797
|
};
|
|
786
798
|
|
|
787
|
-
if (props.validate) {
|
|
799
|
+
if (props.validate && props.value !== "") {
|
|
788
800
|
// Ensures error is updated on unmounted server-side renders
|
|
789
801
|
this.state.error = props.validate(props.value) || null;
|
|
790
802
|
}
|
|
791
803
|
}
|
|
792
804
|
|
|
793
805
|
componentDidMount() {
|
|
794
|
-
|
|
806
|
+
if (this.props.value !== "") {
|
|
807
|
+
this.maybeValidate(this.props.value);
|
|
808
|
+
}
|
|
795
809
|
}
|
|
796
810
|
|
|
797
811
|
render() {
|
|
@@ -803,7 +817,6 @@ class TextFieldInternal extends Component {
|
|
|
803
817
|
disabled,
|
|
804
818
|
onKeyDown,
|
|
805
819
|
placeholder,
|
|
806
|
-
required,
|
|
807
820
|
light,
|
|
808
821
|
style,
|
|
809
822
|
testId,
|
|
@@ -811,11 +824,11 @@ class TextFieldInternal extends Component {
|
|
|
811
824
|
autoComplete,
|
|
812
825
|
forwardedRef
|
|
813
826
|
} = _this$props,
|
|
814
|
-
otherProps = _objectWithoutPropertiesLoose(_this$props, _excluded
|
|
827
|
+
otherProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
|
|
815
828
|
|
|
816
|
-
return /*#__PURE__*/createElement("input", _extends({
|
|
817
|
-
className: css([styles$
|
|
818
|
-
disabled ? styles$
|
|
829
|
+
return /*#__PURE__*/React.createElement("input", _extends({
|
|
830
|
+
className: css([styles$1.input, styles$6.LabelMedium, styles$1.default, // Prioritizes disabled, then focused, then error (if any)
|
|
831
|
+
disabled ? styles$1.disabled : this.state.focused ? [styles$1.focused, light && styles$1.defaultLight] : this.state.error && [styles$1.error, light && styles$1.errorLight], style && style]),
|
|
819
832
|
id: id,
|
|
820
833
|
type: type,
|
|
821
834
|
placeholder: placeholder,
|
|
@@ -825,7 +838,6 @@ class TextFieldInternal extends Component {
|
|
|
825
838
|
onKeyDown: onKeyDown,
|
|
826
839
|
onFocus: this.handleFocus,
|
|
827
840
|
onBlur: this.handleBlur,
|
|
828
|
-
required: required,
|
|
829
841
|
"data-test-id": testId,
|
|
830
842
|
readOnly: readOnly,
|
|
831
843
|
autoComplete: autoComplete,
|
|
@@ -840,7 +852,7 @@ TextFieldInternal.defaultProps = {
|
|
|
840
852
|
disabled: false,
|
|
841
853
|
light: false
|
|
842
854
|
};
|
|
843
|
-
const styles$
|
|
855
|
+
const styles$1 = StyleSheet.create({
|
|
844
856
|
input: {
|
|
845
857
|
width: "100%",
|
|
846
858
|
height: 40,
|
|
@@ -890,27 +902,34 @@ const styles$4 = StyleSheet.create({
|
|
|
890
902
|
boxShadow: `0px 0px 0px 1px ${Color.red}, 0px 0px 0px 2px ${Color.white}`
|
|
891
903
|
}
|
|
892
904
|
});
|
|
893
|
-
const TextField = /*#__PURE__*/forwardRef((props, ref) => /*#__PURE__*/createElement(TextFieldInternal, _extends({}, props, {
|
|
905
|
+
const TextField = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/React.createElement(TextFieldInternal, _extends({}, props, {
|
|
894
906
|
forwardedRef: ref
|
|
895
907
|
})));
|
|
896
908
|
|
|
909
|
+
const StyledSpan = addStyle("span");
|
|
897
910
|
/**
|
|
898
911
|
* A FieldHeading is an element that provides a label, description, and error element
|
|
899
912
|
* to present better context and hints to any type of form field component.
|
|
900
913
|
*/
|
|
901
|
-
|
|
914
|
+
|
|
915
|
+
class FieldHeading extends React.Component {
|
|
902
916
|
renderLabel() {
|
|
903
917
|
const {
|
|
904
918
|
label,
|
|
905
919
|
id,
|
|
920
|
+
required,
|
|
906
921
|
testId
|
|
907
922
|
} = this.props;
|
|
908
|
-
|
|
909
|
-
style: styles
|
|
923
|
+
const requiredIcon = /*#__PURE__*/React.createElement(StyledSpan, {
|
|
924
|
+
style: styles.required,
|
|
925
|
+
"aria-hidden": true
|
|
926
|
+
}, " ", "*");
|
|
927
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, typeof label === "string" ? /*#__PURE__*/React.createElement(LabelMedium, {
|
|
928
|
+
style: styles.label,
|
|
910
929
|
tag: "label",
|
|
911
930
|
htmlFor: id && `${id}-field`,
|
|
912
931
|
testId: testId && `${testId}-label`
|
|
913
|
-
}, label) : label, /*#__PURE__*/createElement(Strut, {
|
|
932
|
+
}, label, required && requiredIcon) : label, /*#__PURE__*/React.createElement(Strut, {
|
|
914
933
|
size: Spacing.xxxSmall_4
|
|
915
934
|
}));
|
|
916
935
|
}
|
|
@@ -925,10 +944,10 @@ class FieldHeading extends Component {
|
|
|
925
944
|
return null;
|
|
926
945
|
}
|
|
927
946
|
|
|
928
|
-
return /*#__PURE__*/createElement(Fragment, null, typeof description === "string" ? /*#__PURE__*/createElement(LabelSmall, {
|
|
929
|
-
style: styles
|
|
947
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, typeof description === "string" ? /*#__PURE__*/React.createElement(LabelSmall, {
|
|
948
|
+
style: styles.description,
|
|
930
949
|
testId: testId && `${testId}-description`
|
|
931
|
-
}, description) : description, /*#__PURE__*/createElement(Strut, {
|
|
950
|
+
}, description) : description, /*#__PURE__*/React.createElement(Strut, {
|
|
932
951
|
size: Spacing.xxxSmall_4
|
|
933
952
|
}));
|
|
934
953
|
}
|
|
@@ -944,10 +963,10 @@ class FieldHeading extends Component {
|
|
|
944
963
|
return null;
|
|
945
964
|
}
|
|
946
965
|
|
|
947
|
-
return /*#__PURE__*/createElement(Fragment, null, /*#__PURE__*/createElement(Strut, {
|
|
966
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Strut, {
|
|
948
967
|
size: Spacing.small_12
|
|
949
|
-
}), typeof error === "string" ? /*#__PURE__*/createElement(LabelSmall, {
|
|
950
|
-
style: styles
|
|
968
|
+
}), typeof error === "string" ? /*#__PURE__*/React.createElement(LabelSmall, {
|
|
969
|
+
style: styles.error,
|
|
951
970
|
role: "alert",
|
|
952
971
|
id: id && `${id}-error`,
|
|
953
972
|
testId: testId && `${testId}-error`
|
|
@@ -959,15 +978,15 @@ class FieldHeading extends Component {
|
|
|
959
978
|
field,
|
|
960
979
|
style
|
|
961
980
|
} = this.props;
|
|
962
|
-
return /*#__PURE__*/createElement(View, {
|
|
981
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
963
982
|
style: style
|
|
964
|
-
}, this.renderLabel(), this.maybeRenderDescription(), /*#__PURE__*/createElement(Strut, {
|
|
983
|
+
}, this.renderLabel(), this.maybeRenderDescription(), /*#__PURE__*/React.createElement(Strut, {
|
|
965
984
|
size: Spacing.xSmall_8
|
|
966
985
|
}), field, this.maybeRenderError());
|
|
967
986
|
}
|
|
968
987
|
|
|
969
988
|
}
|
|
970
|
-
const styles
|
|
989
|
+
const styles = StyleSheet.create({
|
|
971
990
|
label: {
|
|
972
991
|
color: Color.offBlack
|
|
973
992
|
},
|
|
@@ -976,6 +995,9 @@ const styles$5 = StyleSheet.create({
|
|
|
976
995
|
},
|
|
977
996
|
error: {
|
|
978
997
|
color: Color.red
|
|
998
|
+
},
|
|
999
|
+
required: {
|
|
1000
|
+
color: Color.red
|
|
979
1001
|
}
|
|
980
1002
|
});
|
|
981
1003
|
|
|
@@ -985,7 +1007,7 @@ const styles$5 = StyleSheet.create({
|
|
|
985
1007
|
* A LabeledTextField is an element used to accept a single line of text
|
|
986
1008
|
* from the user paired with a label, description, and error field elements.
|
|
987
1009
|
*/
|
|
988
|
-
class LabeledTextFieldInternal extends Component {
|
|
1010
|
+
class LabeledTextFieldInternal extends React.Component {
|
|
989
1011
|
constructor(props) {
|
|
990
1012
|
super(props);
|
|
991
1013
|
|
|
@@ -1042,6 +1064,7 @@ class LabeledTextFieldInternal extends Component {
|
|
|
1042
1064
|
description,
|
|
1043
1065
|
value,
|
|
1044
1066
|
disabled,
|
|
1067
|
+
required,
|
|
1045
1068
|
validate,
|
|
1046
1069
|
onChange,
|
|
1047
1070
|
onKeyDown,
|
|
@@ -1054,17 +1077,19 @@ class LabeledTextFieldInternal extends Component {
|
|
|
1054
1077
|
forwardedRef,
|
|
1055
1078
|
ariaDescribedby
|
|
1056
1079
|
} = this.props;
|
|
1057
|
-
return /*#__PURE__*/createElement(IDProvider, {
|
|
1080
|
+
return /*#__PURE__*/React.createElement(IDProvider, {
|
|
1058
1081
|
id: id,
|
|
1059
1082
|
scope: "labeled-text-field"
|
|
1060
|
-
}, uniqueId => /*#__PURE__*/createElement(FieldHeading, {
|
|
1083
|
+
}, uniqueId => /*#__PURE__*/React.createElement(FieldHeading, {
|
|
1061
1084
|
id: uniqueId,
|
|
1062
1085
|
testId: testId,
|
|
1063
1086
|
style: style,
|
|
1064
|
-
field: /*#__PURE__*/createElement(TextField, {
|
|
1087
|
+
field: /*#__PURE__*/React.createElement(TextField, {
|
|
1065
1088
|
id: `${uniqueId}-field`,
|
|
1066
1089
|
"aria-describedby": ariaDescribedby ? ariaDescribedby : `${uniqueId}-error`,
|
|
1067
1090
|
"aria-invalid": this.state.error ? "true" : "false",
|
|
1091
|
+
"aria-required": required ? "true" : "false",
|
|
1092
|
+
required: required,
|
|
1068
1093
|
testId: testId && `${testId}-field`,
|
|
1069
1094
|
type: type,
|
|
1070
1095
|
value: value,
|
|
@@ -1083,6 +1108,7 @@ class LabeledTextFieldInternal extends Component {
|
|
|
1083
1108
|
}),
|
|
1084
1109
|
label: label,
|
|
1085
1110
|
description: description,
|
|
1111
|
+
required: !!required,
|
|
1086
1112
|
error: !this.state.focused && this.state.error || ""
|
|
1087
1113
|
}));
|
|
1088
1114
|
}
|
|
@@ -1094,7 +1120,7 @@ LabeledTextFieldInternal.defaultProps = {
|
|
|
1094
1120
|
disabled: false,
|
|
1095
1121
|
light: false
|
|
1096
1122
|
};
|
|
1097
|
-
const LabeledTextField = /*#__PURE__*/forwardRef((props, ref) => /*#__PURE__*/createElement(LabeledTextFieldInternal, _extends({}, props, {
|
|
1123
|
+
const LabeledTextField = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/React.createElement(LabeledTextFieldInternal, _extends({}, props, {
|
|
1098
1124
|
forwardedRef: ref
|
|
1099
1125
|
})));
|
|
1100
1126
|
|