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