@khanacademy/wonder-blocks-form 7.1.9 → 7.1.11
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 +27 -0
- package/dist/es/index.js +15 -1140
- package/dist/index.js +15 -1142
- package/package.json +6 -7
package/dist/es/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { useId } from 'react';
|
|
4
|
-
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose';
|
|
5
4
|
import { StyleSheet } from 'aphrodite';
|
|
6
5
|
import { addStyle, Id, View, useOnMountEffect } from '@khanacademy/wonder-blocks-core';
|
|
7
6
|
import { Strut } from '@khanacademy/wonder-blocks-layout';
|
|
@@ -11,1156 +10,32 @@ import { PhosphorIcon } from '@khanacademy/wonder-blocks-icon';
|
|
|
11
10
|
import checkIcon from '@phosphor-icons/core/bold/check-bold.svg';
|
|
12
11
|
import minusIcon from '@phosphor-icons/core/bold/minus-bold.svg';
|
|
13
12
|
|
|
14
|
-
const
|
|
15
|
-
function mapCheckedToAriaChecked(value) {
|
|
16
|
-
switch (value) {
|
|
17
|
-
case true:
|
|
18
|
-
return "true";
|
|
19
|
-
case false:
|
|
20
|
-
return "false";
|
|
21
|
-
default:
|
|
22
|
-
return "mixed";
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
const size$1 = spacing.medium_16;
|
|
26
|
-
const checkSize = spacing.small_12;
|
|
27
|
-
const StyledInput$2 = addStyle("input");
|
|
28
|
-
const CheckboxCore = React.forwardRef(function CheckboxCore(props, ref) {
|
|
29
|
-
const {
|
|
30
|
-
checked,
|
|
31
|
-
disabled,
|
|
32
|
-
error,
|
|
33
|
-
groupName,
|
|
34
|
-
id,
|
|
35
|
-
testId
|
|
36
|
-
} = props,
|
|
37
|
-
sharedProps = _objectWithoutPropertiesLoose(props, _excluded$7);
|
|
38
|
-
const innerRef = React.useRef(null);
|
|
39
|
-
React.useEffect(() => {
|
|
40
|
-
if (innerRef.current != null) {
|
|
41
|
-
innerRef.current.indeterminate = checked == null;
|
|
42
|
-
}
|
|
43
|
-
}, [checked, innerRef]);
|
|
44
|
-
const handleChange = () => {
|
|
45
|
-
return;
|
|
46
|
-
};
|
|
47
|
-
const stateStyles = _generateStyles$1(checked, error);
|
|
48
|
-
const defaultStyle = [sharedStyles$1.inputReset, sharedStyles$1.default, !disabled && stateStyles.default, disabled && sharedStyles$1.disabled];
|
|
49
|
-
const checkboxIcon = React.createElement(PhosphorIcon, {
|
|
50
|
-
color: disabled ? semanticColor.icon.disabled : semanticColor.icon.inverse,
|
|
51
|
-
icon: checked ? checkIcon : minusIcon,
|
|
52
|
-
size: "small",
|
|
53
|
-
style: [sharedStyles$1.checkboxIcon, {
|
|
54
|
-
width: checkSize,
|
|
55
|
-
height: checkSize
|
|
56
|
-
}]
|
|
57
|
-
});
|
|
58
|
-
const ariaChecked = mapCheckedToAriaChecked(checked);
|
|
59
|
-
return React.createElement(React.Fragment, null, React.createElement(StyledInput$2, _extends({}, sharedProps, {
|
|
60
|
-
ref: node => {
|
|
61
|
-
innerRef.current = node;
|
|
62
|
-
if (typeof ref === "function") {
|
|
63
|
-
ref(node);
|
|
64
|
-
} else if (ref != null) {
|
|
65
|
-
ref.current = node;
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
type: "checkbox",
|
|
69
|
-
"aria-checked": ariaChecked,
|
|
70
|
-
"aria-invalid": error,
|
|
71
|
-
checked: checked != null ? checked : undefined,
|
|
72
|
-
disabled: disabled,
|
|
73
|
-
id: id,
|
|
74
|
-
name: groupName,
|
|
75
|
-
onChange: handleChange,
|
|
76
|
-
style: defaultStyle,
|
|
77
|
-
"data-testid": testId
|
|
78
|
-
})), checked || checked == null ? checkboxIcon : React.createElement(React.Fragment, null));
|
|
79
|
-
});
|
|
80
|
-
const disabledState$1 = {
|
|
81
|
-
border: semanticColor.action.secondary.disabled.border,
|
|
82
|
-
background: semanticColor.action.secondary.disabled.background
|
|
83
|
-
};
|
|
84
|
-
const sharedStyles$1 = StyleSheet.create({
|
|
85
|
-
inputReset: {
|
|
86
|
-
appearance: "none",
|
|
87
|
-
WebkitAppearance: "none",
|
|
88
|
-
MozAppearance: "none"
|
|
89
|
-
},
|
|
90
|
-
default: {
|
|
91
|
-
height: size$1,
|
|
92
|
-
width: size$1,
|
|
93
|
-
minHeight: size$1,
|
|
94
|
-
minWidth: size$1,
|
|
95
|
-
margin: 0,
|
|
96
|
-
outline: "none",
|
|
97
|
-
boxSizing: "border-box",
|
|
98
|
-
borderStyle: "solid",
|
|
99
|
-
borderWidth: border.width.thin,
|
|
100
|
-
borderRadius: 3
|
|
101
|
-
},
|
|
102
|
-
disabled: {
|
|
103
|
-
cursor: "auto",
|
|
104
|
-
backgroundColor: disabledState$1.background,
|
|
105
|
-
borderColor: disabledState$1.border,
|
|
106
|
-
borderWidth: border.width.thin
|
|
107
|
-
},
|
|
108
|
-
checkboxIcon: {
|
|
109
|
-
position: "absolute",
|
|
110
|
-
pointerEvents: "none",
|
|
111
|
-
margin: (size$1 - checkSize) / 2
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
const styles$6 = {};
|
|
115
|
-
const _generateStyles$1 = (checked, error) => {
|
|
116
|
-
const styleKey = `${String(checked)}-${String(error)}`;
|
|
117
|
-
if (styles$6[styleKey]) {
|
|
118
|
-
return styles$6[styleKey];
|
|
119
|
-
}
|
|
120
|
-
const isCheckedOrIndeterminate = checked || checked == null;
|
|
121
|
-
const actionType = error ? "destructive" : "progressive";
|
|
122
|
-
const styleType = isCheckedOrIndeterminate ? "primary" : "secondary";
|
|
123
|
-
const colorAction = semanticColor.action[styleType][actionType];
|
|
124
|
-
const states = {
|
|
125
|
-
default: {
|
|
126
|
-
border: colorAction.default.border,
|
|
127
|
-
background: colorAction.default.background
|
|
128
|
-
},
|
|
129
|
-
error: {
|
|
130
|
-
border: semanticColor.status.critical.foreground,
|
|
131
|
-
background: semanticColor.status.critical.background
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
let newStyles = {};
|
|
135
|
-
if (isCheckedOrIndeterminate) {
|
|
136
|
-
newStyles = {
|
|
137
|
-
default: {
|
|
138
|
-
backgroundColor: states.default.background,
|
|
139
|
-
borderColor: states.default.border,
|
|
140
|
-
":focus-visible": {
|
|
141
|
-
outline: `${border.width.medium} solid ${semanticColor.focus.outer}`,
|
|
142
|
-
outlineOffset: 1
|
|
143
|
-
},
|
|
144
|
-
":hover": {
|
|
145
|
-
outline: `${border.width.medium} solid ${colorAction.hover.border}`,
|
|
146
|
-
outlineOffset: 1
|
|
147
|
-
},
|
|
148
|
-
":active": {
|
|
149
|
-
outline: `${border.width.medium} solid ${colorAction.press.border}`,
|
|
150
|
-
outlineOffset: 1,
|
|
151
|
-
background: colorAction.press.background
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
} else {
|
|
156
|
-
const currentState = error ? states.error : states.default;
|
|
157
|
-
newStyles = {
|
|
158
|
-
default: {
|
|
159
|
-
backgroundColor: currentState.background,
|
|
160
|
-
borderColor: currentState.border,
|
|
161
|
-
":focus-visible": {
|
|
162
|
-
backgroundColor: error ? states.error.background : colorAction.hover.background,
|
|
163
|
-
outline: `${border.width.medium} solid ${semanticColor.focus.outer}`,
|
|
164
|
-
outlineOffset: -1
|
|
165
|
-
},
|
|
166
|
-
":hover": {
|
|
167
|
-
backgroundColor: error ? states.error.background : colorAction.hover.background,
|
|
168
|
-
outline: `${border.width.medium} solid ${colorAction.hover.border}`,
|
|
169
|
-
outlineOffset: -1
|
|
170
|
-
},
|
|
171
|
-
":active": {
|
|
172
|
-
backgroundColor: colorAction.press.background,
|
|
173
|
-
outline: `${border.width.medium} solid ${colorAction.press.border}`,
|
|
174
|
-
outlineOffset: -1
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
styles$6[styleKey] = StyleSheet.create(newStyles);
|
|
180
|
-
return styles$6[styleKey];
|
|
181
|
-
};
|
|
13
|
+
function mapCheckedToAriaChecked(value){switch(value){case true:return "true";case false:return "false";default:return "mixed"}}const size$1=spacing.medium_16;const checkSize=spacing.small_12;const StyledInput$2=addStyle("input");const CheckboxCore=React.forwardRef(function CheckboxCore(props,ref){const{checked,disabled,error,groupName,id,testId,...sharedProps}=props;const innerRef=React.useRef(null);React.useEffect(()=>{if(innerRef.current!=null){innerRef.current.indeterminate=checked==null;}},[checked,innerRef]);const handleChange=()=>{return};const stateStyles=_generateStyles$1(checked,error);const defaultStyle=[sharedStyles$1.inputReset,sharedStyles$1.default,!disabled&&stateStyles.default,disabled&&sharedStyles$1.disabled];const checkboxIcon=jsx(PhosphorIcon,{color:disabled?semanticColor.icon.disabled:semanticColor.icon.inverse,icon:checked?checkIcon:minusIcon,size:"small",style:[sharedStyles$1.checkboxIcon,{width:checkSize,height:checkSize}]});const ariaChecked=mapCheckedToAriaChecked(checked);return jsxs(React.Fragment,{children:[jsx(StyledInput$2,{...sharedProps,ref:node=>{innerRef.current=node;if(typeof ref==="function"){ref(node);}else if(ref!=null){ref.current=node;}},type:"checkbox","aria-checked":ariaChecked,"aria-invalid":error,checked:checked??undefined,disabled:disabled,id:id,name:groupName,onChange:handleChange,style:defaultStyle,"data-testid":testId}),checked||checked==null?checkboxIcon:jsx(Fragment,{})]})});const disabledState$1={border:semanticColor.action.secondary.disabled.border,background:semanticColor.action.secondary.disabled.background};const sharedStyles$1=StyleSheet.create({inputReset:{appearance:"none",WebkitAppearance:"none",MozAppearance:"none"},default:{height:size$1,width:size$1,minHeight:size$1,minWidth:size$1,margin:0,outline:"none",boxSizing:"border-box",borderStyle:"solid",borderWidth:border.width.thin,borderRadius:3},disabled:{cursor:"auto",backgroundColor:disabledState$1.background,borderColor:disabledState$1.border,borderWidth:border.width.thin},checkboxIcon:{position:"absolute",pointerEvents:"none",margin:(size$1-checkSize)/2}});const styles$6={};const _generateStyles$1=(checked,error)=>{const styleKey=`${String(checked)}-${String(error)}`;if(styles$6[styleKey]){return styles$6[styleKey]}const isCheckedOrIndeterminate=checked||checked==null;const actionType=error?"destructive":"progressive";const styleType=isCheckedOrIndeterminate?"primary":"secondary";const colorAction=semanticColor.action[styleType][actionType];const states={default:{border:colorAction.default.border,background:colorAction.default.background},error:{border:semanticColor.status.critical.foreground,background:semanticColor.status.critical.background}};let newStyles={};if(isCheckedOrIndeterminate){newStyles={default:{backgroundColor:states.default.background,borderColor:states.default.border,":focus-visible":{outline:`${border.width.medium} solid ${semanticColor.focus.outer}`,outlineOffset:1},":hover":{outline:`${border.width.medium} solid ${colorAction.hover.border}`,outlineOffset:1},":active":{outline:`${border.width.medium} solid ${colorAction.press.border}`,outlineOffset:1,background:colorAction.press.background}}};}else {const currentState=error?states.error:states.default;newStyles={default:{backgroundColor:currentState.background,borderColor:currentState.border,":focus-visible":{backgroundColor:error?states.error.background:colorAction.hover.background,outline:`${border.width.medium} solid ${semanticColor.focus.outer}`,outlineOffset:-1},":hover":{backgroundColor:error?states.error.background:colorAction.hover.background,outline:`${border.width.medium} solid ${colorAction.hover.border}`,outlineOffset:-1},":active":{backgroundColor:colorAction.press.background,outline:`${border.width.medium} solid ${colorAction.press.border}`,outlineOffset:-1}}};}styles$6[styleKey]=StyleSheet.create(newStyles);return styles$6[styleKey]};
|
|
182
14
|
|
|
183
|
-
const
|
|
184
|
-
const StyledInput$1 = addStyle("input");
|
|
185
|
-
const RadioCore = React.forwardRef(function RadioCore(props, ref) {
|
|
186
|
-
const handleChange = () => {
|
|
187
|
-
return;
|
|
188
|
-
};
|
|
189
|
-
const {
|
|
190
|
-
checked,
|
|
191
|
-
disabled,
|
|
192
|
-
error,
|
|
193
|
-
groupName,
|
|
194
|
-
id,
|
|
195
|
-
testId
|
|
196
|
-
} = props,
|
|
197
|
-
sharedProps = _objectWithoutPropertiesLoose(props, _excluded$6);
|
|
198
|
-
const stateStyles = _generateStyles(checked, error);
|
|
199
|
-
const defaultStyle = [sharedStyles.inputReset, sharedStyles.default, !disabled && stateStyles.default, disabled && sharedStyles.disabled];
|
|
200
|
-
return React.createElement(React.Fragment, null, React.createElement(StyledInput$1, _extends({}, sharedProps, {
|
|
201
|
-
type: "radio",
|
|
202
|
-
"aria-invalid": error,
|
|
203
|
-
checked: checked != null ? checked : undefined,
|
|
204
|
-
disabled: disabled,
|
|
205
|
-
id: id,
|
|
206
|
-
name: groupName,
|
|
207
|
-
onChange: handleChange,
|
|
208
|
-
style: defaultStyle,
|
|
209
|
-
"data-testid": testId,
|
|
210
|
-
ref: ref
|
|
211
|
-
})), disabled && checked && React.createElement("span", {
|
|
212
|
-
style: disabledChecked
|
|
213
|
-
}));
|
|
214
|
-
});
|
|
215
|
-
const disabledState = {
|
|
216
|
-
border: semanticColor.action.secondary.disabled.border,
|
|
217
|
-
background: semanticColor.action.secondary.disabled.background
|
|
218
|
-
};
|
|
219
|
-
const size = 16;
|
|
220
|
-
const disabledChecked = {
|
|
221
|
-
position: "absolute",
|
|
222
|
-
top: size / 4,
|
|
223
|
-
left: size / 4,
|
|
224
|
-
height: size / 2,
|
|
225
|
-
width: size / 2,
|
|
226
|
-
borderRadius: border.radius.radius_full,
|
|
227
|
-
backgroundColor: semanticColor.action.primary.disabled.background
|
|
228
|
-
};
|
|
229
|
-
const sharedStyles = StyleSheet.create({
|
|
230
|
-
inputReset: {
|
|
231
|
-
appearance: "none",
|
|
232
|
-
WebkitAppearance: "none",
|
|
233
|
-
MozAppearance: "none"
|
|
234
|
-
},
|
|
235
|
-
default: {
|
|
236
|
-
height: size,
|
|
237
|
-
width: size,
|
|
238
|
-
minHeight: size,
|
|
239
|
-
minWidth: size,
|
|
240
|
-
margin: 0,
|
|
241
|
-
outline: "none",
|
|
242
|
-
boxSizing: "border-box",
|
|
243
|
-
borderStyle: "solid",
|
|
244
|
-
borderWidth: border.width.thin,
|
|
245
|
-
borderRadius: border.radius.radius_full
|
|
246
|
-
},
|
|
247
|
-
disabled: {
|
|
248
|
-
cursor: "auto",
|
|
249
|
-
backgroundColor: disabledState.background,
|
|
250
|
-
borderColor: disabledState.border,
|
|
251
|
-
borderWidth: border.width.thin
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
const styles$5 = {};
|
|
255
|
-
const _generateStyles = (checked, error) => {
|
|
256
|
-
const styleKey = `${String(checked)}-${String(error)}`;
|
|
257
|
-
if (styles$5[styleKey]) {
|
|
258
|
-
return styles$5[styleKey];
|
|
259
|
-
}
|
|
260
|
-
const actionType = error ? "destructive" : "progressive";
|
|
261
|
-
const colorAction = semanticColor.action.secondary[actionType];
|
|
262
|
-
const states = {
|
|
263
|
-
unchecked: {
|
|
264
|
-
border: semanticColor.border.strong,
|
|
265
|
-
background: colorAction.default.background
|
|
266
|
-
},
|
|
267
|
-
checked: {
|
|
268
|
-
border: colorAction.default.foreground,
|
|
269
|
-
background: colorAction.default.background
|
|
270
|
-
},
|
|
271
|
-
error: {
|
|
272
|
-
border: semanticColor.status.critical.foreground,
|
|
273
|
-
background: semanticColor.status.critical.background
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
let newStyles = {};
|
|
277
|
-
if (checked) {
|
|
278
|
-
newStyles = {
|
|
279
|
-
default: {
|
|
280
|
-
backgroundColor: states.checked.background,
|
|
281
|
-
borderColor: states.checked.border,
|
|
282
|
-
borderWidth: size / 4,
|
|
283
|
-
":focus-visible": {
|
|
284
|
-
outline: `${border.width.medium} solid ${semanticColor.focus.outer}`,
|
|
285
|
-
outlineOffset: 1
|
|
286
|
-
},
|
|
287
|
-
":hover": {
|
|
288
|
-
outline: `${border.width.medium} solid ${colorAction.hover.border}`,
|
|
289
|
-
outlineOffset: 1
|
|
290
|
-
},
|
|
291
|
-
":active": {
|
|
292
|
-
outline: `${border.width.medium} solid ${colorAction.press.border}`,
|
|
293
|
-
outlineOffset: 1,
|
|
294
|
-
borderColor: colorAction.press.border
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
};
|
|
298
|
-
} else {
|
|
299
|
-
const currentState = error ? states.error : states.unchecked;
|
|
300
|
-
newStyles = {
|
|
301
|
-
default: {
|
|
302
|
-
backgroundColor: currentState.background,
|
|
303
|
-
borderColor: currentState.border,
|
|
304
|
-
":focus-visible": {
|
|
305
|
-
backgroundColor: error ? states.error.background : colorAction.hover.background,
|
|
306
|
-
outline: `${border.width.medium} solid ${semanticColor.focus.outer}`,
|
|
307
|
-
outlineOffset: -1
|
|
308
|
-
},
|
|
309
|
-
":hover": {
|
|
310
|
-
backgroundColor: error ? states.error.background : colorAction.hover.background,
|
|
311
|
-
outline: `${border.width.medium} solid ${colorAction.hover.border}`,
|
|
312
|
-
outlineOffset: -1
|
|
313
|
-
},
|
|
314
|
-
":active": {
|
|
315
|
-
backgroundColor: colorAction.press.background,
|
|
316
|
-
outline: `${border.width.medium} solid ${colorAction.press.border}`,
|
|
317
|
-
outlineOffset: -1
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
styles$5[styleKey] = StyleSheet.create(newStyles);
|
|
323
|
-
return styles$5[styleKey];
|
|
324
|
-
};
|
|
15
|
+
const StyledInput$1=addStyle("input");const RadioCore=React.forwardRef(function RadioCore(props,ref){const handleChange=()=>{return};const{checked,disabled,error,groupName,id,testId,...sharedProps}=props;const stateStyles=_generateStyles(checked,error);const defaultStyle=[sharedStyles.inputReset,sharedStyles.default,!disabled&&stateStyles.default,disabled&&sharedStyles.disabled];return jsxs(React.Fragment,{children:[jsx(StyledInput$1,{...sharedProps,type:"radio","aria-invalid":error,checked:checked??undefined,disabled:disabled,id:id,name:groupName,onChange:handleChange,style:defaultStyle,"data-testid":testId,ref:ref}),disabled&&checked&&jsx("span",{style:disabledChecked})]})});const disabledState={border:semanticColor.action.secondary.disabled.border,background:semanticColor.action.secondary.disabled.background};const size=16;const disabledChecked={position:"absolute",top:size/4,left:size/4,height:size/2,width:size/2,borderRadius:border.radius.radius_full,backgroundColor:semanticColor.action.primary.disabled.background};const sharedStyles=StyleSheet.create({inputReset:{appearance:"none",WebkitAppearance:"none",MozAppearance:"none"},default:{height:size,width:size,minHeight:size,minWidth:size,margin:0,outline:"none",boxSizing:"border-box",borderStyle:"solid",borderWidth:border.width.thin,borderRadius:border.radius.radius_full},disabled:{cursor:"auto",backgroundColor:disabledState.background,borderColor:disabledState.border,borderWidth:border.width.thin}});const styles$5={};const _generateStyles=(checked,error)=>{const styleKey=`${String(checked)}-${String(error)}`;if(styles$5[styleKey]){return styles$5[styleKey]}const actionType=error?"destructive":"progressive";const colorAction=semanticColor.action.secondary[actionType];const states={unchecked:{border:semanticColor.border.strong,background:colorAction.default.background},checked:{border:colorAction.default.foreground,background:colorAction.default.background},error:{border:semanticColor.status.critical.foreground,background:semanticColor.status.critical.background}};let newStyles={};if(checked){newStyles={default:{backgroundColor:states.checked.background,borderColor:states.checked.border,borderWidth:size/4,":focus-visible":{outline:`${border.width.medium} solid ${semanticColor.focus.outer}`,outlineOffset:1},":hover":{outline:`${border.width.medium} solid ${colorAction.hover.border}`,outlineOffset:1},":active":{outline:`${border.width.medium} solid ${colorAction.press.border}`,outlineOffset:1,borderColor:colorAction.press.border}}};}else {const currentState=error?states.error:states.unchecked;newStyles={default:{backgroundColor:currentState.background,borderColor:currentState.border,":focus-visible":{backgroundColor:error?states.error.background:colorAction.hover.background,outline:`${border.width.medium} solid ${semanticColor.focus.outer}`,outlineOffset:-1},":hover":{backgroundColor:error?states.error.background:colorAction.hover.background,outline:`${border.width.medium} solid ${colorAction.hover.border}`,outlineOffset:-1},":active":{backgroundColor:colorAction.press.background,outline:`${border.width.medium} solid ${colorAction.press.border}`,outlineOffset:-1}}};}styles$5[styleKey]=StyleSheet.create(newStyles);return styles$5[styleKey]};
|
|
325
16
|
|
|
326
|
-
const
|
|
327
|
-
const ChoiceInternal = React.forwardRef(function ChoiceInternal(props, ref) {
|
|
328
|
-
const {
|
|
329
|
-
checked,
|
|
330
|
-
description,
|
|
331
|
-
disabled = false,
|
|
332
|
-
error = false,
|
|
333
|
-
id,
|
|
334
|
-
label,
|
|
335
|
-
onChange,
|
|
336
|
-
style,
|
|
337
|
-
className,
|
|
338
|
-
variant
|
|
339
|
-
} = props,
|
|
340
|
-
coreProps = _objectWithoutPropertiesLoose(props, _excluded$5);
|
|
341
|
-
const handleClick = () => {
|
|
342
|
-
if (variant === "radio" && checked) {
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
onChange(!checked);
|
|
346
|
-
};
|
|
347
|
-
const getChoiceCoreComponent = () => {
|
|
348
|
-
if (variant === "radio") {
|
|
349
|
-
return RadioCore;
|
|
350
|
-
} else {
|
|
351
|
-
return CheckboxCore;
|
|
352
|
-
}
|
|
353
|
-
};
|
|
354
|
-
const getLabel = id => {
|
|
355
|
-
return React.createElement(LabelMedium, {
|
|
356
|
-
style: [styles$4.label, disabled && styles$4.disabledLabel]
|
|
357
|
-
}, React.createElement("label", {
|
|
358
|
-
htmlFor: id
|
|
359
|
-
}, label));
|
|
360
|
-
};
|
|
361
|
-
const getDescription = id => {
|
|
362
|
-
return React.createElement(LabelSmall, {
|
|
363
|
-
style: styles$4.description,
|
|
364
|
-
id: id
|
|
365
|
-
}, description);
|
|
366
|
-
};
|
|
367
|
-
const ChoiceCore = getChoiceCoreComponent();
|
|
368
|
-
return (React.createElement(Id, {
|
|
369
|
-
id: id
|
|
370
|
-
}, uniqueId => {
|
|
371
|
-
const descriptionId = description ? `${uniqueId}-description` : undefined;
|
|
372
|
-
return React.createElement(View, {
|
|
373
|
-
style: style,
|
|
374
|
-
className: className
|
|
375
|
-
}, React.createElement(View, {
|
|
376
|
-
style: styles$4.wrapper,
|
|
377
|
-
tabIndex: -1
|
|
378
|
-
}, React.createElement(ChoiceCore, _extends({}, coreProps, {
|
|
379
|
-
id: uniqueId,
|
|
380
|
-
checked: checked,
|
|
381
|
-
"aria-describedby": descriptionId,
|
|
382
|
-
onClick: handleClick,
|
|
383
|
-
disabled: disabled,
|
|
384
|
-
error: error,
|
|
385
|
-
ref: ref
|
|
386
|
-
})), React.createElement(Strut, {
|
|
387
|
-
size: spacing.xSmall_8
|
|
388
|
-
}), label && getLabel(uniqueId)), description && getDescription(descriptionId));
|
|
389
|
-
})
|
|
390
|
-
);
|
|
391
|
-
});
|
|
392
|
-
const styles$4 = StyleSheet.create({
|
|
393
|
-
wrapper: {
|
|
394
|
-
flexDirection: "row",
|
|
395
|
-
alignItems: "flex-start",
|
|
396
|
-
outline: "none"
|
|
397
|
-
},
|
|
398
|
-
label: {
|
|
399
|
-
marginTop: -2
|
|
400
|
-
},
|
|
401
|
-
disabledLabel: {
|
|
402
|
-
color: semanticColor.action.secondary.disabled.foreground
|
|
403
|
-
},
|
|
404
|
-
description: {
|
|
405
|
-
marginLeft: spacing.medium_16 + spacing.xSmall_8,
|
|
406
|
-
marginTop: spacing.xxxSmall_4,
|
|
407
|
-
color: semanticColor.text.secondary
|
|
408
|
-
}
|
|
409
|
-
});
|
|
17
|
+
const ChoiceInternal=React.forwardRef(function ChoiceInternal(props,ref){const{checked,description,disabled=false,error=false,id,label,onChange,style,className,variant,...coreProps}=props;const handleClick=()=>{if(variant==="radio"&&checked){return}onChange(!checked);};const getChoiceCoreComponent=()=>{if(variant==="radio"){return RadioCore}else {return CheckboxCore}};const getLabel=id=>{return jsx(LabelMedium,{style:[styles$4.label,disabled&&styles$4.disabledLabel],children:jsx("label",{htmlFor:id,children:label})})};const getDescription=id=>{return jsx(LabelSmall,{style:styles$4.description,id:id,children:description})};const ChoiceCore=getChoiceCoreComponent();return jsx(Id,{id:id,children:uniqueId=>{const descriptionId=description?`${uniqueId}-description`:undefined;return jsxs(View,{style:style,className:className,children:[jsxs(View,{style:styles$4.wrapper,tabIndex:-1,children:[jsx(ChoiceCore,{...coreProps,id:uniqueId,checked:checked,"aria-describedby":descriptionId,onClick:handleClick,disabled:disabled,error:error,ref:ref}),jsx(Strut,{size:spacing.xSmall_8}),label&&getLabel(uniqueId)]}),description&&getDescription(descriptionId)]})}})});const styles$4=StyleSheet.create({wrapper:{flexDirection:"row",alignItems:"flex-start",outline:"none"},label:{marginTop:-2},disabledLabel:{color:semanticColor.action.secondary.disabled.foreground},description:{marginLeft:spacing.medium_16+spacing.xSmall_8,marginTop:spacing.xxxSmall_4,color:semanticColor.text.secondary}});
|
|
410
18
|
|
|
411
|
-
const Checkbox
|
|
412
|
-
const {
|
|
413
|
-
disabled = false,
|
|
414
|
-
error = false
|
|
415
|
-
} = props;
|
|
416
|
-
return React.createElement(ChoiceInternal, _extends({}, props, {
|
|
417
|
-
variant: "checkbox",
|
|
418
|
-
disabled: disabled,
|
|
419
|
-
error: error,
|
|
420
|
-
ref: ref
|
|
421
|
-
}));
|
|
422
|
-
});
|
|
19
|
+
const Checkbox=React.forwardRef(function Checkbox(props,ref){const{disabled=false,error=false}=props;return jsx(ChoiceInternal,{...props,variant:"checkbox",disabled:disabled,error:error,ref:ref})});
|
|
423
20
|
|
|
424
|
-
const
|
|
425
|
-
const Radio = React.forwardRef(function Radio(props, ref) {
|
|
426
|
-
const {
|
|
427
|
-
disabled = false,
|
|
428
|
-
error = false
|
|
429
|
-
} = props,
|
|
430
|
-
otherProps = _objectWithoutPropertiesLoose(props, _excluded$4);
|
|
431
|
-
return React.createElement(ChoiceInternal, _extends({}, otherProps, {
|
|
432
|
-
variant: "radio",
|
|
433
|
-
disabled: disabled,
|
|
434
|
-
error: error,
|
|
435
|
-
ref: ref
|
|
436
|
-
}));
|
|
437
|
-
});
|
|
21
|
+
const Radio=React.forwardRef(function Radio(props,ref){const{disabled=false,error=false,...otherProps}=props;return jsx(ChoiceInternal,{...otherProps,variant:"radio",disabled:disabled,error:error,ref:ref})});
|
|
438
22
|
|
|
439
|
-
const
|
|
440
|
-
const Choice = React.forwardRef(function Choice(props, ref) {
|
|
441
|
-
const {
|
|
442
|
-
checked = false,
|
|
443
|
-
disabled = false,
|
|
444
|
-
onChange = () => {},
|
|
445
|
-
variant
|
|
446
|
-
} = props,
|
|
447
|
-
remainingProps = _objectWithoutPropertiesLoose(props, _excluded$3);
|
|
448
|
-
const getChoiceComponent = variant => {
|
|
449
|
-
if (variant === "checkbox") {
|
|
450
|
-
return Checkbox;
|
|
451
|
-
} else {
|
|
452
|
-
return Radio;
|
|
453
|
-
}
|
|
454
|
-
};
|
|
455
|
-
const ChoiceComponent = getChoiceComponent(variant);
|
|
456
|
-
return React.createElement(ChoiceComponent, _extends({}, remainingProps, {
|
|
457
|
-
checked: checked,
|
|
458
|
-
disabled: disabled,
|
|
459
|
-
onChange: onChange,
|
|
460
|
-
ref: ref
|
|
461
|
-
}));
|
|
462
|
-
});
|
|
23
|
+
const Choice=React.forwardRef(function Choice(props,ref){const{checked=false,disabled=false,onChange=()=>{},value,variant,...remainingProps}=props;const getChoiceComponent=variant=>{if(variant==="checkbox"){return Checkbox}else {return Radio}};const ChoiceComponent=getChoiceComponent(variant);return jsx(ChoiceComponent,{...remainingProps,checked:checked,disabled:disabled,onChange:onChange,ref:ref})});
|
|
463
24
|
|
|
464
|
-
const styles$3
|
|
465
|
-
fieldset: {
|
|
466
|
-
display: "flex",
|
|
467
|
-
flexDirection: "column",
|
|
468
|
-
border: "none",
|
|
469
|
-
padding: 0,
|
|
470
|
-
margin: 0
|
|
471
|
-
},
|
|
472
|
-
legend: {
|
|
473
|
-
padding: 0,
|
|
474
|
-
width: "100%"
|
|
475
|
-
},
|
|
476
|
-
description: {
|
|
477
|
-
marginTop: spacing.xxxSmall_4,
|
|
478
|
-
color: semanticColor.text.secondary
|
|
479
|
-
},
|
|
480
|
-
error: {
|
|
481
|
-
marginTop: spacing.xxxSmall_4,
|
|
482
|
-
color: semanticColor.status.critical.foreground
|
|
483
|
-
},
|
|
484
|
-
defaultLineGap: {
|
|
485
|
-
marginTop: spacing.xSmall_8
|
|
486
|
-
}
|
|
487
|
-
});
|
|
25
|
+
const styles$3=StyleSheet.create({fieldset:{display:"flex",flexDirection:"column",border:"none",padding:0,margin:0},legend:{padding:0,width:"100%"},description:{marginTop:spacing.xxxSmall_4,color:semanticColor.text.secondary},error:{marginTop:spacing.xxxSmall_4,color:semanticColor.status.critical.foreground},defaultLineGap:{marginTop:spacing.xSmall_8}});
|
|
488
26
|
|
|
489
|
-
const StyledFieldset$1 =
|
|
490
|
-
const StyledLegend$1 = addStyle("legend");
|
|
491
|
-
const CheckboxGroup = React.forwardRef(function CheckboxGroup(props, ref) {
|
|
492
|
-
const {
|
|
493
|
-
children,
|
|
494
|
-
label,
|
|
495
|
-
description,
|
|
496
|
-
errorMessage,
|
|
497
|
-
groupName,
|
|
498
|
-
onChange,
|
|
499
|
-
selectedValues,
|
|
500
|
-
style,
|
|
501
|
-
testId
|
|
502
|
-
} = props;
|
|
503
|
-
const handleChange = (changedValue, originalCheckedState) => {
|
|
504
|
-
if (originalCheckedState) {
|
|
505
|
-
const index = selectedValues.indexOf(changedValue);
|
|
506
|
-
const updatedSelection = [...selectedValues.slice(0, index), ...selectedValues.slice(index + 1)];
|
|
507
|
-
onChange(updatedSelection);
|
|
508
|
-
} else {
|
|
509
|
-
onChange([...selectedValues, changedValue]);
|
|
510
|
-
}
|
|
511
|
-
};
|
|
512
|
-
const allChildren = React.Children.toArray(children).filter(Boolean);
|
|
513
|
-
return React.createElement(StyledFieldset$1, {
|
|
514
|
-
"data-testid": testId,
|
|
515
|
-
style: [styles$3.fieldset, style],
|
|
516
|
-
ref: ref
|
|
517
|
-
}, label && React.createElement(StyledLegend$1, {
|
|
518
|
-
style: styles$3.legend
|
|
519
|
-
}, React.createElement(LabelMedium, null, label)), description && React.createElement(LabelSmall, {
|
|
520
|
-
style: styles$3.description
|
|
521
|
-
}, description), errorMessage && React.createElement(LabelSmall, {
|
|
522
|
-
style: styles$3.error
|
|
523
|
-
}, errorMessage), (label || description || errorMessage) && React.createElement(Strut, {
|
|
524
|
-
size: spacing.small_12
|
|
525
|
-
}), allChildren.map((child, index) => {
|
|
526
|
-
const {
|
|
527
|
-
style,
|
|
528
|
-
value
|
|
529
|
-
} = child.props;
|
|
530
|
-
const checked = selectedValues.includes(value);
|
|
531
|
-
return React.cloneElement(child, {
|
|
532
|
-
checked: checked,
|
|
533
|
-
error: !!errorMessage,
|
|
534
|
-
groupName: groupName,
|
|
535
|
-
id: `${groupName}-${value}`,
|
|
536
|
-
key: value,
|
|
537
|
-
onChange: () => handleChange(value, checked),
|
|
538
|
-
style: [index > 0 && styles$3.defaultLineGap, style],
|
|
539
|
-
variant: "checkbox"
|
|
540
|
-
});
|
|
541
|
-
}));
|
|
542
|
-
});
|
|
27
|
+
const StyledFieldset$1=addStyle("fieldset");const StyledLegend$1=addStyle("legend");const CheckboxGroup=React.forwardRef(function CheckboxGroup(props,ref){const{children,label,description,errorMessage,groupName,onChange,selectedValues,style,testId}=props;const handleChange=(changedValue,originalCheckedState)=>{if(originalCheckedState){const index=selectedValues.indexOf(changedValue);const updatedSelection=[...selectedValues.slice(0,index),...selectedValues.slice(index+1)];onChange(updatedSelection);}else {onChange([...selectedValues,changedValue]);}};const allChildren=React.Children.toArray(children).filter(Boolean);return jsxs(StyledFieldset$1,{"data-testid":testId,style:[styles$3.fieldset,style],ref:ref,children:[label&&jsx(StyledLegend$1,{style:styles$3.legend,children:jsx(LabelMedium,{children:label})}),description&&jsx(LabelSmall,{style:styles$3.description,children:description}),errorMessage&&jsx(LabelSmall,{style:styles$3.error,children:errorMessage}),(label||description||errorMessage)&&jsx(Strut,{size:spacing.small_12}),allChildren.map((child,index)=>{const{style,value}=child.props;const checked=selectedValues.includes(value);return React.cloneElement(child,{checked:checked,error:!!errorMessage,groupName:groupName,id:`${groupName}-${value}`,key:value,onChange:()=>handleChange(value,checked),style:[index>0&&styles$3.defaultLineGap,style],variant:"checkbox"})})]})});
|
|
543
28
|
|
|
544
|
-
const StyledFieldset =
|
|
545
|
-
const StyledLegend = addStyle("legend");
|
|
546
|
-
const RadioGroup = React.forwardRef(function RadioGroup(props, ref) {
|
|
547
|
-
const {
|
|
548
|
-
children,
|
|
549
|
-
label,
|
|
550
|
-
description,
|
|
551
|
-
errorMessage,
|
|
552
|
-
groupName,
|
|
553
|
-
onChange,
|
|
554
|
-
selectedValue,
|
|
555
|
-
style,
|
|
556
|
-
testId
|
|
557
|
-
} = props;
|
|
558
|
-
const allChildren = React.Children.toArray(children).filter(Boolean);
|
|
559
|
-
return React.createElement(StyledFieldset, {
|
|
560
|
-
"data-testid": testId,
|
|
561
|
-
style: [styles$3.fieldset, style],
|
|
562
|
-
ref: ref
|
|
563
|
-
}, label && React.createElement(StyledLegend, {
|
|
564
|
-
style: styles$3.legend
|
|
565
|
-
}, React.createElement(LabelMedium, null, label)), description && React.createElement(LabelSmall, {
|
|
566
|
-
style: styles$3.description
|
|
567
|
-
}, description), errorMessage && React.createElement(LabelSmall, {
|
|
568
|
-
style: styles$3.error
|
|
569
|
-
}, errorMessage), (label || description || errorMessage) && React.createElement(Strut, {
|
|
570
|
-
size: spacing.small_12
|
|
571
|
-
}), allChildren.map((child, index) => {
|
|
572
|
-
const {
|
|
573
|
-
style,
|
|
574
|
-
value
|
|
575
|
-
} = child.props;
|
|
576
|
-
const checked = selectedValue === value;
|
|
577
|
-
return React.cloneElement(child, {
|
|
578
|
-
checked: checked,
|
|
579
|
-
error: !!errorMessage,
|
|
580
|
-
groupName: groupName,
|
|
581
|
-
id: `${groupName}-${value}`,
|
|
582
|
-
key: value,
|
|
583
|
-
onChange: () => onChange(value),
|
|
584
|
-
style: [index > 0 && styles$3.defaultLineGap, style],
|
|
585
|
-
variant: "radio"
|
|
586
|
-
});
|
|
587
|
-
}));
|
|
588
|
-
});
|
|
29
|
+
const StyledFieldset=addStyle("fieldset");const StyledLegend=addStyle("legend");const RadioGroup=React.forwardRef(function RadioGroup(props,ref){const{children,label,description,errorMessage,groupName,onChange,selectedValue,style,testId}=props;const allChildren=React.Children.toArray(children).filter(Boolean);return jsxs(StyledFieldset,{"data-testid":testId,style:[styles$3.fieldset,style],ref:ref,children:[label&&jsx(StyledLegend,{style:styles$3.legend,children:jsx(LabelMedium,{children:label})}),description&&jsx(LabelSmall,{style:styles$3.description,children:description}),errorMessage&&jsx(LabelSmall,{style:styles$3.error,children:errorMessage}),(label||description||errorMessage)&&jsx(Strut,{size:spacing.small_12}),allChildren.map((child,index)=>{const{style,value}=child.props;const checked=selectedValue===value;return React.cloneElement(child,{checked:checked,error:!!errorMessage,groupName:groupName,id:`${groupName}-${value}`,key:value,onChange:()=>onChange(value),style:[index>0&&styles$3.defaultLineGap,style],variant:"radio"})})]})});
|
|
589
30
|
|
|
590
|
-
const defaultErrorMessage
|
|
591
|
-
const useFieldValidation = ({
|
|
592
|
-
value,
|
|
593
|
-
disabled: _disabled = false,
|
|
594
|
-
validate,
|
|
595
|
-
onValidate,
|
|
596
|
-
required: _required = false,
|
|
597
|
-
instantValidation: _instantValidation = true
|
|
598
|
-
}) => {
|
|
599
|
-
const [errorMessage, setErrorMessage] = React.useState(() => validate && value !== "" && !_disabled && validate(value) || null);
|
|
600
|
-
const onChangeValidation = newValue => {
|
|
601
|
-
if (_instantValidation) {
|
|
602
|
-
handleValidation(newValue);
|
|
603
|
-
} else {
|
|
604
|
-
setErrorMessage(null);
|
|
605
|
-
if (onValidate) {
|
|
606
|
-
onValidate(null);
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
};
|
|
610
|
-
const onBlurValidation = newValue => {
|
|
611
|
-
if (!_instantValidation) {
|
|
612
|
-
if (newValue || _required) {
|
|
613
|
-
handleValidation(newValue);
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
};
|
|
617
|
-
const handleValidation = newValue => {
|
|
618
|
-
if (_disabled) {
|
|
619
|
-
return;
|
|
620
|
-
}
|
|
621
|
-
if (validate) {
|
|
622
|
-
const error = validate(newValue) || null;
|
|
623
|
-
setErrorMessage(error);
|
|
624
|
-
if (onValidate) {
|
|
625
|
-
onValidate(error);
|
|
626
|
-
}
|
|
627
|
-
} else if (_required) {
|
|
628
|
-
const requiredString = typeof _required === "string" ? _required : defaultErrorMessage;
|
|
629
|
-
const error = newValue ? null : requiredString;
|
|
630
|
-
setErrorMessage(error);
|
|
631
|
-
if (onValidate) {
|
|
632
|
-
onValidate(error);
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
};
|
|
636
|
-
useOnMountEffect(() => {
|
|
637
|
-
if (value !== "") {
|
|
638
|
-
handleValidation(value);
|
|
639
|
-
}
|
|
640
|
-
});
|
|
641
|
-
return {
|
|
642
|
-
errorMessage,
|
|
643
|
-
onBlurValidation,
|
|
644
|
-
onChangeValidation
|
|
645
|
-
};
|
|
646
|
-
};
|
|
31
|
+
const defaultErrorMessage="This field is required.";const useFieldValidation=({value,disabled=false,validate,onValidate,required=false,instantValidation=true})=>{const[errorMessage,setErrorMessage]=React.useState(()=>validate&&value!==""&&!disabled&&validate(value)||null);const onChangeValidation=newValue=>{if(instantValidation){handleValidation(newValue);}else {setErrorMessage(null);if(onValidate){onValidate(null);}}};const onBlurValidation=newValue=>{if(!instantValidation){if(newValue||required){handleValidation(newValue);}}};const handleValidation=newValue=>{if(disabled){return}if(validate){const error=validate(newValue)||null;setErrorMessage(error);if(onValidate){onValidate(error);}}else if(required){const requiredString=typeof required==="string"?required:defaultErrorMessage;const error=newValue?null:requiredString;setErrorMessage(error);if(onValidate){onValidate(error);}}};useOnMountEffect(()=>{if(value!==""){handleValidation(value);}});return {errorMessage,onBlurValidation,onChangeValidation}};
|
|
647
32
|
|
|
648
|
-
const
|
|
649
|
-
const StyledInput = addStyle("input");
|
|
650
|
-
const TextField = props => {
|
|
651
|
-
const {
|
|
652
|
-
id,
|
|
653
|
-
type = "text",
|
|
654
|
-
value,
|
|
655
|
-
name,
|
|
656
|
-
disabled = false,
|
|
657
|
-
error,
|
|
658
|
-
validate,
|
|
659
|
-
onValidate,
|
|
660
|
-
required,
|
|
661
|
-
placeholder,
|
|
662
|
-
style,
|
|
663
|
-
testId,
|
|
664
|
-
readOnly,
|
|
665
|
-
autoFocus,
|
|
666
|
-
autoComplete,
|
|
667
|
-
forwardedRef,
|
|
668
|
-
instantValidation = true,
|
|
669
|
-
onKeyDown,
|
|
670
|
-
onChange,
|
|
671
|
-
onFocus,
|
|
672
|
-
onBlur
|
|
673
|
-
} = props,
|
|
674
|
-
otherProps = _objectWithoutPropertiesLoose(props, _excluded$2);
|
|
675
|
-
const {
|
|
676
|
-
errorMessage,
|
|
677
|
-
onBlurValidation,
|
|
678
|
-
onChangeValidation
|
|
679
|
-
} = useFieldValidation({
|
|
680
|
-
value,
|
|
681
|
-
required,
|
|
682
|
-
disabled,
|
|
683
|
-
instantValidation,
|
|
684
|
-
validate,
|
|
685
|
-
onValidate
|
|
686
|
-
});
|
|
687
|
-
const hasError = error || !!errorMessage;
|
|
688
|
-
const handleChange = event => {
|
|
689
|
-
const newValue = event.target.value;
|
|
690
|
-
onChangeValidation(newValue);
|
|
691
|
-
onChange(newValue);
|
|
692
|
-
};
|
|
693
|
-
const handleFocus = event => {
|
|
694
|
-
if (onFocus) {
|
|
695
|
-
onFocus(event);
|
|
696
|
-
}
|
|
697
|
-
};
|
|
698
|
-
const handleBlur = event => {
|
|
699
|
-
onBlurValidation(event.target.value);
|
|
700
|
-
if (onBlur) {
|
|
701
|
-
onBlur(event);
|
|
702
|
-
}
|
|
703
|
-
};
|
|
704
|
-
return React.createElement(Id, {
|
|
705
|
-
id: id
|
|
706
|
-
}, uniqueId => React.createElement(StyledInput, _extends({
|
|
707
|
-
style: [styles$2.input, styles$7.LabelMedium, styles$2.default, !disabled && styles$2.defaultFocus, disabled && styles$2.disabled, hasError && styles$2.error, style],
|
|
708
|
-
id: uniqueId,
|
|
709
|
-
type: type,
|
|
710
|
-
placeholder: placeholder,
|
|
711
|
-
value: value,
|
|
712
|
-
name: name,
|
|
713
|
-
"aria-disabled": disabled,
|
|
714
|
-
"aria-required": !!required,
|
|
715
|
-
onChange: handleChange,
|
|
716
|
-
onKeyDown: disabled ? undefined : onKeyDown,
|
|
717
|
-
onFocus: handleFocus,
|
|
718
|
-
onBlur: handleBlur,
|
|
719
|
-
"data-testid": testId,
|
|
720
|
-
readOnly: readOnly || disabled,
|
|
721
|
-
autoFocus: autoFocus,
|
|
722
|
-
autoComplete: autoComplete,
|
|
723
|
-
ref: forwardedRef,
|
|
724
|
-
"aria-invalid": hasError
|
|
725
|
-
}, otherProps)));
|
|
726
|
-
};
|
|
727
|
-
const states$1 = {
|
|
728
|
-
default: {
|
|
729
|
-
border: semanticColor.border.strong,
|
|
730
|
-
background: semanticColor.surface.primary,
|
|
731
|
-
foreground: semanticColor.text.primary
|
|
732
|
-
},
|
|
733
|
-
disabled: {
|
|
734
|
-
border: semanticColor.action.secondary.disabled.border,
|
|
735
|
-
background: semanticColor.action.secondary.disabled.background,
|
|
736
|
-
foreground: semanticColor.text.secondary
|
|
737
|
-
},
|
|
738
|
-
error: {
|
|
739
|
-
border: semanticColor.status.critical.foreground,
|
|
740
|
-
background: semanticColor.status.critical.background,
|
|
741
|
-
foreground: semanticColor.text.primary
|
|
742
|
-
}
|
|
743
|
-
};
|
|
744
|
-
const styles$2 = StyleSheet.create({
|
|
745
|
-
input: {
|
|
746
|
-
width: "100%",
|
|
747
|
-
height: 40,
|
|
748
|
-
borderRadius: border.radius.radius_040,
|
|
749
|
-
boxSizing: "border-box",
|
|
750
|
-
paddingLeft: spacing.medium_16,
|
|
751
|
-
margin: 0
|
|
752
|
-
},
|
|
753
|
-
default: {
|
|
754
|
-
background: states$1.default.background,
|
|
755
|
-
border: `${border.width.thin} solid ${states$1.default.border}`,
|
|
756
|
-
color: states$1.default.foreground,
|
|
757
|
-
"::placeholder": {
|
|
758
|
-
color: semanticColor.text.secondary
|
|
759
|
-
}
|
|
760
|
-
},
|
|
761
|
-
defaultFocus: {
|
|
762
|
-
":focus-visible": {
|
|
763
|
-
borderColor: semanticColor.focus.outer,
|
|
764
|
-
outline: `${border.width.thin} solid ${semanticColor.focus.outer}`,
|
|
765
|
-
outlineOffset: -2
|
|
766
|
-
}
|
|
767
|
-
},
|
|
768
|
-
error: {
|
|
769
|
-
background: states$1.error.background,
|
|
770
|
-
border: `${border.width.thin} solid ${states$1.error.border}`,
|
|
771
|
-
color: states$1.error.foreground,
|
|
772
|
-
"::placeholder": {
|
|
773
|
-
color: semanticColor.text.secondary
|
|
774
|
-
},
|
|
775
|
-
":focus-visible": {
|
|
776
|
-
outlineColor: semanticColor.focus.outer,
|
|
777
|
-
outline: `${border.width.medium} solid ${semanticColor.focus.outer}`
|
|
778
|
-
}
|
|
779
|
-
},
|
|
780
|
-
disabled: {
|
|
781
|
-
background: states$1.disabled.background,
|
|
782
|
-
border: `${border.width.thin} solid ${states$1.disabled.border}`,
|
|
783
|
-
color: states$1.disabled.foreground,
|
|
784
|
-
"::placeholder": {
|
|
785
|
-
color: states$1.disabled.foreground
|
|
786
|
-
},
|
|
787
|
-
cursor: "not-allowed",
|
|
788
|
-
":focus-visible": {
|
|
789
|
-
outline: `${border.width.medium} solid ${semanticColor.focus.outer}`,
|
|
790
|
-
outlineOffset: -3
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
});
|
|
794
|
-
var TextField$1 = React.forwardRef((props, ref) => React.createElement(TextField, _extends({}, props, {
|
|
795
|
-
forwardedRef: ref
|
|
796
|
-
})));
|
|
33
|
+
const StyledInput=addStyle("input");const TextField=props=>{const{id,type="text",value,name,disabled=false,error,validate,onValidate,required,placeholder,style,testId,readOnly,autoFocus,autoComplete,forwardedRef,instantValidation=true,onKeyDown,onChange,onFocus,onBlur,...otherProps}=props;const{errorMessage,onBlurValidation,onChangeValidation}=useFieldValidation({value,required,disabled,instantValidation,validate,onValidate});const hasError=error||!!errorMessage;const handleChange=event=>{const newValue=event.target.value;onChangeValidation(newValue);onChange(newValue);};const handleFocus=event=>{if(onFocus){onFocus(event);}};const handleBlur=event=>{onBlurValidation(event.target.value);if(onBlur){onBlur(event);}};return jsx(Id,{id:id,children:uniqueId=>jsx(StyledInput,{style:[styles$2.input,styles$7.LabelMedium,styles$2.default,!disabled&&styles$2.defaultFocus,disabled&&styles$2.disabled,hasError&&styles$2.error,style],id:uniqueId,type:type,placeholder:placeholder,value:value,name:name,"aria-disabled":disabled,"aria-required":!!required,onChange:handleChange,onKeyDown:disabled?undefined:onKeyDown,onFocus:handleFocus,onBlur:handleBlur,"data-testid":testId,readOnly:readOnly||disabled,autoFocus:autoFocus,autoComplete:autoComplete,ref:forwardedRef,"aria-invalid":hasError,...otherProps})})};const states$1={default:{border:semanticColor.border.strong,background:semanticColor.surface.primary,foreground:semanticColor.text.primary},disabled:{border:semanticColor.action.secondary.disabled.border,background:semanticColor.action.secondary.disabled.background,foreground:semanticColor.text.secondary},error:{border:semanticColor.status.critical.foreground,background:semanticColor.status.critical.background,foreground:semanticColor.text.primary}};const styles$2=StyleSheet.create({input:{width:"100%",height:40,borderRadius:border.radius.radius_040,boxSizing:"border-box",paddingLeft:spacing.medium_16,margin:0},default:{background:states$1.default.background,border:`${border.width.thin} solid ${states$1.default.border}`,color:states$1.default.foreground,"::placeholder":{color:semanticColor.text.secondary}},defaultFocus:{":focus-visible":{borderColor:semanticColor.focus.outer,outline:`${border.width.thin} solid ${semanticColor.focus.outer}`,outlineOffset:-2}},error:{background:states$1.error.background,border:`${border.width.thin} solid ${states$1.error.border}`,color:states$1.error.foreground,"::placeholder":{color:semanticColor.text.secondary},":focus-visible":{outlineColor:semanticColor.focus.outer,outline:`${border.width.medium} solid ${semanticColor.focus.outer}`}},disabled:{background:states$1.disabled.background,border:`${border.width.thin} solid ${states$1.disabled.border}`,color:states$1.disabled.foreground,"::placeholder":{color:states$1.disabled.foreground},cursor:"not-allowed",":focus-visible":{outline:`${border.width.medium} solid ${semanticColor.focus.outer}`,outlineOffset:-3}}});var TextField$1 = React.forwardRef((props,ref)=>jsx(TextField,{...props,forwardedRef:ref}));
|
|
797
34
|
|
|
798
|
-
const StyledSpan
|
|
799
|
-
class FieldHeading extends React.Component {
|
|
800
|
-
renderLabel() {
|
|
801
|
-
const {
|
|
802
|
-
label,
|
|
803
|
-
id,
|
|
804
|
-
required,
|
|
805
|
-
testId
|
|
806
|
-
} = this.props;
|
|
807
|
-
const requiredIcon = React.createElement(StyledSpan, {
|
|
808
|
-
style: styles$1.required,
|
|
809
|
-
"aria-hidden": true
|
|
810
|
-
}, " ", "*");
|
|
811
|
-
return React.createElement(React.Fragment, null, React.createElement(LabelMedium, {
|
|
812
|
-
style: styles$1.label,
|
|
813
|
-
tag: "label",
|
|
814
|
-
htmlFor: id && `${id}-field`,
|
|
815
|
-
testId: testId && `${testId}-label`
|
|
816
|
-
}, label, required && requiredIcon), React.createElement(Strut, {
|
|
817
|
-
size: spacing.xxxSmall_4
|
|
818
|
-
}));
|
|
819
|
-
}
|
|
820
|
-
maybeRenderDescription() {
|
|
821
|
-
const {
|
|
822
|
-
description,
|
|
823
|
-
testId
|
|
824
|
-
} = this.props;
|
|
825
|
-
if (!description) {
|
|
826
|
-
return null;
|
|
827
|
-
}
|
|
828
|
-
return React.createElement(React.Fragment, null, React.createElement(LabelSmall, {
|
|
829
|
-
style: styles$1.description,
|
|
830
|
-
testId: testId && `${testId}-description`
|
|
831
|
-
}, description), React.createElement(Strut, {
|
|
832
|
-
size: spacing.xxxSmall_4
|
|
833
|
-
}));
|
|
834
|
-
}
|
|
835
|
-
maybeRenderError() {
|
|
836
|
-
const {
|
|
837
|
-
error,
|
|
838
|
-
id,
|
|
839
|
-
testId
|
|
840
|
-
} = this.props;
|
|
841
|
-
if (!error) {
|
|
842
|
-
return null;
|
|
843
|
-
}
|
|
844
|
-
return React.createElement(React.Fragment, null, React.createElement(Strut, {
|
|
845
|
-
size: spacing.small_12
|
|
846
|
-
}), React.createElement(LabelSmall, {
|
|
847
|
-
style: styles$1.error,
|
|
848
|
-
role: "alert",
|
|
849
|
-
id: id && `${id}-error`,
|
|
850
|
-
testId: testId && `${testId}-error`
|
|
851
|
-
}, error));
|
|
852
|
-
}
|
|
853
|
-
render() {
|
|
854
|
-
const {
|
|
855
|
-
field,
|
|
856
|
-
style
|
|
857
|
-
} = this.props;
|
|
858
|
-
return React.createElement(View, {
|
|
859
|
-
style: style
|
|
860
|
-
}, this.renderLabel(), this.maybeRenderDescription(), React.createElement(Strut, {
|
|
861
|
-
size: spacing.xSmall_8
|
|
862
|
-
}), field, this.maybeRenderError());
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
const styles$1 = StyleSheet.create({
|
|
866
|
-
label: {
|
|
867
|
-
color: semanticColor.text.primary
|
|
868
|
-
},
|
|
869
|
-
description: {
|
|
870
|
-
color: semanticColor.text.secondary
|
|
871
|
-
},
|
|
872
|
-
error: {
|
|
873
|
-
color: semanticColor.status.critical.foreground
|
|
874
|
-
},
|
|
875
|
-
required: {
|
|
876
|
-
color: semanticColor.status.critical.foreground
|
|
877
|
-
}
|
|
878
|
-
});
|
|
35
|
+
const StyledSpan=addStyle("span");class FieldHeading extends React.Component{renderLabel(){const{label,id,required,testId}=this.props;const requiredIcon=jsxs(StyledSpan,{style:styles$1.required,"aria-hidden":true,children:[" ","*"]});return jsxs(React.Fragment,{children:[jsxs(LabelMedium,{style:styles$1.label,tag:"label",htmlFor:id&&`${id}-field`,testId:testId&&`${testId}-label`,children:[label,required&&requiredIcon]}),jsx(Strut,{size:spacing.xxxSmall_4})]})}maybeRenderDescription(){const{description,testId}=this.props;if(!description){return null}return jsxs(React.Fragment,{children:[jsx(LabelSmall,{style:styles$1.description,testId:testId&&`${testId}-description`,children:description}),jsx(Strut,{size:spacing.xxxSmall_4})]})}maybeRenderError(){const{error,id,testId}=this.props;if(!error){return null}return jsxs(React.Fragment,{children:[jsx(Strut,{size:spacing.small_12}),jsx(LabelSmall,{style:styles$1.error,role:"alert",id:id&&`${id}-error`,testId:testId&&`${testId}-error`,children:error})]})}render(){const{field,style}=this.props;return jsxs(View,{style:style,children:[this.renderLabel(),this.maybeRenderDescription(),jsx(Strut,{size:spacing.xSmall_8}),field,this.maybeRenderError()]})}}const styles$1=StyleSheet.create({label:{color:semanticColor.text.primary},description:{color:semanticColor.text.secondary},error:{color:semanticColor.status.critical.foreground},required:{color:semanticColor.status.critical.foreground}});
|
|
879
36
|
|
|
880
|
-
|
|
881
|
-
class LabeledTextField extends React.Component {
|
|
882
|
-
constructor(props) {
|
|
883
|
-
super(props);
|
|
884
|
-
this.handleValidate = errorMessage => {
|
|
885
|
-
const {
|
|
886
|
-
onValidate
|
|
887
|
-
} = this.props;
|
|
888
|
-
this.setState({
|
|
889
|
-
error: errorMessage
|
|
890
|
-
}, () => {
|
|
891
|
-
if (onValidate) {
|
|
892
|
-
onValidate(errorMessage);
|
|
893
|
-
}
|
|
894
|
-
});
|
|
895
|
-
};
|
|
896
|
-
this.handleFocus = event => {
|
|
897
|
-
const {
|
|
898
|
-
onFocus
|
|
899
|
-
} = this.props;
|
|
900
|
-
this.setState({
|
|
901
|
-
focused: true
|
|
902
|
-
}, () => {
|
|
903
|
-
if (onFocus) {
|
|
904
|
-
onFocus(event);
|
|
905
|
-
}
|
|
906
|
-
});
|
|
907
|
-
};
|
|
908
|
-
this.handleBlur = event => {
|
|
909
|
-
const {
|
|
910
|
-
onBlur
|
|
911
|
-
} = this.props;
|
|
912
|
-
this.setState({
|
|
913
|
-
focused: false
|
|
914
|
-
}, () => {
|
|
915
|
-
if (onBlur) {
|
|
916
|
-
onBlur(event);
|
|
917
|
-
}
|
|
918
|
-
});
|
|
919
|
-
};
|
|
920
|
-
this.state = {
|
|
921
|
-
error: null,
|
|
922
|
-
focused: false
|
|
923
|
-
};
|
|
924
|
-
}
|
|
925
|
-
render() {
|
|
926
|
-
const _this$props = this.props,
|
|
927
|
-
{
|
|
928
|
-
id,
|
|
929
|
-
type,
|
|
930
|
-
label,
|
|
931
|
-
description,
|
|
932
|
-
value,
|
|
933
|
-
disabled,
|
|
934
|
-
required,
|
|
935
|
-
validate,
|
|
936
|
-
onChange,
|
|
937
|
-
onKeyDown,
|
|
938
|
-
placeholder,
|
|
939
|
-
style,
|
|
940
|
-
testId,
|
|
941
|
-
readOnly,
|
|
942
|
-
autoComplete,
|
|
943
|
-
forwardedRef,
|
|
944
|
-
ariaDescribedby,
|
|
945
|
-
name
|
|
946
|
-
} = _this$props,
|
|
947
|
-
otherProps = _objectWithoutPropertiesLoose(_this$props, _excluded$1);
|
|
948
|
-
return React.createElement(Id, {
|
|
949
|
-
id: id
|
|
950
|
-
}, uniqueId => React.createElement(FieldHeading, {
|
|
951
|
-
id: uniqueId,
|
|
952
|
-
testId: testId,
|
|
953
|
-
style: style,
|
|
954
|
-
field: React.createElement(TextField$1, _extends({
|
|
955
|
-
id: `${uniqueId}-field`,
|
|
956
|
-
"aria-describedby": ariaDescribedby ? ariaDescribedby : `${uniqueId}-error`,
|
|
957
|
-
"aria-required": required ? "true" : "false",
|
|
958
|
-
required: required,
|
|
959
|
-
testId: testId && `${testId}-field`,
|
|
960
|
-
type: type,
|
|
961
|
-
value: value,
|
|
962
|
-
placeholder: placeholder,
|
|
963
|
-
disabled: disabled,
|
|
964
|
-
validate: validate,
|
|
965
|
-
onValidate: this.handleValidate,
|
|
966
|
-
onChange: onChange,
|
|
967
|
-
onKeyDown: onKeyDown,
|
|
968
|
-
onFocus: this.handleFocus,
|
|
969
|
-
onBlur: this.handleBlur,
|
|
970
|
-
readOnly: readOnly,
|
|
971
|
-
autoComplete: autoComplete,
|
|
972
|
-
ref: forwardedRef,
|
|
973
|
-
name: name
|
|
974
|
-
}, otherProps)),
|
|
975
|
-
label: label,
|
|
976
|
-
description: description,
|
|
977
|
-
required: !!required,
|
|
978
|
-
error: !this.state.focused && this.state.error || ""
|
|
979
|
-
}));
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
LabeledTextField.defaultProps = {
|
|
983
|
-
type: "text",
|
|
984
|
-
disabled: false
|
|
985
|
-
};
|
|
986
|
-
var labeledTextField = React.forwardRef((props, ref) => React.createElement(LabeledTextField, _extends({}, props, {
|
|
987
|
-
forwardedRef: ref
|
|
988
|
-
})));
|
|
37
|
+
class LabeledTextField extends React.Component{render(){const{id,type,label,description,value,disabled,required,validate,onChange,onKeyDown,placeholder,style,testId,readOnly,autoComplete,forwardedRef,ariaDescribedby,name,onValidate,onFocus,onBlur,...otherProps}=this.props;return jsx(Id,{id:id,children:uniqueId=>jsx(FieldHeading,{id:uniqueId,testId:testId,style:style,field:jsx(TextField$1,{id:`${uniqueId}-field`,"aria-describedby":ariaDescribedby?ariaDescribedby:`${uniqueId}-error`,"aria-required":required?"true":"false",required:required,testId:testId&&`${testId}-field`,type:type,value:value,placeholder:placeholder,disabled:disabled,validate:validate,onValidate:this.handleValidate,onChange:onChange,onKeyDown:onKeyDown,onFocus:this.handleFocus,onBlur:this.handleBlur,readOnly:readOnly,autoComplete:autoComplete,ref:forwardedRef,name:name,...otherProps}),label:label,description:description,required:!!required,error:!this.state.focused&&this.state.error||""})})}constructor(props){super(props),this.handleValidate=errorMessage=>{const{onValidate}=this.props;this.setState({error:errorMessage},()=>{if(onValidate){onValidate(errorMessage);}});},this.handleFocus=event=>{const{onFocus}=this.props;this.setState({focused:true},()=>{if(onFocus){onFocus(event);}});},this.handleBlur=event=>{const{onBlur}=this.props;this.setState({focused:false},()=>{if(onBlur){onBlur(event);}});};this.state={error:null,focused:false};}}LabeledTextField.defaultProps={type:"text",disabled:false};var labeledTextField = React.forwardRef((props,ref)=>jsx(LabeledTextField,{...props,forwardedRef:ref}));
|
|
989
38
|
|
|
990
|
-
const
|
|
991
|
-
const StyledTextarea = addStyle("textarea");
|
|
992
|
-
const TextArea = React.forwardRef(function TextArea(props, ref) {
|
|
993
|
-
const {
|
|
994
|
-
onChange,
|
|
995
|
-
value,
|
|
996
|
-
placeholder,
|
|
997
|
-
disabled,
|
|
998
|
-
id,
|
|
999
|
-
testId,
|
|
1000
|
-
style,
|
|
1001
|
-
readOnly,
|
|
1002
|
-
autoComplete,
|
|
1003
|
-
name,
|
|
1004
|
-
className,
|
|
1005
|
-
autoFocus,
|
|
1006
|
-
rows,
|
|
1007
|
-
spellCheck,
|
|
1008
|
-
wrap,
|
|
1009
|
-
minLength,
|
|
1010
|
-
maxLength,
|
|
1011
|
-
onClick,
|
|
1012
|
-
onKeyDown,
|
|
1013
|
-
onKeyUp,
|
|
1014
|
-
onFocus,
|
|
1015
|
-
onBlur,
|
|
1016
|
-
validate,
|
|
1017
|
-
onValidate,
|
|
1018
|
-
required,
|
|
1019
|
-
resizeType,
|
|
1020
|
-
rootStyle,
|
|
1021
|
-
error,
|
|
1022
|
-
instantValidation = true
|
|
1023
|
-
} = props,
|
|
1024
|
-
otherProps = _objectWithoutPropertiesLoose(props, _excluded);
|
|
1025
|
-
const {
|
|
1026
|
-
errorMessage,
|
|
1027
|
-
onBlurValidation,
|
|
1028
|
-
onChangeValidation
|
|
1029
|
-
} = useFieldValidation({
|
|
1030
|
-
value,
|
|
1031
|
-
disabled,
|
|
1032
|
-
validate,
|
|
1033
|
-
onValidate,
|
|
1034
|
-
required,
|
|
1035
|
-
instantValidation
|
|
1036
|
-
});
|
|
1037
|
-
const hasError = error || !!errorMessage;
|
|
1038
|
-
const generatedUniqueId = useId();
|
|
1039
|
-
const uniqueId = id != null ? id : generatedUniqueId;
|
|
1040
|
-
const handleChange = event => {
|
|
1041
|
-
const newValue = event.target.value;
|
|
1042
|
-
onChangeValidation(newValue);
|
|
1043
|
-
onChange(newValue);
|
|
1044
|
-
};
|
|
1045
|
-
const handleBlur = event => {
|
|
1046
|
-
onBlurValidation(event.target.value);
|
|
1047
|
-
if (onBlur) {
|
|
1048
|
-
onBlur(event);
|
|
1049
|
-
}
|
|
1050
|
-
};
|
|
1051
|
-
return React.createElement(View, {
|
|
1052
|
-
style: [{
|
|
1053
|
-
width: "100%"
|
|
1054
|
-
}, rootStyle]
|
|
1055
|
-
}, React.createElement(StyledTextarea, _extends({
|
|
1056
|
-
id: uniqueId,
|
|
1057
|
-
"data-testid": testId,
|
|
1058
|
-
ref: ref,
|
|
1059
|
-
className: className,
|
|
1060
|
-
style: [styles.textarea, styles$7.LabelMedium, resizeType && resizeStyles[resizeType], styles.default, !disabled && styles.defaultFocus, disabled && styles.disabled, hasError && styles.error, style],
|
|
1061
|
-
value: value,
|
|
1062
|
-
onChange: handleChange,
|
|
1063
|
-
placeholder: placeholder,
|
|
1064
|
-
"aria-disabled": disabled,
|
|
1065
|
-
readOnly: readOnly || disabled,
|
|
1066
|
-
autoComplete: autoComplete,
|
|
1067
|
-
name: name,
|
|
1068
|
-
autoFocus: autoFocus,
|
|
1069
|
-
rows: rows,
|
|
1070
|
-
spellCheck: spellCheck,
|
|
1071
|
-
wrap: wrap,
|
|
1072
|
-
minLength: minLength,
|
|
1073
|
-
maxLength: maxLength,
|
|
1074
|
-
"aria-required": !!required,
|
|
1075
|
-
onClick: disabled ? undefined : onClick,
|
|
1076
|
-
onKeyDown: disabled ? undefined : onKeyDown,
|
|
1077
|
-
onKeyUp: disabled ? undefined : onKeyUp,
|
|
1078
|
-
onFocus: onFocus,
|
|
1079
|
-
onBlur: handleBlur,
|
|
1080
|
-
required: !!required
|
|
1081
|
-
}, otherProps, {
|
|
1082
|
-
"aria-invalid": hasError
|
|
1083
|
-
})));
|
|
1084
|
-
});
|
|
1085
|
-
const VERTICAL_SPACING_PX = 10;
|
|
1086
|
-
const states = {
|
|
1087
|
-
default: {
|
|
1088
|
-
border: semanticColor.border.strong,
|
|
1089
|
-
background: semanticColor.surface.primary,
|
|
1090
|
-
foreground: semanticColor.text.primary
|
|
1091
|
-
},
|
|
1092
|
-
disabled: {
|
|
1093
|
-
border: semanticColor.action.secondary.disabled.border,
|
|
1094
|
-
background: semanticColor.action.secondary.disabled.background,
|
|
1095
|
-
foreground: semanticColor.text.secondary
|
|
1096
|
-
},
|
|
1097
|
-
error: {
|
|
1098
|
-
border: semanticColor.status.critical.foreground,
|
|
1099
|
-
background: semanticColor.status.critical.background,
|
|
1100
|
-
foreground: semanticColor.text.primary
|
|
1101
|
-
}
|
|
1102
|
-
};
|
|
1103
|
-
const styles = StyleSheet.create({
|
|
1104
|
-
textarea: {
|
|
1105
|
-
borderRadius: border.radius.radius_040,
|
|
1106
|
-
boxSizing: "border-box",
|
|
1107
|
-
padding: `${VERTICAL_SPACING_PX}px ${spacing.medium_16}px`,
|
|
1108
|
-
minHeight: `${VERTICAL_SPACING_PX * 2 + font.lineHeight.medium + 2}px`
|
|
1109
|
-
},
|
|
1110
|
-
default: {
|
|
1111
|
-
background: states.default.background,
|
|
1112
|
-
border: `${border.width.thin} solid ${states.default.border}`,
|
|
1113
|
-
color: states.default.foreground,
|
|
1114
|
-
"::placeholder": {
|
|
1115
|
-
color: semanticColor.text.secondary
|
|
1116
|
-
}
|
|
1117
|
-
},
|
|
1118
|
-
defaultFocus: {
|
|
1119
|
-
":focus-visible": {
|
|
1120
|
-
borderColor: semanticColor.focus.outer,
|
|
1121
|
-
outline: `${border.width.thin} solid ${semanticColor.focus.outer}`,
|
|
1122
|
-
outlineOffset: -2
|
|
1123
|
-
}
|
|
1124
|
-
},
|
|
1125
|
-
disabled: {
|
|
1126
|
-
background: states.disabled.background,
|
|
1127
|
-
border: `${border.width.thin} solid ${states.disabled.border}`,
|
|
1128
|
-
color: states.disabled.foreground,
|
|
1129
|
-
"::placeholder": {
|
|
1130
|
-
color: states.disabled.foreground
|
|
1131
|
-
},
|
|
1132
|
-
cursor: "not-allowed",
|
|
1133
|
-
":focus-visible": {
|
|
1134
|
-
outline: `${border.width.medium} solid ${semanticColor.focus.outer}`,
|
|
1135
|
-
outlineOffset: -3
|
|
1136
|
-
}
|
|
1137
|
-
},
|
|
1138
|
-
error: {
|
|
1139
|
-
background: states.error.background,
|
|
1140
|
-
border: `${border.width.thin} solid ${states.error.border}`,
|
|
1141
|
-
color: states.error.foreground,
|
|
1142
|
-
"::placeholder": {
|
|
1143
|
-
color: semanticColor.text.secondary
|
|
1144
|
-
},
|
|
1145
|
-
":focus-visible": {
|
|
1146
|
-
outline: `${border.width.medium} solid ${semanticColor.focus.outer}`,
|
|
1147
|
-
borderColor: states.error.border
|
|
1148
|
-
}
|
|
1149
|
-
}
|
|
1150
|
-
});
|
|
1151
|
-
const resizeStyles = StyleSheet.create({
|
|
1152
|
-
both: {
|
|
1153
|
-
resize: "both"
|
|
1154
|
-
},
|
|
1155
|
-
none: {
|
|
1156
|
-
resize: "none"
|
|
1157
|
-
},
|
|
1158
|
-
horizontal: {
|
|
1159
|
-
resize: "horizontal"
|
|
1160
|
-
},
|
|
1161
|
-
vertical: {
|
|
1162
|
-
resize: "vertical"
|
|
1163
|
-
}
|
|
1164
|
-
});
|
|
39
|
+
const StyledTextarea=addStyle("textarea");const TextArea=React.forwardRef(function TextArea(props,ref){const{onChange,value,placeholder,disabled,id,testId,style,readOnly,autoComplete,name,className,autoFocus,rows,spellCheck,wrap,minLength,maxLength,onClick,onKeyDown,onKeyUp,onFocus,onBlur,validate,onValidate,required,resizeType,rootStyle,error,instantValidation=true,...otherProps}=props;const{errorMessage,onBlurValidation,onChangeValidation}=useFieldValidation({value,disabled,validate,onValidate,required,instantValidation});const hasError=error||!!errorMessage;const generatedUniqueId=useId();const uniqueId=id??generatedUniqueId;const handleChange=event=>{const newValue=event.target.value;onChangeValidation(newValue);onChange(newValue);};const handleBlur=event=>{onBlurValidation(event.target.value);if(onBlur){onBlur(event);}};return jsx(View,{style:[{width:"100%"},rootStyle],children:jsx(StyledTextarea,{id:uniqueId,"data-testid":testId,ref:ref,className:className,style:[styles.textarea,styles$7.LabelMedium,resizeType&&resizeStyles[resizeType],styles.default,!disabled&&styles.defaultFocus,disabled&&styles.disabled,hasError&&styles.error,style],value:value,onChange:handleChange,placeholder:placeholder,"aria-disabled":disabled,readOnly:readOnly||disabled,autoComplete:autoComplete,name:name,autoFocus:autoFocus,rows:rows,spellCheck:spellCheck,wrap:wrap,minLength:minLength,maxLength:maxLength,"aria-required":!!required,onClick:disabled?undefined:onClick,onKeyDown:disabled?undefined:onKeyDown,onKeyUp:disabled?undefined:onKeyUp,onFocus:onFocus,onBlur:handleBlur,required:!!required,...otherProps,"aria-invalid":hasError})})});const VERTICAL_SPACING_PX=10;const states={default:{border:semanticColor.border.strong,background:semanticColor.surface.primary,foreground:semanticColor.text.primary},disabled:{border:semanticColor.action.secondary.disabled.border,background:semanticColor.action.secondary.disabled.background,foreground:semanticColor.text.secondary},error:{border:semanticColor.status.critical.foreground,background:semanticColor.status.critical.background,foreground:semanticColor.text.primary}};const styles=StyleSheet.create({textarea:{borderRadius:border.radius.radius_040,boxSizing:"border-box",padding:`${VERTICAL_SPACING_PX}px ${spacing.medium_16}px`,minHeight:`calc(${VERTICAL_SPACING_PX*2+2}px + ${font.lineHeight.medium})`},default:{background:states.default.background,border:`${border.width.thin} solid ${states.default.border}`,color:states.default.foreground,"::placeholder":{color:semanticColor.text.secondary}},defaultFocus:{":focus-visible":{borderColor:semanticColor.focus.outer,outline:`${border.width.thin} solid ${semanticColor.focus.outer}`,outlineOffset:-2}},disabled:{background:states.disabled.background,border:`${border.width.thin} solid ${states.disabled.border}`,color:states.disabled.foreground,"::placeholder":{color:states.disabled.foreground},cursor:"not-allowed",":focus-visible":{outline:`${border.width.medium} solid ${semanticColor.focus.outer}`,outlineOffset:-3}},error:{background:states.error.background,border:`${border.width.thin} solid ${states.error.border}`,color:states.error.foreground,"::placeholder":{color:semanticColor.text.secondary},":focus-visible":{outline:`${border.width.medium} solid ${semanticColor.focus.outer}`,borderColor:states.error.border}}});const resizeStyles=StyleSheet.create({both:{resize:"both"},none:{resize:"none"},horizontal:{resize:"horizontal"},vertical:{resize:"vertical"}});
|
|
1165
40
|
|
|
1166
41
|
export { Checkbox, CheckboxGroup, Choice, labeledTextField as LabeledTextField, RadioGroup, TextArea, TextField$1 as TextField };
|