@mirohq/design-system-input 0.2.9 → 0.2.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/dist/main.js +114 -565
- package/dist/main.js.map +1 -1
- package/dist/module.js +109 -560
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +38 -126
- package/package.json +8 -8
package/dist/module.js
CHANGED
|
@@ -1,183 +1,9 @@
|
|
|
1
1
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
2
|
-
import React, {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { styled } from '@mirohq/design-system-stitches';
|
|
7
|
-
import { Primitive } from '@mirohq/design-system-primitive';
|
|
8
|
-
import { Tooltip } from '@mirohq/design-system-tooltip';
|
|
9
|
-
import { BaseButton } from '@mirohq/design-system-base-button';
|
|
10
|
-
import { focus } from '@mirohq/design-system-styles';
|
|
11
|
-
import { IconCross, IconExclamationPointCircle, IconCheckMark, IconLockClosed, IconEyeOpen, IconEyeClosed, IconEnvelope, IconMagnifyingGlass } from '@mirohq/design-system-icons';
|
|
2
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { useInputContext, BaseInput } from '@mirohq/design-system-base-input';
|
|
4
|
+
import { IconCross, IconLockClosed, IconEyeOpen, IconEyeClosed, IconEnvelope, IconMagnifyingGlass } from '@mirohq/design-system-icons';
|
|
5
|
+
import { booleanify, stringAttrValue, mergeRefs } from '@mirohq/design-system-utils';
|
|
12
6
|
import { useFormFieldContext, FloatingLabel } from '@mirohq/design-system-base-form';
|
|
13
|
-
import { usePress } from '@mirohq/design-system-use-press';
|
|
14
|
-
import { useHover } from '@react-aria/interactions';
|
|
15
|
-
import { mergeProps } from '@react-aria/utils';
|
|
16
|
-
import { styles } from '@mirohq/design-system-base-input';
|
|
17
|
-
import { useAriaDisabled } from '@mirohq/design-system-use-aria-disabled';
|
|
18
|
-
|
|
19
|
-
const StyledIconSlot = styled(Primitive.div, {
|
|
20
|
-
order: 1,
|
|
21
|
-
alignContent: "center",
|
|
22
|
-
display: "flex",
|
|
23
|
-
justifyContent: "center",
|
|
24
|
-
color: "$icon-neutrals-subtle",
|
|
25
|
-
"& svg, & img": {
|
|
26
|
-
pointerEvents: "none"
|
|
27
|
-
},
|
|
28
|
-
variants: {
|
|
29
|
-
disabled: {
|
|
30
|
-
true: {
|
|
31
|
-
"& svg": {
|
|
32
|
-
color: "$icon-neutrals-disabled"
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
const InputContext = createContext({});
|
|
40
|
-
const InputProvider = ({
|
|
41
|
-
children,
|
|
42
|
-
disabled,
|
|
43
|
-
"aria-disabled": ariaDisabled,
|
|
44
|
-
readOnly,
|
|
45
|
-
required,
|
|
46
|
-
valid,
|
|
47
|
-
...restProps
|
|
48
|
-
}) => {
|
|
49
|
-
const actionButtonRef = useRef(null);
|
|
50
|
-
const inputRef = useRef(null);
|
|
51
|
-
const [focused, setFocused] = useState(false);
|
|
52
|
-
const [hovered, setHovered] = useState(false);
|
|
53
|
-
const [hasIconSlot, setHasIconSlot] = useState(false);
|
|
54
|
-
const editable = !booleanify(disabled) && !booleanify(ariaDisabled) && !booleanify(readOnly);
|
|
55
|
-
return /* @__PURE__ */ jsx(
|
|
56
|
-
InputContext.Provider,
|
|
57
|
-
{
|
|
58
|
-
value: {
|
|
59
|
-
...restProps,
|
|
60
|
-
setFocused,
|
|
61
|
-
setHovered,
|
|
62
|
-
setHasIconSlot,
|
|
63
|
-
hasIconSlot,
|
|
64
|
-
hovered,
|
|
65
|
-
focused,
|
|
66
|
-
disabled,
|
|
67
|
-
"aria-disabled": ariaDisabled,
|
|
68
|
-
readOnly,
|
|
69
|
-
editable,
|
|
70
|
-
inputRef,
|
|
71
|
-
actionButtonRef,
|
|
72
|
-
required,
|
|
73
|
-
valid
|
|
74
|
-
},
|
|
75
|
-
children
|
|
76
|
-
}
|
|
77
|
-
);
|
|
78
|
-
};
|
|
79
|
-
const useInputContext = () => useContext(InputContext);
|
|
80
|
-
|
|
81
|
-
const IconSlot = React.forwardRef(({ children, ...restProps }, forwardRef) => {
|
|
82
|
-
const {
|
|
83
|
-
"aria-disabled": ariaDisabled,
|
|
84
|
-
disabled,
|
|
85
|
-
setHasIconSlot
|
|
86
|
-
} = useInputContext();
|
|
87
|
-
const formattedChildren = addPropsToChildren(children, isIconComponent, {
|
|
88
|
-
size: "small",
|
|
89
|
-
weight: "thin",
|
|
90
|
-
"aria-hidden": true
|
|
91
|
-
});
|
|
92
|
-
useLayoutEffect(() => {
|
|
93
|
-
setHasIconSlot(true);
|
|
94
|
-
return () => setHasIconSlot(false);
|
|
95
|
-
}, [setHasIconSlot]);
|
|
96
|
-
return /* @__PURE__ */ jsx(
|
|
97
|
-
StyledIconSlot,
|
|
98
|
-
{
|
|
99
|
-
...restProps,
|
|
100
|
-
disabled: booleanify(disabled != null ? disabled : ariaDisabled),
|
|
101
|
-
ref: forwardRef,
|
|
102
|
-
children: formattedChildren
|
|
103
|
-
}
|
|
104
|
-
);
|
|
105
|
-
});
|
|
106
|
-
IconSlot.displayName = "IconSlot";
|
|
107
|
-
|
|
108
|
-
const StyledActionButton = styled(BaseButton, {
|
|
109
|
-
backgroundColor: "transparent",
|
|
110
|
-
color: "$icon-neutrals-subtle",
|
|
111
|
-
display: "flex",
|
|
112
|
-
justifyContent: "center",
|
|
113
|
-
order: 3,
|
|
114
|
-
padding: "6px",
|
|
115
|
-
square: "$7",
|
|
116
|
-
"& svg:not([data-icon-component]), & img:not([data-icon-component])": {
|
|
117
|
-
square: "$icon-200",
|
|
118
|
-
"--svg-stroke-width": "$stroke-width$thin"
|
|
119
|
-
},
|
|
120
|
-
...focus.css({
|
|
121
|
-
boxShadow: "$focus-small"
|
|
122
|
-
}),
|
|
123
|
-
"&:hover": {
|
|
124
|
-
backgroundColor: "$background-neutrals-subtle-hover"
|
|
125
|
-
},
|
|
126
|
-
"&:active, &[data-pressed]": {
|
|
127
|
-
backgroundColor: "$background-neutrals-subtle-active"
|
|
128
|
-
},
|
|
129
|
-
variants: {
|
|
130
|
-
readOnlyAppearance: {
|
|
131
|
-
true: {
|
|
132
|
-
"& svg[data-icon-component], & img[data-icon-component]": {
|
|
133
|
-
color: "$icon-neutrals-subtle"
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
disableAppearance: {
|
|
138
|
-
true: {
|
|
139
|
-
color: "$icon-neutrals-disabled"
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
const ActionButton = React.forwardRef(({ "aria-label": ariaLabel, label, children, ...restProps }, forwardRef) => {
|
|
146
|
-
const {
|
|
147
|
-
valid,
|
|
148
|
-
hovered,
|
|
149
|
-
editable,
|
|
150
|
-
"aria-disabled": ariaDisabled,
|
|
151
|
-
disabled,
|
|
152
|
-
readOnly,
|
|
153
|
-
actionButtonRef
|
|
154
|
-
} = useInputContext();
|
|
155
|
-
const showInputSlot = valid === void 0 || booleanify(hovered);
|
|
156
|
-
let formattedChildren = children;
|
|
157
|
-
formattedChildren = addPropsToChildren(children, isIconComponent, {
|
|
158
|
-
"aria-hidden": true
|
|
159
|
-
});
|
|
160
|
-
const hasPressEvent = Object.keys(restProps).some(
|
|
161
|
-
(key) => key.startsWith("onPress")
|
|
162
|
-
);
|
|
163
|
-
const customDisabled = restProps.disabled;
|
|
164
|
-
return /* @__PURE__ */ jsx(Fragment, { children: showInputSlot && /* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
165
|
-
/* @__PURE__ */ jsx(Tooltip.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
166
|
-
StyledActionButton,
|
|
167
|
-
{
|
|
168
|
-
type: "button",
|
|
169
|
-
...restProps,
|
|
170
|
-
"aria-label": ariaLabel != null ? ariaLabel : label,
|
|
171
|
-
disabled: hasPressEvent ? customDisabled : customDisabled != null ? customDisabled : !editable,
|
|
172
|
-
disableAppearance: hasPressEvent ? !booleanify(readOnly) && customDisabled : booleanify(disabled != null ? disabled : ariaDisabled),
|
|
173
|
-
readOnlyAppearance: readOnly,
|
|
174
|
-
ref: mergeRefs([forwardRef, actionButtonRef]),
|
|
175
|
-
children: formattedChildren
|
|
176
|
-
}
|
|
177
|
-
) }),
|
|
178
|
-
/* @__PURE__ */ jsx(Tooltip.Content, { children: label })
|
|
179
|
-
] }) });
|
|
180
|
-
});
|
|
181
7
|
|
|
182
8
|
const createSyntheticChangeEvent = (inputRef) => {
|
|
183
9
|
const event = {
|
|
@@ -214,7 +40,7 @@ const ClearAction = ({
|
|
|
214
40
|
if (!clearable)
|
|
215
41
|
return /* @__PURE__ */ jsx(Fragment, {});
|
|
216
42
|
return /* @__PURE__ */ jsx(
|
|
217
|
-
ActionButton,
|
|
43
|
+
BaseInput.ActionButton,
|
|
218
44
|
{
|
|
219
45
|
label: clearLabel,
|
|
220
46
|
disabled: booleanify((_a = disabled != null ? disabled : ariaDisabled) != null ? _a : readOnly),
|
|
@@ -233,367 +59,6 @@ const ClearAction = ({
|
|
|
233
59
|
);
|
|
234
60
|
};
|
|
235
61
|
|
|
236
|
-
const StyledIconExclamationPointCircle = styled(
|
|
237
|
-
IconExclamationPointCircle,
|
|
238
|
-
{
|
|
239
|
-
color: "$icon-danger"
|
|
240
|
-
}
|
|
241
|
-
);
|
|
242
|
-
const StyledIconCheckMark = styled(IconCheckMark, {
|
|
243
|
-
color: "$icon-success"
|
|
244
|
-
});
|
|
245
|
-
const StyledValidityBox = styled(Primitive.div, {
|
|
246
|
-
order: 3,
|
|
247
|
-
display: "flex",
|
|
248
|
-
alignItems: "center",
|
|
249
|
-
padding: "6px"
|
|
250
|
-
});
|
|
251
|
-
const StyledBaseInput = styled("div", {
|
|
252
|
-
position: "relative",
|
|
253
|
-
alignItems: "center",
|
|
254
|
-
display: "inline-flex",
|
|
255
|
-
height: "max-content",
|
|
256
|
-
boxSizing: "border-box",
|
|
257
|
-
width: "100%",
|
|
258
|
-
...styles.variants.idle,
|
|
259
|
-
variants: {
|
|
260
|
-
hovered: {
|
|
261
|
-
true: {},
|
|
262
|
-
false: {}
|
|
263
|
-
},
|
|
264
|
-
focused: {
|
|
265
|
-
true: styles.variants.focused,
|
|
266
|
-
false: {}
|
|
267
|
-
},
|
|
268
|
-
valid: {
|
|
269
|
-
true: {},
|
|
270
|
-
false: {}
|
|
271
|
-
},
|
|
272
|
-
readOnly: {
|
|
273
|
-
true: styles.variants.readOnly,
|
|
274
|
-
false: {}
|
|
275
|
-
},
|
|
276
|
-
disabled: {
|
|
277
|
-
true: styles.variants.disabled,
|
|
278
|
-
false: {}
|
|
279
|
-
},
|
|
280
|
-
ariaDisabled: {
|
|
281
|
-
true: styles.variants.disabled,
|
|
282
|
-
false: {}
|
|
283
|
-
},
|
|
284
|
-
size: {
|
|
285
|
-
large: {
|
|
286
|
-
height: "$10",
|
|
287
|
-
padding: "0 $100 ",
|
|
288
|
-
["& ".concat(StyledIconSlot)]: {
|
|
289
|
-
paddingRight: "$50"
|
|
290
|
-
},
|
|
291
|
-
["& ".concat(StyledActionButton, ", & ").concat(StyledValidityBox)]: {
|
|
292
|
-
marginLeft: "$50"
|
|
293
|
-
},
|
|
294
|
-
["& ".concat(StyledValidityBox)]: {
|
|
295
|
-
paddingRight: "6px"
|
|
296
|
-
}
|
|
297
|
-
},
|
|
298
|
-
"x-large": {
|
|
299
|
-
height: "$12",
|
|
300
|
-
padding: "0 $150",
|
|
301
|
-
["& ".concat(StyledIconSlot)]: {
|
|
302
|
-
paddingRight: "$100"
|
|
303
|
-
},
|
|
304
|
-
["& ".concat(StyledActionButton, ", & ").concat(StyledValidityBox)]: {
|
|
305
|
-
marginLeft: "$100"
|
|
306
|
-
},
|
|
307
|
-
["& ".concat(StyledValidityBox)]: {
|
|
308
|
-
paddingRight: "6px"
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
},
|
|
313
|
-
compoundVariants: [
|
|
314
|
-
/** Idle states */
|
|
315
|
-
{
|
|
316
|
-
valid: false,
|
|
317
|
-
readOnly: false,
|
|
318
|
-
disabled: false,
|
|
319
|
-
ariaDisabled: false,
|
|
320
|
-
css: styles.variants.invalid.idle
|
|
321
|
-
},
|
|
322
|
-
{
|
|
323
|
-
valid: true,
|
|
324
|
-
readOnly: false,
|
|
325
|
-
disabled: false,
|
|
326
|
-
ariaDisabled: false,
|
|
327
|
-
css: styles.variants.valid.idle
|
|
328
|
-
},
|
|
329
|
-
/** Focus States */
|
|
330
|
-
{
|
|
331
|
-
focused: true,
|
|
332
|
-
readOnly: false,
|
|
333
|
-
css: {
|
|
334
|
-
borderColor: styles.variants.focused.borderColor
|
|
335
|
-
}
|
|
336
|
-
},
|
|
337
|
-
{
|
|
338
|
-
focused: true,
|
|
339
|
-
readOnly: false,
|
|
340
|
-
valid: false,
|
|
341
|
-
disabled: false,
|
|
342
|
-
ariaDisabled: false,
|
|
343
|
-
css: styles.variants.invalid.focused
|
|
344
|
-
},
|
|
345
|
-
{
|
|
346
|
-
focused: true,
|
|
347
|
-
readOnly: false,
|
|
348
|
-
valid: true,
|
|
349
|
-
disabled: false,
|
|
350
|
-
ariaDisabled: false,
|
|
351
|
-
css: styles.variants.valid.focused
|
|
352
|
-
},
|
|
353
|
-
/** Hover states */
|
|
354
|
-
{
|
|
355
|
-
hovered: true,
|
|
356
|
-
disabled: false,
|
|
357
|
-
ariaDisabled: false,
|
|
358
|
-
readOnly: false,
|
|
359
|
-
css: styles.variants.hovered
|
|
360
|
-
},
|
|
361
|
-
{
|
|
362
|
-
hovered: true,
|
|
363
|
-
focused: false,
|
|
364
|
-
valid: false,
|
|
365
|
-
readOnly: false,
|
|
366
|
-
disabled: false,
|
|
367
|
-
ariaDisabled: false,
|
|
368
|
-
css: styles.variants.invalid.hovered
|
|
369
|
-
},
|
|
370
|
-
{
|
|
371
|
-
hovered: true,
|
|
372
|
-
focused: false,
|
|
373
|
-
valid: true,
|
|
374
|
-
readOnly: false,
|
|
375
|
-
disabled: false,
|
|
376
|
-
ariaDisabled: false,
|
|
377
|
-
css: styles.variants.valid.hovered
|
|
378
|
-
}
|
|
379
|
-
],
|
|
380
|
-
defaultVariants: {
|
|
381
|
-
size: "large"
|
|
382
|
-
}
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
const disabledAndReadonlySelectors = ':read-only, :disabled, [aria-disabled="true"], [data-disabled]';
|
|
386
|
-
const StyledInput = styled(Primitive.input, {
|
|
387
|
-
all: "unset",
|
|
388
|
-
background: "transparent",
|
|
389
|
-
color: "$text-neutrals",
|
|
390
|
-
width: "100%",
|
|
391
|
-
borderRadius: "$50",
|
|
392
|
-
order: 2,
|
|
393
|
-
padding: "0 $50",
|
|
394
|
-
height: "100%",
|
|
395
|
-
"&::placeholder": {
|
|
396
|
-
fontStyle: "italic"
|
|
397
|
-
},
|
|
398
|
-
["&:not(".concat(disabledAndReadonlySelectors, ")::placeholder")]: styles.base.placeholder,
|
|
399
|
-
"&:read-only": {
|
|
400
|
-
color: styles.variants.readOnly.color
|
|
401
|
-
},
|
|
402
|
-
"&:disabled, &[aria-disabled=true], &[data-disabled]": styles.base.disabled
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
const Input$1 = React.forwardRef(
|
|
406
|
-
({
|
|
407
|
-
id,
|
|
408
|
-
"aria-describedby": ariaDescribedBy,
|
|
409
|
-
"aria-invalid": ariaInvalid,
|
|
410
|
-
...restProps
|
|
411
|
-
}, forwardRef) => {
|
|
412
|
-
const {
|
|
413
|
-
"aria-disabled": ariaDisabled,
|
|
414
|
-
disabled,
|
|
415
|
-
setFocused,
|
|
416
|
-
inputRef,
|
|
417
|
-
required,
|
|
418
|
-
readOnly,
|
|
419
|
-
onChange
|
|
420
|
-
} = useInputContext();
|
|
421
|
-
const {
|
|
422
|
-
formElementId,
|
|
423
|
-
ariaDescribedBy: formFieldContextDescribedBy,
|
|
424
|
-
ariaInvalid: formFieldAriaInvalid,
|
|
425
|
-
formElementRef,
|
|
426
|
-
setRequired,
|
|
427
|
-
setReadOnly,
|
|
428
|
-
setDisabled,
|
|
429
|
-
setAriaDisabled
|
|
430
|
-
} = useFormFieldContext();
|
|
431
|
-
const { onBlur, onFocus, ...elementProps } = useAriaDisabled({
|
|
432
|
-
...restProps,
|
|
433
|
-
ariaDisabled
|
|
434
|
-
});
|
|
435
|
-
useEffect(() => {
|
|
436
|
-
setRequired == null ? void 0 : setRequired(required);
|
|
437
|
-
setReadOnly == null ? void 0 : setReadOnly(readOnly);
|
|
438
|
-
setDisabled == null ? void 0 : setDisabled(disabled);
|
|
439
|
-
setAriaDisabled == null ? void 0 : setAriaDisabled(ariaDisabled);
|
|
440
|
-
}, [
|
|
441
|
-
disabled,
|
|
442
|
-
ariaDisabled,
|
|
443
|
-
readOnly,
|
|
444
|
-
required,
|
|
445
|
-
ariaInvalid,
|
|
446
|
-
setRequired,
|
|
447
|
-
setReadOnly,
|
|
448
|
-
setDisabled,
|
|
449
|
-
setAriaDisabled
|
|
450
|
-
]);
|
|
451
|
-
const onFocusHandler = React.useCallback(
|
|
452
|
-
(e) => {
|
|
453
|
-
setFocused(true);
|
|
454
|
-
onFocus == null ? void 0 : onFocus(e);
|
|
455
|
-
},
|
|
456
|
-
[setFocused, onFocus]
|
|
457
|
-
);
|
|
458
|
-
const onBlurHandler = React.useCallback(
|
|
459
|
-
(e) => {
|
|
460
|
-
setFocused(false);
|
|
461
|
-
onBlur == null ? void 0 : onBlur(e);
|
|
462
|
-
},
|
|
463
|
-
[setFocused, onBlur]
|
|
464
|
-
);
|
|
465
|
-
return /* @__PURE__ */ jsx(
|
|
466
|
-
StyledInput,
|
|
467
|
-
{
|
|
468
|
-
...elementProps,
|
|
469
|
-
id: id != null ? id : formElementId,
|
|
470
|
-
readOnly,
|
|
471
|
-
"aria-describedby": stringAttrValue(
|
|
472
|
-
ariaDescribedBy,
|
|
473
|
-
formFieldContextDescribedBy
|
|
474
|
-
),
|
|
475
|
-
"aria-invalid": ariaInvalid != null ? ariaInvalid : formFieldAriaInvalid,
|
|
476
|
-
disabled: disabled === true || void 0,
|
|
477
|
-
required: required === true || void 0,
|
|
478
|
-
onFocus: onFocusHandler,
|
|
479
|
-
onBlur: onBlurHandler,
|
|
480
|
-
onChange,
|
|
481
|
-
ref: mergeRefs([inputRef, formElementRef, forwardRef])
|
|
482
|
-
}
|
|
483
|
-
);
|
|
484
|
-
}
|
|
485
|
-
);
|
|
486
|
-
|
|
487
|
-
const Root = React.forwardRef(({ children, size, placeholder, role, ...restProps }, forwardRef) => {
|
|
488
|
-
var _a, _b, _c;
|
|
489
|
-
const ref = useRef(null);
|
|
490
|
-
const {
|
|
491
|
-
valid: inputValid,
|
|
492
|
-
"aria-disabled": ariaDisabled,
|
|
493
|
-
disabled,
|
|
494
|
-
readOnly,
|
|
495
|
-
focused,
|
|
496
|
-
setHovered,
|
|
497
|
-
inputRef,
|
|
498
|
-
actionButtonRef,
|
|
499
|
-
setFocused,
|
|
500
|
-
hasIconSlot
|
|
501
|
-
} = useInputContext();
|
|
502
|
-
const { hoverProps, isHovered: hovered } = useHover({
|
|
503
|
-
onHoverChange: setHovered
|
|
504
|
-
});
|
|
505
|
-
const { pressProps } = usePress({
|
|
506
|
-
onPressStart: (e) => {
|
|
507
|
-
const { target } = e.originalEvent;
|
|
508
|
-
const shouldPrevent = document.activeElement === inputRef.current && target !== inputRef.current;
|
|
509
|
-
if (shouldPrevent) {
|
|
510
|
-
e.originalEvent.preventDefault();
|
|
511
|
-
}
|
|
512
|
-
},
|
|
513
|
-
onPressEnd: (e) => {
|
|
514
|
-
var _a2, _b2;
|
|
515
|
-
const { target } = e.originalEvent;
|
|
516
|
-
const isActionButton = target === actionButtonRef.current || ((_a2 = actionButtonRef.current) == null ? void 0 : _a2.contains(target)) === true;
|
|
517
|
-
const shouldFocusInput = !isActionButton && !booleanify(disabled) && !booleanify(focused);
|
|
518
|
-
if (shouldFocusInput) {
|
|
519
|
-
(_b2 = inputRef.current) == null ? void 0 : _b2.focus();
|
|
520
|
-
setFocused(true);
|
|
521
|
-
}
|
|
522
|
-
},
|
|
523
|
-
preventFocusOnPress: "auto"
|
|
524
|
-
});
|
|
525
|
-
const ariaDisabledOrDisabled = booleanify(ariaDisabled) || booleanify(disabled);
|
|
526
|
-
const inputValue = (_c = (_b = (_a = inputRef.current) == null ? void 0 : _a.value) != null ? _b : restProps.value) != null ? _c : restProps.defaultValue;
|
|
527
|
-
const {
|
|
528
|
-
label,
|
|
529
|
-
shouldUseFloatingLabel,
|
|
530
|
-
valid: formFieldValid
|
|
531
|
-
} = useFormFieldContext();
|
|
532
|
-
const floatingLabel = placeholder !== void 0 || inputValue !== void 0 && inputValue !== "" || focused;
|
|
533
|
-
const useFloatingLabel = shouldUseFloatingLabel && role !== "combobox";
|
|
534
|
-
const valid = formFieldValid != null ? formFieldValid : inputValid;
|
|
535
|
-
const showValidityIcon = !booleanify(readOnly) && !ariaDisabledOrDisabled && !hovered && !focused && valid !== void 0;
|
|
536
|
-
const ValidIcon = valid === true ? StyledIconCheckMark : StyledIconExclamationPointCircle;
|
|
537
|
-
return /* @__PURE__ */ jsxs(
|
|
538
|
-
StyledBaseInput,
|
|
539
|
-
{
|
|
540
|
-
...mergeProps(restProps, hoverProps, pressProps),
|
|
541
|
-
"data-invalid": booleanishAttrValue(valid === false),
|
|
542
|
-
"data-valid": booleanishAttrValue(valid === true),
|
|
543
|
-
"data-form-element": role !== "combobox" ? "input" : void 0,
|
|
544
|
-
ref: mergeRefs([ref, forwardRef]),
|
|
545
|
-
size,
|
|
546
|
-
hovered,
|
|
547
|
-
focused,
|
|
548
|
-
valid,
|
|
549
|
-
disabled: booleanify(disabled),
|
|
550
|
-
ariaDisabled: booleanify(ariaDisabled),
|
|
551
|
-
readOnly: booleanify(readOnly),
|
|
552
|
-
children: [
|
|
553
|
-
useFloatingLabel && /* @__PURE__ */ jsx(
|
|
554
|
-
FloatingLabel,
|
|
555
|
-
{
|
|
556
|
-
floating: floatingLabel,
|
|
557
|
-
css: !floatingLabel && hasIconSlot ? (
|
|
558
|
-
// icon size + input padding
|
|
559
|
-
{
|
|
560
|
-
transform: "translate(calc($sizes$icon-200 + $space$50 - 1px), -1px)"
|
|
561
|
-
}
|
|
562
|
-
) : floatingLabel ? { transform: "translateY(calc(-50% - 1px))" } : void 0,
|
|
563
|
-
size,
|
|
564
|
-
children: label
|
|
565
|
-
}
|
|
566
|
-
),
|
|
567
|
-
children,
|
|
568
|
-
showValidityIcon && /* @__PURE__ */ jsx(StyledValidityBox, { children: /* @__PURE__ */ jsx(ValidIcon, { size: "small", weight: "thin" }) })
|
|
569
|
-
]
|
|
570
|
-
}
|
|
571
|
-
);
|
|
572
|
-
});
|
|
573
|
-
const BaseInput = React.forwardRef(
|
|
574
|
-
({
|
|
575
|
-
"aria-disabled": ariaDisabled,
|
|
576
|
-
disabled,
|
|
577
|
-
valid,
|
|
578
|
-
readOnly,
|
|
579
|
-
required,
|
|
580
|
-
onChange,
|
|
581
|
-
...restProps
|
|
582
|
-
}, forwardRef) => /* @__PURE__ */ jsx(
|
|
583
|
-
InputProvider,
|
|
584
|
-
{
|
|
585
|
-
valid,
|
|
586
|
-
disabled,
|
|
587
|
-
"aria-disabled": ariaDisabled,
|
|
588
|
-
readOnly,
|
|
589
|
-
required,
|
|
590
|
-
onChange,
|
|
591
|
-
children: /* @__PURE__ */ jsx(Root, { ...restProps, ref: forwardRef })
|
|
592
|
-
}
|
|
593
|
-
)
|
|
594
|
-
);
|
|
595
|
-
BaseInput.Input = Input$1;
|
|
596
|
-
|
|
597
62
|
const baseInputAllowedEvents = [
|
|
598
63
|
"onMouseEnter",
|
|
599
64
|
"onMouseLeave",
|
|
@@ -616,8 +81,9 @@ const baseInputAllowedEvents = [
|
|
|
616
81
|
"onTouchMove",
|
|
617
82
|
"onTouchMoveCapture"
|
|
618
83
|
];
|
|
619
|
-
const useBaseInputProps = (allProps) => {
|
|
84
|
+
const useBaseInputProps = (allProps, forwardRef) => {
|
|
620
85
|
const {
|
|
86
|
+
// base-input props
|
|
621
87
|
valid,
|
|
622
88
|
"aria-disabled": ariaDisabled,
|
|
623
89
|
readOnly,
|
|
@@ -626,16 +92,46 @@ const useBaseInputProps = (allProps) => {
|
|
|
626
92
|
size,
|
|
627
93
|
className,
|
|
628
94
|
css,
|
|
629
|
-
|
|
95
|
+
onChange,
|
|
96
|
+
"data-testid": dataTestId,
|
|
97
|
+
// input props
|
|
98
|
+
id,
|
|
99
|
+
"aria-describedby": ariaDescribedBy,
|
|
100
|
+
"aria-invalid": ariaInvalid,
|
|
101
|
+
// input & floatingLabel shared props
|
|
630
102
|
placeholder,
|
|
631
103
|
value,
|
|
632
104
|
defaultValue,
|
|
633
|
-
role,
|
|
634
|
-
onChange,
|
|
635
105
|
...restProps
|
|
636
106
|
} = allProps;
|
|
107
|
+
const {
|
|
108
|
+
formElementId,
|
|
109
|
+
formElementRef,
|
|
110
|
+
ariaDescribedBy: formFieldContextDescribedBy,
|
|
111
|
+
ariaInvalid: formFieldAriaInvalid,
|
|
112
|
+
valid: formFieldValid,
|
|
113
|
+
setRequired,
|
|
114
|
+
setReadOnly,
|
|
115
|
+
setDisabled,
|
|
116
|
+
setAriaDisabled
|
|
117
|
+
} = useFormFieldContext();
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
setRequired == null ? void 0 : setRequired(required);
|
|
120
|
+
setReadOnly == null ? void 0 : setReadOnly(readOnly);
|
|
121
|
+
setDisabled == null ? void 0 : setDisabled(disabled);
|
|
122
|
+
setAriaDisabled == null ? void 0 : setAriaDisabled(ariaDisabled);
|
|
123
|
+
}, [
|
|
124
|
+
disabled,
|
|
125
|
+
ariaDisabled,
|
|
126
|
+
readOnly,
|
|
127
|
+
required,
|
|
128
|
+
setRequired,
|
|
129
|
+
setReadOnly,
|
|
130
|
+
setDisabled,
|
|
131
|
+
setAriaDisabled
|
|
132
|
+
]);
|
|
637
133
|
const baseInputProps = {
|
|
638
|
-
valid,
|
|
134
|
+
valid: formFieldValid != null ? formFieldValid : valid,
|
|
639
135
|
"aria-disabled": ariaDisabled,
|
|
640
136
|
readOnly,
|
|
641
137
|
required,
|
|
@@ -643,17 +139,26 @@ const useBaseInputProps = (allProps) => {
|
|
|
643
139
|
size,
|
|
644
140
|
className,
|
|
645
141
|
css,
|
|
142
|
+
onChange,
|
|
143
|
+
"data-testid": dataTestId
|
|
144
|
+
};
|
|
145
|
+
const inputProps = {
|
|
146
|
+
id: id != null ? id : formElementId,
|
|
147
|
+
"aria-describedby": stringAttrValue(
|
|
148
|
+
ariaDescribedBy,
|
|
149
|
+
formFieldContextDescribedBy
|
|
150
|
+
),
|
|
151
|
+
"aria-invalid": ariaInvalid != null ? ariaInvalid : formFieldAriaInvalid,
|
|
646
152
|
placeholder,
|
|
647
153
|
value,
|
|
648
154
|
defaultValue,
|
|
649
|
-
|
|
650
|
-
onChange
|
|
155
|
+
ref: mergeRefs([formElementRef, forwardRef])
|
|
651
156
|
};
|
|
652
|
-
const
|
|
157
|
+
const floatingLabelProps = {
|
|
653
158
|
placeholder,
|
|
654
159
|
value,
|
|
655
160
|
defaultValue,
|
|
656
|
-
|
|
161
|
+
size
|
|
657
162
|
};
|
|
658
163
|
Object.entries(restProps).forEach(([key, value2]) => {
|
|
659
164
|
if (baseInputAllowedEvents.includes(key)) {
|
|
@@ -662,9 +167,43 @@ const useBaseInputProps = (allProps) => {
|
|
|
662
167
|
inputProps[key] = value2;
|
|
663
168
|
}
|
|
664
169
|
});
|
|
665
|
-
return { baseInputProps, inputProps };
|
|
170
|
+
return { baseInputProps, inputProps, floatingLabelProps };
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const InputFloatingLabel = ({
|
|
174
|
+
placeholder,
|
|
175
|
+
value,
|
|
176
|
+
defaultValue,
|
|
177
|
+
size
|
|
178
|
+
}) => {
|
|
179
|
+
var _a, _b, _c;
|
|
180
|
+
const { focused, inputRef, hasIconSlot } = useInputContext();
|
|
181
|
+
const inputValue = (_c = (_b = (_a = inputRef.current) == null ? void 0 : _a.value) != null ? _b : value) != null ? _c : defaultValue;
|
|
182
|
+
const { label, shouldUseFloatingLabel } = useFormFieldContext();
|
|
183
|
+
const floatingLabel = placeholder !== void 0 || inputValue !== void 0 && inputValue !== "" || focused;
|
|
184
|
+
if (!shouldUseFloatingLabel) {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
return /* @__PURE__ */ jsx(
|
|
188
|
+
FloatingLabel,
|
|
189
|
+
{
|
|
190
|
+
floating: floatingLabel,
|
|
191
|
+
css: !floatingLabel && hasIconSlot ? (
|
|
192
|
+
// icon size + input padding
|
|
193
|
+
{
|
|
194
|
+
transform: "translate(calc($sizes$icon-200 + $space$50 - 1px), -1px)"
|
|
195
|
+
}
|
|
196
|
+
) : floatingLabel ? { transform: "translateY(calc(-50% - 1px))" } : void 0,
|
|
197
|
+
size,
|
|
198
|
+
children: label
|
|
199
|
+
}
|
|
200
|
+
);
|
|
666
201
|
};
|
|
667
202
|
|
|
203
|
+
const ActionButton = BaseInput.ActionButton;
|
|
204
|
+
|
|
205
|
+
const IconSlot = BaseInput.IconSlot;
|
|
206
|
+
|
|
668
207
|
const Input = React.forwardRef(
|
|
669
208
|
({ children, ...restProps }, forwardRef) => {
|
|
670
209
|
const {
|
|
@@ -673,9 +212,10 @@ const Input = React.forwardRef(
|
|
|
673
212
|
clearLabel,
|
|
674
213
|
...elementProps
|
|
675
214
|
} = restProps;
|
|
676
|
-
const { baseInputProps, inputProps } = useBaseInputProps(elementProps);
|
|
215
|
+
const { baseInputProps, inputProps, floatingLabelProps } = useBaseInputProps(elementProps, forwardRef);
|
|
677
216
|
return /* @__PURE__ */ jsxs(BaseInput, { ...baseInputProps, children: [
|
|
678
|
-
/* @__PURE__ */ jsx(
|
|
217
|
+
/* @__PURE__ */ jsx(InputFloatingLabel, { ...floatingLabelProps }),
|
|
218
|
+
/* @__PURE__ */ jsx(BaseInput.Input, { ...inputProps }),
|
|
679
219
|
children,
|
|
680
220
|
/* @__PURE__ */ jsx(
|
|
681
221
|
ClearAction,
|
|
@@ -706,8 +246,9 @@ const InputPassword = React.forwardRef(
|
|
|
706
246
|
const inputRef = useRef(null);
|
|
707
247
|
const [revealState, setRevealState] = useState(defaultReveal != null ? defaultReveal : false);
|
|
708
248
|
const revealInternal = reveal != null ? reveal : revealState;
|
|
709
|
-
const { baseInputProps, inputProps } = useBaseInputProps(restProps);
|
|
249
|
+
const { baseInputProps, inputProps, floatingLabelProps } = useBaseInputProps(restProps, forwardRef);
|
|
710
250
|
return /* @__PURE__ */ jsxs(BaseInput, { ...baseInputProps, children: [
|
|
251
|
+
/* @__PURE__ */ jsx(InputFloatingLabel, { ...floatingLabelProps }),
|
|
711
252
|
/* @__PURE__ */ jsx(
|
|
712
253
|
BaseInput.Input,
|
|
713
254
|
{
|
|
@@ -717,9 +258,9 @@ const InputPassword = React.forwardRef(
|
|
|
717
258
|
}
|
|
718
259
|
),
|
|
719
260
|
children,
|
|
720
|
-
/* @__PURE__ */ jsx(IconSlot, { children: /* @__PURE__ */ jsx(IconLockClosed, {}) }),
|
|
261
|
+
/* @__PURE__ */ jsx(BaseInput.IconSlot, { children: /* @__PURE__ */ jsx(IconLockClosed, {}) }),
|
|
721
262
|
/* @__PURE__ */ jsx(
|
|
722
|
-
ActionButton,
|
|
263
|
+
BaseInput.ActionButton,
|
|
723
264
|
{
|
|
724
265
|
label: revealInternal ? hideLabel : revealLabel,
|
|
725
266
|
disabled: false,
|
|
@@ -749,9 +290,13 @@ const InputEmail = React.forwardRef(({ children, ...restProps }, forwardRef) =>
|
|
|
749
290
|
clearLabel,
|
|
750
291
|
...elementProps
|
|
751
292
|
} = restProps;
|
|
752
|
-
const { baseInputProps, inputProps } = useBaseInputProps(
|
|
293
|
+
const { baseInputProps, inputProps, floatingLabelProps } = useBaseInputProps(
|
|
294
|
+
elementProps,
|
|
295
|
+
forwardRef
|
|
296
|
+
);
|
|
753
297
|
return /* @__PURE__ */ jsxs(BaseInput, { ...baseInputProps, children: [
|
|
754
|
-
/* @__PURE__ */ jsx(
|
|
298
|
+
/* @__PURE__ */ jsx(InputFloatingLabel, { ...floatingLabelProps }),
|
|
299
|
+
/* @__PURE__ */ jsx(BaseInput.Input, { type: "email", ...inputProps }),
|
|
755
300
|
children,
|
|
756
301
|
/* @__PURE__ */ jsx(
|
|
757
302
|
ClearAction,
|
|
@@ -762,7 +307,7 @@ const InputEmail = React.forwardRef(({ children, ...restProps }, forwardRef) =>
|
|
|
762
307
|
value: inputProps.value
|
|
763
308
|
}
|
|
764
309
|
),
|
|
765
|
-
/* @__PURE__ */ jsx(IconSlot, { children: /* @__PURE__ */ jsx(IconEnvelope, {}) })
|
|
310
|
+
/* @__PURE__ */ jsx(BaseInput.IconSlot, { children: /* @__PURE__ */ jsx(IconEnvelope, {}) })
|
|
766
311
|
] });
|
|
767
312
|
});
|
|
768
313
|
InputEmail.ActionButton = ActionButton;
|
|
@@ -774,8 +319,12 @@ const InputSearch = React.forwardRef(({ children, ...restProps }, forwardRef) =>
|
|
|
774
319
|
clearLabel,
|
|
775
320
|
...elementProps
|
|
776
321
|
} = restProps;
|
|
777
|
-
const { baseInputProps, inputProps } = useBaseInputProps(
|
|
322
|
+
const { baseInputProps, inputProps, floatingLabelProps } = useBaseInputProps(
|
|
323
|
+
elementProps,
|
|
324
|
+
forwardRef
|
|
325
|
+
);
|
|
778
326
|
return /* @__PURE__ */ jsxs(BaseInput, { ...baseInputProps, children: [
|
|
327
|
+
/* @__PURE__ */ jsx(InputFloatingLabel, { ...floatingLabelProps }),
|
|
779
328
|
/* @__PURE__ */ jsx(BaseInput.Input, { ...inputProps, ref: forwardRef }),
|
|
780
329
|
children,
|
|
781
330
|
/* @__PURE__ */ jsx(
|
|
@@ -787,7 +336,7 @@ const InputSearch = React.forwardRef(({ children, ...restProps }, forwardRef) =>
|
|
|
787
336
|
value: inputProps.value
|
|
788
337
|
}
|
|
789
338
|
),
|
|
790
|
-
/* @__PURE__ */ jsx(IconSlot, { children: /* @__PURE__ */ jsx(IconMagnifyingGlass, {}) })
|
|
339
|
+
/* @__PURE__ */ jsx(BaseInput.IconSlot, { children: /* @__PURE__ */ jsx(IconMagnifyingGlass, {}) })
|
|
791
340
|
] });
|
|
792
341
|
});
|
|
793
342
|
InputSearch.ActionButton = ActionButton;
|