@trackunit/react-form-components 0.0.452 → 0.0.454
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/index.cjs.js +323 -200
- package/index.esm.js +323 -202
- package/package.json +3 -2
- package/src/components/ActionButton/ActionButton.d.ts +1 -1
- package/src/components/BaseInput/BaseInput.variants.d.ts +11 -1
- package/src/components/EmailInput/EmailInput.d.ts +14 -1
- package/src/components/Schedule/ScheduleParser.d.ts +6 -2
- package/src/components/Select/CreatableSelect.d.ts +1 -1
- package/src/components/Select/Select.d.ts +1 -1
- package/src/components/Select/Select.variants.d.ts +5 -0
- package/src/components/Select/shared.d.ts +2 -2
- package/src/components/Select/useCustomComponents.d.ts +1 -1
- package/src/components/SelectField/FormFieldSelectAdapter.d.ts +2 -2
- package/src/components/TextArea/TextArea.d.ts +1 -1
- package/src/utilities/compareReactNodes.d.ts +5 -0
package/index.cjs.js
CHANGED
|
@@ -18,6 +18,7 @@ var ReactAsyncCreatableSelect = require('react-select/async-creatable');
|
|
|
18
18
|
var ReactCreatableSelect = require('react-select/creatable');
|
|
19
19
|
var ReactAsyncSelect = require('react-select/async');
|
|
20
20
|
var sharedUtils = require('@trackunit/shared-utils');
|
|
21
|
+
var tailwindMerge = require('tailwind-merge');
|
|
21
22
|
var zod = require('zod');
|
|
22
23
|
|
|
23
24
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -156,14 +157,14 @@ const ActionButton = ({ type, value, dataTestId, iconSize, disabled, className }
|
|
|
156
157
|
case "PHONE_NUMBER":
|
|
157
158
|
return window.open(`tel:${value}`);
|
|
158
159
|
case "COPY":
|
|
160
|
+
// Typescript seems to be unable to detect RefObject
|
|
161
|
+
// as one of the members of the union RefObject | string | null which gives access to the `current` property
|
|
162
|
+
// eslint-disable-next-line react/prop-types
|
|
159
163
|
return copyToClipboard((_b = (_a = value === null || value === void 0 ? void 0 : value.current) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : "");
|
|
160
164
|
default:
|
|
161
165
|
return null;
|
|
162
166
|
}
|
|
163
167
|
};
|
|
164
|
-
if (ButtonAction === null) {
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
168
|
return (jsxRuntime.jsx("div", { className: cvaActionContainer({ className }), children: jsxRuntime.jsx(reactComponents.IconButton, { className: cvaActionButton({ size: iconSize }), dataTestId: dataTestId || "testIconButtonId", disabled: disabled, icon: jsxRuntime.jsx(reactComponents.Icon, { name: getIconName(), size: "small" }), onClick: ButtonAction, size: "small", variant: "secondary" }) }));
|
|
168
169
|
};
|
|
169
170
|
|
|
@@ -209,21 +210,56 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
209
210
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
210
211
|
};
|
|
211
212
|
|
|
213
|
+
/**
|
|
214
|
+
* Used to compare two React nodes for deep equality.
|
|
215
|
+
*/
|
|
216
|
+
const compareReactNodes = (node1, node2) => {
|
|
217
|
+
// Base case: If both objects are identical, return true.
|
|
218
|
+
if (node1 === node2) {
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
// Check if both objects are valid React elements.
|
|
222
|
+
if (React.isValidElement(node1) && React.isValidElement(node2)) {
|
|
223
|
+
const { type: type1, props: props1, key: key1 } = node1;
|
|
224
|
+
const { type: type2, props: props2, key: key2 } = node2;
|
|
225
|
+
if (type1 !== type2 || key1 !== key2) {
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
return compareReactNodes(props1, props2);
|
|
229
|
+
}
|
|
230
|
+
// Check if both objects are objects and not null.
|
|
231
|
+
if (typeof node1 !== "object" || typeof node2 !== "object" || node1 === null || node2 === null) {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
// Get the keys of both objects.
|
|
235
|
+
const keys1 = Object.keys(node1);
|
|
236
|
+
const keys2 = Object.keys(node2);
|
|
237
|
+
// Check if the number of keys is the same.
|
|
238
|
+
if (keys1.length !== keys2.length) {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
// Iterate through the keys and compare their values recursively.
|
|
242
|
+
for (const key of keys1) {
|
|
243
|
+
if (!keys2.includes(key) ||
|
|
244
|
+
!compareReactNodes(node1[key], node2[key])) {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
// If all checks pass, the objects are deep equal.
|
|
249
|
+
return true;
|
|
250
|
+
};
|
|
251
|
+
|
|
212
252
|
const cvaInputBase = cssClassVarianceUtilities.cvaMerge([
|
|
213
253
|
"component-baseInput-shadow",
|
|
214
254
|
"component-baseInput-border",
|
|
215
255
|
"component-baseInput-background",
|
|
216
256
|
"border-slate-300",
|
|
217
|
-
"focus-within:ring-2",
|
|
218
|
-
"focus-within:ring-inset",
|
|
219
|
-
"focus-within:ring-primary-500",
|
|
220
|
-
"focus-within:border-slate-400",
|
|
221
257
|
"hover:border-slate-400",
|
|
222
258
|
"hover:bg-slate-50",
|
|
223
259
|
"transition",
|
|
224
260
|
]);
|
|
225
261
|
const cvaInputBaseDisabled = cssClassVarianceUtilities.cvaMerge(["bg-slate-100", "hover:bg-slate-100", "hover:border-slate-300"]);
|
|
226
|
-
const cvaInputBaseInvalid = cssClassVarianceUtilities.cvaMerge(["border-danger-600"
|
|
262
|
+
const cvaInputBaseInvalid = cssClassVarianceUtilities.cvaMerge(["border-danger-600"]);
|
|
227
263
|
const cvaInput = cssClassVarianceUtilities.cvaMerge(["relative", "flex", "h-10", cvaInputBase()], {
|
|
228
264
|
variants: {
|
|
229
265
|
size: {
|
|
@@ -232,24 +268,15 @@ const cvaInput = cssClassVarianceUtilities.cvaMerge(["relative", "flex", "h-10",
|
|
|
232
268
|
},
|
|
233
269
|
disabled: {
|
|
234
270
|
true: cvaInputBaseDisabled(),
|
|
235
|
-
false: "",
|
|
271
|
+
false: [""],
|
|
236
272
|
},
|
|
237
273
|
invalid: {
|
|
238
274
|
true: cvaInputBaseInvalid(),
|
|
239
|
-
false: "",
|
|
275
|
+
false: [""],
|
|
240
276
|
},
|
|
241
277
|
},
|
|
242
278
|
});
|
|
243
|
-
const cvaInputField = cssClassVarianceUtilities.cvaMerge([
|
|
244
|
-
"w-full",
|
|
245
|
-
"px-3",
|
|
246
|
-
"border-0",
|
|
247
|
-
"bg-transparent",
|
|
248
|
-
"text-base",
|
|
249
|
-
"text-slate-900",
|
|
250
|
-
"placeholder-slate-400",
|
|
251
|
-
"focus-visible:outline-none",
|
|
252
|
-
], {
|
|
279
|
+
const cvaInputField = cssClassVarianceUtilities.cvaMerge(["w-full", "px-3", "border-0", "bg-transparent", "text-base", "text-slate-900", "placeholder-slate-400", "component-baseInput-border"], {
|
|
253
280
|
variants: {
|
|
254
281
|
size: {
|
|
255
282
|
small: ["py-1"],
|
|
@@ -257,9 +284,28 @@ const cvaInputField = cssClassVarianceUtilities.cvaMerge([
|
|
|
257
284
|
},
|
|
258
285
|
disabled: {
|
|
259
286
|
true: ["text-slate-700"],
|
|
260
|
-
false: "",
|
|
287
|
+
false: [""],
|
|
288
|
+
},
|
|
289
|
+
autoFocus: {
|
|
290
|
+
true: [""],
|
|
291
|
+
false: ["focus-visible:outline-none"],
|
|
292
|
+
},
|
|
293
|
+
addonBefore: {
|
|
294
|
+
true: [""],
|
|
295
|
+
false: [""],
|
|
296
|
+
},
|
|
297
|
+
prefix: {
|
|
298
|
+
true: ["ps-10"],
|
|
299
|
+
false: [""],
|
|
261
300
|
},
|
|
262
301
|
},
|
|
302
|
+
compoundVariants: [
|
|
303
|
+
{
|
|
304
|
+
addonBefore: true,
|
|
305
|
+
prefix: true,
|
|
306
|
+
className: ["ps-4"],
|
|
307
|
+
},
|
|
308
|
+
],
|
|
263
309
|
});
|
|
264
310
|
const cvaInputAddon = cssClassVarianceUtilities.cvaMerge([
|
|
265
311
|
"flex",
|
|
@@ -271,7 +317,6 @@ const cvaInputAddon = cssClassVarianceUtilities.cvaMerge([
|
|
|
271
317
|
"bg-slate-50",
|
|
272
318
|
]);
|
|
273
319
|
const cvaInputAddonBefore = cssClassVarianceUtilities.cvaMerge([cvaInputAddon(), "border-r", "rounded-l-lg"]);
|
|
274
|
-
const cvaInputAddonAfter = cssClassVarianceUtilities.cvaMerge([cvaInputAddon(), "border-l", "rounded-r-lg"]);
|
|
275
320
|
const cvaInputPrefix = cssClassVarianceUtilities.cvaMerge([
|
|
276
321
|
"flex",
|
|
277
322
|
"justify-center",
|
|
@@ -281,21 +326,62 @@ const cvaInputPrefix = cssClassVarianceUtilities.cvaMerge([
|
|
|
281
326
|
"component-baseInput-prefix",
|
|
282
327
|
"component-search-borderless",
|
|
283
328
|
"pl-3",
|
|
329
|
+
"absolute",
|
|
330
|
+
"inset-y-0",
|
|
284
331
|
], {
|
|
285
332
|
variants: {
|
|
286
333
|
disabled: {
|
|
287
334
|
true: ["text-slate-500"],
|
|
288
|
-
false: "",
|
|
335
|
+
false: [""],
|
|
336
|
+
},
|
|
337
|
+
addonBefore: {
|
|
338
|
+
true: ["relative"],
|
|
339
|
+
false: [""],
|
|
289
340
|
},
|
|
290
341
|
},
|
|
291
342
|
});
|
|
292
|
-
const cvaInputSuffix = cssClassVarianceUtilities.cvaMerge(["flex", "justify-center", "items-center", "text-slate-400", "px-3"], {
|
|
343
|
+
const cvaInputSuffix = cssClassVarianceUtilities.cvaMerge(["flex", "justify-center", "items-center", "text-slate-400", "px-3", "absolute", "inset-y-0", "right-0"], {
|
|
293
344
|
variants: {
|
|
294
345
|
disabled: {
|
|
295
346
|
true: ["text-slate-500"],
|
|
296
|
-
false: "",
|
|
347
|
+
false: [""],
|
|
348
|
+
},
|
|
349
|
+
addonAfter: {
|
|
350
|
+
true: ["relative"],
|
|
351
|
+
false: [""],
|
|
352
|
+
},
|
|
353
|
+
actions: {
|
|
354
|
+
true: ["right-10"],
|
|
355
|
+
false: [""],
|
|
297
356
|
},
|
|
298
357
|
},
|
|
358
|
+
compoundVariants: [
|
|
359
|
+
{
|
|
360
|
+
addonAfter: true,
|
|
361
|
+
actions: true,
|
|
362
|
+
className: ["right-0"],
|
|
363
|
+
},
|
|
364
|
+
],
|
|
365
|
+
});
|
|
366
|
+
const cvaInputAddonAfter = cssClassVarianceUtilities.cvaMerge([cvaInputAddon(), "border-l", "rounded-r-lg", "ml-[1px]"]);
|
|
367
|
+
const cvaInputAction = cssClassVarianceUtilities.cvaMerge(["absolute", "end-0.5"], {
|
|
368
|
+
variants: {
|
|
369
|
+
addonAfter: {
|
|
370
|
+
true: ["relative"],
|
|
371
|
+
false: [""],
|
|
372
|
+
},
|
|
373
|
+
suffix: {
|
|
374
|
+
true: ["absolute"],
|
|
375
|
+
false: [""],
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
compoundVariants: [
|
|
379
|
+
{
|
|
380
|
+
addonAfter: true,
|
|
381
|
+
suffix: true,
|
|
382
|
+
className: ["relative"],
|
|
383
|
+
},
|
|
384
|
+
],
|
|
299
385
|
});
|
|
300
386
|
|
|
301
387
|
/**
|
|
@@ -307,7 +393,7 @@ const cvaInputSuffix = cssClassVarianceUtilities.cvaMerge(["flex", "justify-cent
|
|
|
307
393
|
* This is a base used by our other input components such as TextInput, NumberInput, PasswordInput, etc.
|
|
308
394
|
*/
|
|
309
395
|
const BaseInput = React__namespace.forwardRef((_a, ref) => {
|
|
310
|
-
var _b
|
|
396
|
+
var _b;
|
|
311
397
|
var { className, isInvalid, dataTestId, prefix, suffix, addonBefore, addonAfter, actions, fieldSize = "medium", nonInteractive = false, showDefaultActions = false, inputClassName, placeholder, addonBeforeClassName } = _a, rest = __rest(_a, ["className", "isInvalid", "dataTestId", "prefix", "suffix", "addonBefore", "addonAfter", "actions", "fieldSize", "nonInteractive", "showDefaultActions", "inputClassName", "placeholder", "addonBeforeClassName"]);
|
|
312
398
|
const renderAsDisabled = rest.disabled || rest.readOnly;
|
|
313
399
|
const innerRef = React__namespace.useRef(null);
|
|
@@ -318,15 +404,29 @@ const BaseInput = React__namespace.forwardRef((_a, ref) => {
|
|
|
318
404
|
invalid: isInvalid,
|
|
319
405
|
size: fieldSize,
|
|
320
406
|
className,
|
|
321
|
-
}), "data-testid": dataTestId
|
|
407
|
+
}), "data-testid": dataTestId ? `${dataTestId}-container` : null, children: [addonBefore ? (jsxRuntime.jsx("div", { className: cvaInputAddonBefore({ className: addonBeforeClassName }), "data-testid": dataTestId ? `${dataTestId}-addonBefore` : null, children: addonBefore })) : null, prefix && !compareReactNodes(addonBefore, prefix) ? (jsxRuntime.jsx("div", { className: cvaInputPrefix({
|
|
408
|
+
disabled: renderAsDisabled,
|
|
409
|
+
addonBefore: addonBefore !== undefined,
|
|
410
|
+
}), "data-testid": dataTestId ? `${dataTestId}-prefix` : null, children: prefix })) : null, jsxRuntime.jsx("input", Object.assign({ "aria-required": rest.required, className: cvaInputField({
|
|
411
|
+
autoFocus: rest.autoFocus,
|
|
412
|
+
size: fieldSize,
|
|
322
413
|
disabled: renderAsDisabled,
|
|
323
|
-
|
|
414
|
+
className: inputClassName,
|
|
415
|
+
addonBefore: addonBefore !== undefined,
|
|
416
|
+
prefix: !compareReactNodes(addonBefore, prefix),
|
|
417
|
+
}), "data-testid": dataTestId, placeholder: renderAsDisabled ? undefined : placeholder, ref: innerRef }, rest, { disabled: renderAsDisabled, readOnly: rest.readOnly || nonInteractive })), suffix && addonBefore !== suffix ? (jsxRuntime.jsx("div", { className: cvaInputSuffix({
|
|
324
418
|
disabled: renderAsDisabled,
|
|
325
|
-
|
|
419
|
+
addonAfter: addonAfter !== undefined && !compareReactNodes(addonBefore, addonAfter),
|
|
420
|
+
actions: (actions && !compareReactNodes(addonBefore, actions)) || false,
|
|
421
|
+
}), "data-testid": dataTestId ? `${dataTestId}-suffix` : null, children: suffix })) : null, rest.readOnly === true &&
|
|
326
422
|
showDefaultActions &&
|
|
327
|
-
((_b = innerRef
|
|
328
|
-
|
|
423
|
+
((_b = innerRef.current) === null || _b === void 0 ? void 0 : _b.value.length) &&
|
|
424
|
+
innerRef.current.value.length > 0 ? (jsxRuntime.jsx(ActionButton, { type: "COPY", value: innerRef }, "default-copy-action")) : null, actions && !compareReactNodes(addonBefore, actions) ? (jsxRuntime.jsx("div", { className: cvaInputAction({
|
|
425
|
+
addonAfter: addonAfter !== undefined && !compareReactNodes(addonBefore, addonAfter),
|
|
426
|
+
suffix: !compareReactNodes(addonBefore, suffix),
|
|
427
|
+
}), children: actions })) : null, addonAfter && !compareReactNodes(addonBefore, addonAfter) && !compareReactNodes(addonAfter, suffix) ? (jsxRuntime.jsx("div", { className: cvaInputAddonAfter(), "data-testid": dataTestId ? `${dataTestId}-addonAfter` : null, children: addonAfter })) : null] }));
|
|
329
428
|
});
|
|
429
|
+
BaseInput.displayName = "BaseInput";
|
|
330
430
|
|
|
331
431
|
const cvaLabel = cssClassVarianceUtilities.cvaMerge([
|
|
332
432
|
"text-base",
|
|
@@ -379,15 +479,11 @@ const cvaCheckbox = cssClassVarianceUtilities.cvaMerge([
|
|
|
379
479
|
"justify-center",
|
|
380
480
|
"box-border",
|
|
381
481
|
"transition",
|
|
382
|
-
"focus:bg-slate-200",
|
|
383
482
|
"outline-0",
|
|
384
483
|
"active:bg-slate-200",
|
|
385
484
|
"active:ring-2",
|
|
386
485
|
"active:ring-inset",
|
|
387
486
|
"active:ring-primary-700",
|
|
388
|
-
"focus:ring-2",
|
|
389
|
-
"focus:ring-inset",
|
|
390
|
-
"focus:ring-primary-700",
|
|
391
487
|
"cursor-pointer",
|
|
392
488
|
"group-active:ring-2",
|
|
393
489
|
"group-active:ring-inset",
|
|
@@ -395,13 +491,7 @@ const cvaCheckbox = cssClassVarianceUtilities.cvaMerge([
|
|
|
395
491
|
], {
|
|
396
492
|
variants: {
|
|
397
493
|
invalid: {
|
|
398
|
-
true: [
|
|
399
|
-
"border-red-600",
|
|
400
|
-
"active:ring-red-700",
|
|
401
|
-
"focus:ring-red-700",
|
|
402
|
-
"group-focus:ring-2",
|
|
403
|
-
"group-focus:ring-inset",
|
|
404
|
-
],
|
|
494
|
+
true: ["border-red-600", "active:ring-red-700", "group-focus:ring-2", "group-focus:ring-inset"],
|
|
405
495
|
false: "",
|
|
406
496
|
},
|
|
407
497
|
state: {
|
|
@@ -411,11 +501,8 @@ const cvaCheckbox = cssClassVarianceUtilities.cvaMerge([
|
|
|
411
501
|
"hover:bg-primary-700",
|
|
412
502
|
"hover:border-primary-700",
|
|
413
503
|
"active:bg-primary-700",
|
|
414
|
-
"focus:bg-primary-700",
|
|
415
504
|
"group-hover:bg-primary-700",
|
|
416
505
|
"group-hover:border-primary-700",
|
|
417
|
-
"group-focus:bg-primary-700",
|
|
418
|
-
"group-focus:border-primary-700",
|
|
419
506
|
],
|
|
420
507
|
deselected: ["group-hover:bg-slate-100"],
|
|
421
508
|
indeterminate: [
|
|
@@ -423,14 +510,10 @@ const cvaCheckbox = cssClassVarianceUtilities.cvaMerge([
|
|
|
423
510
|
"border-primary-600",
|
|
424
511
|
"hover:bg-primary-700",
|
|
425
512
|
"hover:border-primary-700",
|
|
426
|
-
"focus:bg-primary-800",
|
|
427
|
-
"focus:border-primary-800",
|
|
428
513
|
"active:bg-primary-800",
|
|
429
514
|
"active:border-primary-800",
|
|
430
515
|
"group-hover:bg-primary-700",
|
|
431
516
|
"group-hover:border-primary-700",
|
|
432
|
-
"group-focus:bg-primary-800",
|
|
433
|
-
"group-focus:border-primary-800",
|
|
434
517
|
],
|
|
435
518
|
},
|
|
436
519
|
disabled: {
|
|
@@ -438,13 +521,8 @@ const cvaCheckbox = cssClassVarianceUtilities.cvaMerge([
|
|
|
438
521
|
"bg-slate-300",
|
|
439
522
|
"border-slate-300",
|
|
440
523
|
"cursor-not-allowed",
|
|
441
|
-
"group-hover:bg-slate-300",
|
|
442
|
-
"group-focus:bg-slate-300",
|
|
443
524
|
"hover:bg-slate-300",
|
|
444
|
-
"focus:bg-slate-300",
|
|
445
525
|
"active:bg-slate-300",
|
|
446
|
-
"focus:ring-0",
|
|
447
|
-
"focus:ring-inset",
|
|
448
526
|
"group-active:ring-0",
|
|
449
527
|
"group-active:ring-inset",
|
|
450
528
|
],
|
|
@@ -519,10 +597,10 @@ const Checkbox = React__namespace.forwardRef((_a, ref) => {
|
|
|
519
597
|
var _a, _b;
|
|
520
598
|
e.preventDefault();
|
|
521
599
|
if ("Space" === e.code) {
|
|
522
|
-
(_a = internalRef
|
|
600
|
+
(_a = internalRef.current) === null || _a === void 0 ? void 0 : _a.click();
|
|
523
601
|
}
|
|
524
602
|
if ("Enter" === e.code) {
|
|
525
|
-
(_b = internalRef
|
|
603
|
+
(_b = internalRef.current) === null || _b === void 0 ? void 0 : _b.click();
|
|
526
604
|
}
|
|
527
605
|
};
|
|
528
606
|
const [labelRef, setLabelRef] = React__namespace.useState(null);
|
|
@@ -530,16 +608,17 @@ const Checkbox = React__namespace.forwardRef((_a, ref) => {
|
|
|
530
608
|
onLabelRefChange && labelRef && onLabelRefChange(labelRef);
|
|
531
609
|
}, [labelRef, onLabelRefChange]);
|
|
532
610
|
const uuid = rest.id;
|
|
533
|
-
return (jsxRuntime.jsxs("label", { className: cvaCheckboxContainer({ className }), "data-testid": dataTestId
|
|
611
|
+
return (jsxRuntime.jsxs("label", { className: cvaCheckboxContainer({ className }), "data-testid": dataTestId ? `${dataTestId}-container` : null, htmlFor: uuid, onClick: e => stopPropagation && e.stopPropagation(), onKeyDown: onKeyPress, ref: internalRef, children: [jsxRuntime.jsx("input", Object.assign({ "aria-checked": !indeterminate && checked, checked: !indeterminate && checked, className: cvaCheckboxInput(), "data-testid": dataTestId, disabled: disabled, id: uuid, onChange: onChange, readOnly: readOnly, type: "checkbox" }, rest, { ref: ref })), jsxRuntime.jsx("span", { className: cvaCheckbox({
|
|
534
612
|
disabled: isReadonly,
|
|
535
613
|
invalid: isReadonly ? false : isInvalid,
|
|
536
614
|
state: indeterminate ? "indeterminate" : checked ? "selected" : "deselected",
|
|
537
|
-
}), id: uuid, tabIndex: isReadonly ? -1 : tabIndex, children: icon }), label
|
|
615
|
+
}), id: uuid, tabIndex: isReadonly ? -1 : tabIndex, children: icon }), label ? (jsxRuntime.jsx("span", { className: "flex", children: jsxRuntime.jsx("span", { className: cvaLabel({
|
|
538
616
|
invalid: isReadonly ? false : isInvalid,
|
|
539
617
|
disabled: isReadonly,
|
|
540
618
|
className: "cursor-pointer",
|
|
541
|
-
}), id: `checkbox-label-${label}`, ref: labelReference => setLabelRef(labelReference), children: label }) })), suffix] }));
|
|
619
|
+
}), id: `checkbox-label-${label}`, ref: labelReference => setLabelRef(labelReference), children: label }) })) : null, suffix] }));
|
|
542
620
|
});
|
|
621
|
+
Checkbox.displayName = "Checkbox";
|
|
543
622
|
|
|
544
623
|
/**
|
|
545
624
|
* The Label component is used for labels for input fields.
|
|
@@ -579,7 +658,7 @@ const cvaHelpAddon = cssClassVarianceUtilities.cvaMerge(["ml-auto"]);
|
|
|
579
658
|
* @returns {JSX.Element} FormGroup component
|
|
580
659
|
*/
|
|
581
660
|
const FormGroup = ({ isInvalid, helpText, helpAddon, tip, className, dataTestId, label, htmlFor, children, tipIconProps, disabled = false, required = false, }) => {
|
|
582
|
-
return (jsxRuntime.jsxs("div", { className: cvaFormGroup({ disabled, className }), "data-testid": dataTestId, children: [jsxRuntime.jsxs("div", { className: cvaFormGroupContainerBefore(), children: [label ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Label, { className: "component-formGroup-font", dataTestId: dataTestId
|
|
661
|
+
return (jsxRuntime.jsxs("div", { className: cvaFormGroup({ disabled, className }), "data-testid": dataTestId, children: [jsxRuntime.jsxs("div", { className: cvaFormGroupContainerBefore(), children: [label ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Label, { className: "component-formGroup-font", dataTestId: dataTestId ? `${dataTestId}-label` : undefined, htmlFor: htmlFor, id: htmlFor + "-label", children: label }), required ? jsxRuntime.jsx("span", { className: "required-asterisk", children: "*" }) : null] })) : null, tip ? (jsxRuntime.jsx(reactComponents.Tooltip, { className: "ml-1", dataTestId: dataTestId ? `${dataTestId}-tooltip` : undefined, iconProps: tipIconProps, label: tip, placement: "bottom" })) : null] }), children, jsxRuntime.jsxs("div", { className: cvaFormGroupContainerAfter({ invalid: isInvalid }), children: [helpText ? jsxRuntime.jsx("span", { "data-testid": dataTestId ? `${dataTestId}-helpText` : undefined, children: helpText }) : undefined, helpAddon ? (jsxRuntime.jsx("span", { className: cvaHelpAddon(), "data-testid": dataTestId ? `${dataTestId}-helpAddon` : null, children: helpAddon })) : null] })] }));
|
|
583
662
|
};
|
|
584
663
|
|
|
585
664
|
/**
|
|
@@ -590,8 +669,9 @@ const FormGroup = ({ isInvalid, helpText, helpAddon, tip, className, dataTestId,
|
|
|
590
669
|
const CheckboxField = React.forwardRef((_a, ref) => {
|
|
591
670
|
var { label, id, tip, helpText, helpAddon, isInvalid, className, checked, dataTestId, checkboxLabel, onChange } = _a, rest = __rest(_a, ["label", "id", "tip", "helpText", "helpAddon", "isInvalid", "className", "checked", "dataTestId", "checkboxLabel", "onChange"]);
|
|
592
671
|
const htmlForId = id ? id : "checkboxField-" + uuid.v4();
|
|
593
|
-
return (jsxRuntime.jsx(FormGroup, { className: "flex flex-col gap-1", dataTestId: dataTestId
|
|
672
|
+
return (jsxRuntime.jsx(FormGroup, { className: "flex flex-col gap-1", dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, disabled: rest.disabled, helpAddon: helpAddon, helpText: helpText, htmlFor: htmlForId, label: label, required: rest.required, tip: tip, children: jsxRuntime.jsx(Checkbox, Object.assign({ checked: checked, className: className, dataTestId: dataTestId, id: htmlForId, label: checkboxLabel, onChange: onChange, ref: ref }, rest)) }));
|
|
594
673
|
});
|
|
674
|
+
CheckboxField.displayName = "CheckboxField";
|
|
595
675
|
|
|
596
676
|
/**
|
|
597
677
|
* Validates if the given value is a valid hex color.
|
|
@@ -624,16 +704,17 @@ const ColorField = React.forwardRef((_a, ref) => {
|
|
|
624
704
|
}
|
|
625
705
|
}, [onChange]);
|
|
626
706
|
const renderAsInvalid = !!errorMessage || (value && typeof value === "string" && !isValidHEXColor(value)) || isInvalid;
|
|
627
|
-
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId
|
|
707
|
+
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, disabled: rest.disabled, helpAddon: helpAddon, helpText: (renderAsInvalid && errorMessage) || helpText, htmlFor: htmlForId, isInvalid: renderAsInvalid, label: label, required: rest.required, tip: tip, children: jsxRuntime.jsxs("div", { className: cvaInput({
|
|
628
708
|
disabled: false,
|
|
629
709
|
invalid: false,
|
|
630
710
|
className,
|
|
631
|
-
}), "data-testid": dataTestId
|
|
632
|
-
if (innerRef
|
|
711
|
+
}), "data-testid": dataTestId ? `${dataTestId}-container` : null, children: [jsxRuntime.jsx("input", { "aria-labelledby": htmlForId + "-label-text", className: cvaInputField({ disabled: false }), "data-testid": dataTestId ? `${dataTestId}-textField` : null, onChange: handleChange, type: "text", value: value }), jsxRuntime.jsx("input", { "aria-labelledby": htmlForId + "-label", className: "mr-1 h-[25px] w-[25px] self-center bg-inherit", "data-testid": dataTestId, defaultValue: defaultValue, id: htmlForId, onChange: handleChange, ref: innerRef, type: "color", value: value }), jsxRuntime.jsx(reactComponents.IconButton, { className: "mr-1 self-center", icon: jsxRuntime.jsx(reactComponents.Icon, { name: "Pencil", type: "outline" }), onClick: () => {
|
|
712
|
+
if (innerRef.current) {
|
|
633
713
|
innerRef.current.click();
|
|
634
714
|
}
|
|
635
715
|
}, variant: "ghost-neutral" })] }) }));
|
|
636
716
|
});
|
|
717
|
+
ColorField.displayName = "ColorField";
|
|
637
718
|
|
|
638
719
|
/**
|
|
639
720
|
* A wrapper around BaseInput with a pop-up day picker.
|
|
@@ -645,8 +726,9 @@ const DateInput = React.forwardRef((_a, ref) => {
|
|
|
645
726
|
const formatDateToInputString = (date) => isDate.isValidDate(date) ? dateFns.format(date, "yyyy-MM-dd") : date;
|
|
646
727
|
// Chrome and Firefox need their default icon to have datepicker functionality.
|
|
647
728
|
const showIcon = !/Chrome/.test(navigator.userAgent) && !/Firefox/.test(navigator.userAgent);
|
|
648
|
-
return (jsxRuntime.jsx(BaseInput, Object.assign({ defaultValue: formatDateToInputString(defaultValue), max: formatDateToInputString(max), min: formatDateToInputString(min), ref: ref, suffix: showIcon
|
|
729
|
+
return (jsxRuntime.jsx(BaseInput, Object.assign({ defaultValue: formatDateToInputString(defaultValue), max: formatDateToInputString(max), min: formatDateToInputString(min), ref: ref, suffix: showIcon ? jsxRuntime.jsx(reactComponents.Icon, { dataTestId: "calendar", name: "Calendar", size: "medium", type: "solid" }) : null, type: "date", value: formatDateToInputString(value) }, rest)));
|
|
649
730
|
});
|
|
731
|
+
DateInput.displayName = "DateInput";
|
|
650
732
|
|
|
651
733
|
/**
|
|
652
734
|
* The date field component is used for entering date values.
|
|
@@ -659,8 +741,9 @@ const DateField = React.forwardRef((_a, ref) => {
|
|
|
659
741
|
var { label, id, tip, helpText, errorMessage, helpAddon, isInvalid, className, defaultValue, dataTestId } = _a, rest = __rest(_a, ["label", "id", "tip", "helpText", "errorMessage", "helpAddon", "isInvalid", "className", "defaultValue", "dataTestId"]);
|
|
660
742
|
const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
|
|
661
743
|
const htmlForId = id ? id : "dateField-" + uuid.v4();
|
|
662
|
-
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId
|
|
744
|
+
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, disabled: rest.disabled, helpAddon: helpAddon, helpText: (renderAsInvalid && errorMessage) || helpText, htmlFor: htmlForId, isInvalid: renderAsInvalid, label: label, required: rest.required, tip: tip, children: jsxRuntime.jsx(DateInput, Object.assign({ "aria-labelledby": htmlForId + "-label", defaultValue: defaultValue, id: htmlForId, isInvalid: renderAsInvalid, ref: ref }, rest, { className: className, dataTestId: dataTestId })) }));
|
|
663
745
|
});
|
|
746
|
+
DateField.displayName = "DateField";
|
|
664
747
|
|
|
665
748
|
const cvaDropZone = cssClassVarianceUtilities.cvaMerge([
|
|
666
749
|
"flex",
|
|
@@ -750,7 +833,7 @@ const DropZone = (_a) => {
|
|
|
750
833
|
e.preventDefault();
|
|
751
834
|
e.stopPropagation();
|
|
752
835
|
setDragActive(false);
|
|
753
|
-
if (e.dataTransfer.files
|
|
836
|
+
if (e.dataTransfer.files[0] && !disabled) {
|
|
754
837
|
filesSelected(e.dataTransfer.files);
|
|
755
838
|
setFileDropped(true);
|
|
756
839
|
}
|
|
@@ -770,7 +853,7 @@ const DropZone = (_a) => {
|
|
|
770
853
|
e.preventDefault();
|
|
771
854
|
e.stopPropagation();
|
|
772
855
|
}
|
|
773
|
-
}, onDragEnter: handleDrag, onDragLeave: handleDrag, onDragOver: handleDrag, onDrop: handleDrop }, rest, { children: [jsxRuntime.jsx("input", { accept: accept, className: "hidden", id: "input-file-upload", onChange: handleChange, title: t("dropzone.input.title"), type: "file" }), jsxRuntime.jsxs("label", { className: cvaDropZoneLabel(), "data-testid": dataTestId
|
|
856
|
+
}, onDragEnter: handleDrag, onDragLeave: handleDrag, onDragOver: handleDrag, onDrop: handleDrop }, rest, { children: [jsxRuntime.jsx("input", { accept: accept, className: "hidden", id: "input-file-upload", onChange: handleChange, title: t("dropzone.input.title"), type: "file" }), jsxRuntime.jsxs("label", { className: cvaDropZoneLabel(), "data-testid": dataTestId ? `${dataTestId}-label` : null, htmlFor: "input-file-upload", ref: inputLabelRef, children: [jsxRuntime.jsx("div", { className: cvaDropZoneIconBackground({ invalid: isInvalid }), children: jsxRuntime.jsx(reactComponents.Icon, { className: !isInvalid ? "text-gray-400" : "", color: isInvalid ? "danger" : "neutral", name: "ArrowUpCircle", type: "solid" }) }), jsxRuntime.jsx("button", { disabled: disabled, onClick: handleButtonClick, children: label })] })] })));
|
|
774
857
|
};
|
|
775
858
|
|
|
776
859
|
// Doing the same check as we do on the backend
|
|
@@ -800,7 +883,7 @@ const validateEmailAddress = (email) => {
|
|
|
800
883
|
* For specific input types make sure to use the corresponding input component.
|
|
801
884
|
*/
|
|
802
885
|
const EmailInput = React__namespace.forwardRef((_a, ref) => {
|
|
803
|
-
var { fieldSize = "medium", disabled = false, dataTestId, isInvalid = false, onChange } = _a, rest = __rest(_a, ["fieldSize", "disabled", "dataTestId", "isInvalid", "onChange"]);
|
|
886
|
+
var { fieldSize = "medium", disabled = false, dataTestId, isInvalid = false, onChange, disableAction = false } = _a, rest = __rest(_a, ["fieldSize", "disabled", "dataTestId", "isInvalid", "onChange", "disableAction"]);
|
|
804
887
|
const [email, setEmail] = React__namespace.useState("");
|
|
805
888
|
const sendEmail = () => {
|
|
806
889
|
return window.open(`mailto:${email}`);
|
|
@@ -811,9 +894,9 @@ const EmailInput = React__namespace.forwardRef((_a, ref) => {
|
|
|
811
894
|
setEmail(newValue);
|
|
812
895
|
}, [onChange]);
|
|
813
896
|
const renderAsInvalid = (email && !validateEmailAddress(email)) || isInvalid;
|
|
814
|
-
return (jsxRuntime.jsx(BaseInput, Object.assign({ actions: email &&
|
|
815
|
-
email.length > 0 && (jsxRuntime.jsx(ActionButton, { dataTestId: dataTestId && `${dataTestId}-emailIcon`, disabled: disabled, iconSize: fieldSize, onClick: sendEmail, type: "EMAIL", value: email })), dataTestId: dataTestId, isInvalid: renderAsInvalid, onChange: handleChange, placeholder: rest.placeholder || "mail@example.com", ref: ref, type: "email" }, rest)));
|
|
897
|
+
return (jsxRuntime.jsx(BaseInput, Object.assign({ actions: email && email.length > 0 ? (jsxRuntime.jsx(ActionButton, { dataTestId: dataTestId ? `${dataTestId}-emailIcon` : undefined, disabled: disableAction || isInvalid, iconSize: fieldSize, onClick: sendEmail, type: "EMAIL", value: email })) : null, dataTestId: dataTestId, disabled: disabled, isInvalid: renderAsInvalid, onChange: handleChange, placeholder: rest.placeholder || "mail@example.com", ref: ref, type: "email" }, rest)));
|
|
816
898
|
});
|
|
899
|
+
EmailInput.displayName = "EmailInput";
|
|
817
900
|
|
|
818
901
|
/**
|
|
819
902
|
* The EmailField component is used to enter email.
|
|
@@ -833,8 +916,9 @@ const EmailField = React.forwardRef((_a, ref) => {
|
|
|
833
916
|
onChange(event);
|
|
834
917
|
}
|
|
835
918
|
}, [onChange]);
|
|
836
|
-
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId
|
|
919
|
+
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, disabled: rest.disabled, helpAddon: helpAddon, helpText: (renderAsInvalid && errorMessage) || helpText, htmlFor: htmlForId, isInvalid: renderAsInvalid, label: label, required: rest.required, tip: tip, children: jsxRuntime.jsx(EmailInput, Object.assign({ "aria-labelledby": htmlForId + "-label", defaultValue: defaultValue, disabled: renderAsInvalid, id: htmlForId, isInvalid: renderAsInvalid, onChange: handleChange, ref: ref, value: value }, rest, { className: className, dataTestId: dataTestId })) }));
|
|
837
920
|
});
|
|
921
|
+
EmailField.displayName = "EmailField";
|
|
838
922
|
|
|
839
923
|
/**
|
|
840
924
|
* A thin wrapper around the `BaseInput` component for number input fields.
|
|
@@ -844,6 +928,7 @@ const EmailField = React.forwardRef((_a, ref) => {
|
|
|
844
928
|
const NumberInput = React.forwardRef((props, ref) => {
|
|
845
929
|
return jsxRuntime.jsx(BaseInput, Object.assign({ ref: ref, type: "number" }, props, { value: props.value }));
|
|
846
930
|
});
|
|
931
|
+
NumberInput.displayName = "NumberInput";
|
|
847
932
|
|
|
848
933
|
/**
|
|
849
934
|
* The number field component is used for entering numeric values and includes controls for incrementally increasing or decreasing the value.
|
|
@@ -856,8 +941,9 @@ const NumberField = React.forwardRef((_a, ref) => {
|
|
|
856
941
|
var { label, id, tip, helpText, errorMessage, helpAddon, isInvalid, maxLength, className, value, dataTestId } = _a, rest = __rest(_a, ["label", "id", "tip", "helpText", "errorMessage", "helpAddon", "isInvalid", "maxLength", "className", "value", "dataTestId"]);
|
|
857
942
|
const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
|
|
858
943
|
const htmlForId = id ? id : "numberField-" + uuid.v4();
|
|
859
|
-
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId
|
|
944
|
+
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, helpAddon: helpAddon, helpText: (renderAsInvalid && errorMessage) || helpText, htmlFor: htmlForId, isInvalid: renderAsInvalid, label: label, required: rest.required, tip: tip, children: jsxRuntime.jsx(NumberInput, Object.assign({ "aria-labelledby": htmlForId + "-label", id: htmlForId, isInvalid: renderAsInvalid, maxLength: maxLength, ref: ref, value: value }, rest, { className: className, dataTestId: dataTestId })) }));
|
|
860
945
|
});
|
|
946
|
+
NumberField.displayName = "NumberField";
|
|
861
947
|
|
|
862
948
|
const cvaOptionCardLabel = cssClassVarianceUtilities.cvaMerge([
|
|
863
949
|
cvaInputBase(),
|
|
@@ -891,11 +977,11 @@ const cvaOptionCardContainer = cssClassVarianceUtilities.cvaMerge(["contents"]);
|
|
|
891
977
|
const OptionCard = React.forwardRef((_a, ref) => {
|
|
892
978
|
var { icon, heading, subheading, description, disabled, id, value, className, contentClassName, dataTestId, customImage } = _a, rest = __rest(_a, ["icon", "heading", "subheading", "description", "disabled", "id", "value", "className", "contentClassName", "dataTestId", "customImage"]);
|
|
893
979
|
const htmlForId = id !== null && id !== void 0 ? id : "option-card-" + uuid.v4();
|
|
894
|
-
return (jsxRuntime.jsxs("div", { className: cvaOptionCardContainer(), "data-testid": dataTestId, children: [jsxRuntime.jsx("input", Object.assign({ className: "peer absolute h-0 w-0 opacity-0", id: htmlForId, ref: ref, type: "radio", value: value }, rest)), jsxRuntime.jsxs("label", { className: cvaOptionCardLabel({ className, disabled }), htmlFor: htmlForId, children: [disabled &&
|
|
895
|
-
icon
|
|
896
|
-
!customImage &&
|
|
897
|
-
React.cloneElement(icon, { className: `${icon.props.className} text-secondary-400` }), disabled && customImage && jsxRuntime.jsx("img", { alt: "logo", className: customImage.className, src: customImage.src }), !disabled && !customImage && icon, !disabled && customImage && jsxRuntime.jsx("img", { alt: "logo", className: customImage.className, src: customImage.src }), heading && (jsxRuntime.jsx(reactComponents.Heading, { subtle: disabled, variant: "secondary", children: heading })), (subheading || description) && (jsxRuntime.jsxs("div", { className: cvaOptionCardContent({ className: contentClassName }), children: [subheading && (jsxRuntime.jsx(reactComponents.Text, { align: "center", subtle: disabled, type: "span", weight: "thick", children: subheading })), description && (jsxRuntime.jsx(reactComponents.Text, { align: "center", subtle: true, type: "span", children: description }))] }))] })] }));
|
|
980
|
+
return (jsxRuntime.jsxs("div", { className: cvaOptionCardContainer(), "data-testid": dataTestId, children: [jsxRuntime.jsx("input", Object.assign({ className: "peer absolute h-0 w-0 opacity-0", id: htmlForId, ref: ref, type: "radio", value: value }, rest)), jsxRuntime.jsxs("label", { className: cvaOptionCardLabel({ className, disabled }), htmlFor: htmlForId, children: [disabled && icon && !customImage
|
|
981
|
+
? React.cloneElement(icon, { className: `${icon.props.className} text-secondary-400` })
|
|
982
|
+
: null, disabled && customImage ? jsxRuntime.jsx("img", { alt: "logo", className: customImage.className, src: customImage.src }) : null, !disabled && !customImage && icon, !disabled && customImage ? jsxRuntime.jsx("img", { alt: "logo", className: customImage.className, src: customImage.src }) : null, heading ? (jsxRuntime.jsx(reactComponents.Heading, { subtle: disabled, variant: "secondary", children: heading })) : null, subheading || description ? (jsxRuntime.jsxs("div", { className: cvaOptionCardContent({ className: contentClassName }), children: [subheading ? (jsxRuntime.jsx(reactComponents.Text, { align: "center", subtle: disabled, type: "span", weight: "thick", children: subheading })) : null, description ? (jsxRuntime.jsx(reactComponents.Text, { align: "center", subtle: true, type: "span", children: description })) : null] })) : null] })] }));
|
|
898
983
|
});
|
|
984
|
+
OptionCard.displayName = "OptionCard";
|
|
899
985
|
|
|
900
986
|
/**
|
|
901
987
|
* A thin wrapper around the `BaseInput` component for password input fields.
|
|
@@ -906,6 +992,7 @@ const PasswordInput = React.forwardRef((props, ref) => {
|
|
|
906
992
|
const [showPassword, setShowPassword] = React.useState(false);
|
|
907
993
|
return (jsxRuntime.jsx(BaseInput, Object.assign({ ref: ref }, props, { actions: jsxRuntime.jsx("div", { className: cvaActionContainer(), children: jsxRuntime.jsx(reactComponents.IconButton, { className: cvaActionButton({ size: props.fieldSize }), icon: jsxRuntime.jsx(reactComponents.Icon, { name: showPassword ? "EyeSlash" : "Eye", size: "small" }), onClick: () => setShowPassword(prevState => !prevState), size: "small", variant: "secondary" }) }), type: showPassword ? "text" : "password" })));
|
|
908
994
|
});
|
|
995
|
+
PasswordInput.displayName = "PasswordInput";
|
|
909
996
|
|
|
910
997
|
/**
|
|
911
998
|
* Password fields enter a password or other confidential information. Characters are masked as they are typed.
|
|
@@ -921,8 +1008,9 @@ const PasswordField = React.forwardRef((_a, ref) => {
|
|
|
921
1008
|
const handleChange = React.useCallback((event) => {
|
|
922
1009
|
onChange === null || onChange === void 0 ? void 0 : onChange(event);
|
|
923
1010
|
}, [onChange]);
|
|
924
|
-
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId
|
|
1011
|
+
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, helpAddon: helpAddon, helpText: (renderAsInvalid && errorMessage) || helpText, htmlFor: htmlFor, isInvalid: renderAsInvalid, label: label, required: rest.required, tip: tip, children: jsxRuntime.jsx(PasswordInput, Object.assign({}, rest, { "aria-labelledby": htmlFor + "-label", className: className, dataTestId: dataTestId, disabled: rest.readOnly, id: htmlFor, isInvalid: renderAsInvalid, maxLength: maxLength, onChange: handleChange, ref: ref, value: value })) }));
|
|
925
1012
|
});
|
|
1013
|
+
PasswordField.displayName = "PasswordField";
|
|
926
1014
|
|
|
927
1015
|
/**
|
|
928
1016
|
* @param phoneNumber - a phone number as a string
|
|
@@ -1033,10 +1121,9 @@ const PhoneInput = React.forwardRef((_a, ref) => {
|
|
|
1033
1121
|
onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
|
|
1034
1122
|
fieldIsFocused.current = true;
|
|
1035
1123
|
}, [onFocus]);
|
|
1036
|
-
return (jsxRuntime.jsx("div", { className: "grid grid-cols-1 gap-2", "data-testid": dataTestId
|
|
1037
|
-
innerValue &&
|
|
1038
|
-
(innerValue === null || innerValue === void 0 ? void 0 : innerValue.length) > 0 && (jsxRuntime.jsx(ActionButton, { dataTestId: dataTestId && `${dataTestId}-phoneIcon`, disabled: disabled || isInvalid, iconSize: fieldSize, type: "PHONE_NUMBER", value: (value === null || value === void 0 ? void 0 : value.toString()) || "" })), dataTestId: dataTestId && `${dataTestId}-phoneNumberInput`, disabled: disabled, fieldSize: fieldSize, id: "phoneInput-number", isInvalid: isInvalid, name: name, onBlur: handleBlur, onChange: handleChange, onFocus: handleFocus, prefix: (countryCode && countryCodeToFlagEmoji(countryCode)) || undefined, readOnly: readOnly, ref: ref, type: "tel", value: innerValue }, rest)) }));
|
|
1124
|
+
return (jsxRuntime.jsx("div", { className: "grid grid-cols-1 gap-2", "data-testid": dataTestId ? `${dataTestId}-container` : null, children: jsxRuntime.jsx(BaseInput, Object.assign({ actions: !disableAction && innerValue && innerValue.length > 0 ? (jsxRuntime.jsx(ActionButton, { dataTestId: dataTestId ? `${dataTestId}-phoneIcon` : undefined, disabled: isInvalid, iconSize: fieldSize, type: "PHONE_NUMBER", value: (value === null || value === void 0 ? void 0 : value.toString()) || "" })) : null, dataTestId: dataTestId ? `${dataTestId}-phoneNumberInput` : undefined, disabled: disabled, fieldSize: fieldSize, id: "phoneInput-number", isInvalid: isInvalid, name: name, onBlur: handleBlur, onChange: handleChange, onFocus: handleFocus, prefix: (countryCode && countryCodeToFlagEmoji(countryCode)) || undefined, readOnly: readOnly, ref: ref, type: "tel", value: innerValue }, rest)) }));
|
|
1039
1125
|
});
|
|
1126
|
+
PhoneInput.displayName = "PhoneInput";
|
|
1040
1127
|
|
|
1041
1128
|
/**
|
|
1042
1129
|
* The PhoneField component is used to enter phone number.
|
|
@@ -1058,8 +1145,9 @@ const PhoneField = React.forwardRef((_a, ref) => {
|
|
|
1058
1145
|
var { label, id, tip, helpText, isInvalid, errorMessage, value, helpAddon, className, defaultValue, dataTestId, name, onChange, onBlur } = _a, rest = __rest(_a, ["label", "id", "tip", "helpText", "isInvalid", "errorMessage", "value", "helpAddon", "className", "defaultValue", "dataTestId", "name", "onChange", "onBlur"]);
|
|
1059
1146
|
const htmlForId = id ? id : "phoneField-" + uuid.v4();
|
|
1060
1147
|
const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
|
|
1061
|
-
return (jsxRuntime.jsx(FormGroup, { className: className, dataTestId: dataTestId
|
|
1148
|
+
return (jsxRuntime.jsx(FormGroup, { className: className, dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, disabled: rest.disabled, helpAddon: helpAddon, helpText: (renderAsInvalid && errorMessage) || helpText, htmlFor: htmlForId, isInvalid: renderAsInvalid, label: label, required: rest.required, tip: tip, children: jsxRuntime.jsx(PhoneInput, Object.assign({ "aria-labelledby": htmlForId + "-label", dataTestId: dataTestId, defaultValue: defaultValue, id: htmlForId, isInvalid: renderAsInvalid, name: name, onBlur: onBlur, onChange: onChange, ref: ref, value: value }, rest)) }));
|
|
1062
1149
|
});
|
|
1150
|
+
PhoneField.displayName = "PhoneField";
|
|
1063
1151
|
|
|
1064
1152
|
/**
|
|
1065
1153
|
* The PhoneFieldWithController component is a wrapper for the PhoneField component to connect it to react-hook-form.
|
|
@@ -1070,6 +1158,7 @@ const PhoneFieldWithController = React.forwardRef((_a, ref) => {
|
|
|
1070
1158
|
var { control, controllerProps, name, value } = _a, rest = __rest(_a, ["control", "controllerProps", "name", "value"]);
|
|
1071
1159
|
return (jsxRuntime.jsx(reactHookForm.Controller, Object.assign({ control: control, defaultValue: value, name: name }, controllerProps, { render: ({ field }) => jsxRuntime.jsx(PhoneField, Object.assign({}, rest, field, { ref: ref })) })));
|
|
1072
1160
|
});
|
|
1161
|
+
PhoneFieldWithController.displayName = "PhoneFieldWithController";
|
|
1073
1162
|
|
|
1074
1163
|
/**
|
|
1075
1164
|
* Validates a phone number
|
|
@@ -1082,7 +1171,7 @@ const validatePhoneNumber = (phoneNumber) => {
|
|
|
1082
1171
|
asYouType.input(phoneNumber);
|
|
1083
1172
|
const countryCode = asYouType.getCallingCode();
|
|
1084
1173
|
const national = asYouType.getNationalNumber();
|
|
1085
|
-
const safePhoneNumber = getPhoneNumberWithPlus(phoneNumber
|
|
1174
|
+
const safePhoneNumber = getPhoneNumberWithPlus(phoneNumber.trim());
|
|
1086
1175
|
const number = parsePhoneNumberFromString__default["default"](safePhoneNumber);
|
|
1087
1176
|
if (phoneNumber && parsePhoneNumberFromString.isValidPhoneNumber(phoneNumber)) {
|
|
1088
1177
|
return undefined;
|
|
@@ -1133,9 +1222,6 @@ const cvaRadioItem = cssClassVarianceUtilities.cvaMerge([
|
|
|
1133
1222
|
"box-border",
|
|
1134
1223
|
"hover:cursor-pointer",
|
|
1135
1224
|
"hover:bg-slate-100",
|
|
1136
|
-
"focus:ring-2",
|
|
1137
|
-
"focus:ring-inset",
|
|
1138
|
-
"focus:ring-primary-700",
|
|
1139
1225
|
], {
|
|
1140
1226
|
variants: {
|
|
1141
1227
|
checked: {
|
|
@@ -1151,10 +1237,6 @@ const cvaRadioItem = cssClassVarianceUtilities.cvaMerge([
|
|
|
1151
1237
|
"active:ring-2",
|
|
1152
1238
|
"active:ring-inset",
|
|
1153
1239
|
"active:ring-primary-700",
|
|
1154
|
-
"focus:bg-slate-200",
|
|
1155
|
-
"focus:ring-2",
|
|
1156
|
-
"focus:ring-inset",
|
|
1157
|
-
"focus:ring-primary-700",
|
|
1158
1240
|
"group-active:ring-2",
|
|
1159
1241
|
"group-active:ring-inset",
|
|
1160
1242
|
"group-active:ring-primary-700",
|
|
@@ -1162,13 +1244,7 @@ const cvaRadioItem = cssClassVarianceUtilities.cvaMerge([
|
|
|
1162
1244
|
false: "",
|
|
1163
1245
|
},
|
|
1164
1246
|
invalid: {
|
|
1165
|
-
true: [
|
|
1166
|
-
"border-red-600",
|
|
1167
|
-
"active:ring-red-700",
|
|
1168
|
-
"focus:ring-red-700",
|
|
1169
|
-
"group-focus:ring-2",
|
|
1170
|
-
"group-focus:ring-inset",
|
|
1171
|
-
],
|
|
1247
|
+
true: ["border-red-600", "active:ring-red-700"],
|
|
1172
1248
|
false: "",
|
|
1173
1249
|
},
|
|
1174
1250
|
disabled: {
|
|
@@ -1176,13 +1252,8 @@ const cvaRadioItem = cssClassVarianceUtilities.cvaMerge([
|
|
|
1176
1252
|
"bg-slate-400",
|
|
1177
1253
|
"border-slate-300",
|
|
1178
1254
|
"cursor-not-allowed",
|
|
1179
|
-
"group-hover:bg-slate-400",
|
|
1180
|
-
"group-focus:bg-slate-400",
|
|
1181
1255
|
"hover:bg-slate-400",
|
|
1182
|
-
"focus:bg-slate-400",
|
|
1183
1256
|
"active:bg-slate-400",
|
|
1184
|
-
"focus:ring-0",
|
|
1185
|
-
"focus:ring-inset",
|
|
1186
1257
|
"group-active:ring-0",
|
|
1187
1258
|
"group-active:ring-inset",
|
|
1188
1259
|
],
|
|
@@ -1223,7 +1294,7 @@ const RadioGroupContext = React__namespace.createContext(null);
|
|
|
1223
1294
|
* @returns {JSX.Element} RadioGroup component
|
|
1224
1295
|
*/
|
|
1225
1296
|
const RadioGroup = ({ children, id, name, value, disabled, onChange, label, inline, className, dataTestId, isInvalid, }) => {
|
|
1226
|
-
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId
|
|
1297
|
+
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, label: label, children: jsxRuntime.jsx("div", { className: cvaRadioGroup({ layout: inline ? "inline" : null, className }), "data-testid": dataTestId, children: jsxRuntime.jsx(RadioGroupContext.Provider, { value: {
|
|
1227
1298
|
id,
|
|
1228
1299
|
value,
|
|
1229
1300
|
name: name || id,
|
|
@@ -1243,11 +1314,11 @@ RadioGroup.displayName = "RadioGroup";
|
|
|
1243
1314
|
const RadioItem = ({ label, value, dataTestId, className, description, }) => {
|
|
1244
1315
|
const groupCtx = React__namespace.useContext(RadioGroupContext);
|
|
1245
1316
|
const isChecked = (groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.value) === value;
|
|
1246
|
-
return (jsxRuntime.jsxs("label", { className: cvaRadioItemWrapper({ className }), "data-testid": dataTestId
|
|
1317
|
+
return (jsxRuntime.jsxs("label", { className: cvaRadioItemWrapper({ className }), "data-testid": dataTestId ? `${dataTestId}-Wrapper` : null, htmlFor: `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`, children: [jsxRuntime.jsx("input", { checked: isChecked, className: cvaRadioItem({
|
|
1247
1318
|
checked: isChecked,
|
|
1248
1319
|
disabled: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled,
|
|
1249
1320
|
invalid: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.isInvalid,
|
|
1250
|
-
}), "data-testid": dataTestId, id: `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`, onChange: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.onChange, type: "radio", value: value }), jsxRuntime.jsxs("div", { className: cvaRadioItemLabelContainer(), children: [jsxRuntime.jsx(Label, { dataTestId: dataTestId
|
|
1321
|
+
}), "data-testid": dataTestId, id: `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`, onChange: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.onChange, type: "radio", value: value }), jsxRuntime.jsxs("div", { className: cvaRadioItemLabelContainer(), children: [jsxRuntime.jsx(Label, { dataTestId: dataTestId ? `${dataTestId}-Label` : undefined, disabled: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled, htmlFor: `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`, isInvalid: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.isInvalid, children: label }), description ? (jsxRuntime.jsx("label", { className: cvaRadioItemDescription({ disabled: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled }), "data-testid": dataTestId ? `${dataTestId}-Description` : null, htmlFor: `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`, children: description })) : null] })] }));
|
|
1251
1322
|
};
|
|
1252
1323
|
|
|
1253
1324
|
const cvaTimeRange = cssClassVarianceUtilities.cvaMerge(["flex", "flex-1", "items-center", "gap-4", "border-transparent", "rounded-md"]);
|
|
@@ -1259,7 +1330,6 @@ const cvaTimeRange = cssClassVarianceUtilities.cvaMerge(["flex", "flex-1", "item
|
|
|
1259
1330
|
* @returns {JSX.Element} TimeRange component
|
|
1260
1331
|
*/
|
|
1261
1332
|
const TimeRange = ({ id, className, dataTestId, children, range, onChange, disabled, isInvalid, }) => {
|
|
1262
|
-
var _a, _b;
|
|
1263
1333
|
const [timeRange, setTimeRange] = React__default["default"].useState(range !== null && range !== void 0 ? range : {
|
|
1264
1334
|
timeFrom: "",
|
|
1265
1335
|
timeTo: "",
|
|
@@ -1271,7 +1341,7 @@ const TimeRange = ({ id, className, dataTestId, children, range, onChange, disab
|
|
|
1271
1341
|
setTimeRange(prev => (Object.assign(Object.assign({}, prev), { timeTo })));
|
|
1272
1342
|
};
|
|
1273
1343
|
const onRangeChange = () => onChange(timeRange);
|
|
1274
|
-
return (jsxRuntime.jsxs("div", { className: cvaTimeRange({ className }), "data-testid": dataTestId, id: id, children: [jsxRuntime.jsx(BaseInput, { dataTestId: `${dataTestId}-from`, disabled: disabled, isInvalid: isInvalid, onBlur: onRangeChange, onChange: (time) => onChangeFrom(time.currentTarget.value), type: "time", value:
|
|
1344
|
+
return (jsxRuntime.jsxs("div", { className: cvaTimeRange({ className }), "data-testid": dataTestId, id: id, children: [jsxRuntime.jsx(BaseInput, { dataTestId: `${dataTestId}-from`, disabled: disabled, isInvalid: isInvalid, onBlur: onRangeChange, onChange: (time) => onChangeFrom(time.currentTarget.value), type: "time", value: timeRange.timeFrom }), children !== null && children !== void 0 ? children : jsxRuntime.jsx("div", { "data-testid": `${dataTestId}-separator`, children: "-" }), jsxRuntime.jsx(BaseInput, { dataTestId: `${dataTestId}-to`, disabled: disabled, isInvalid: isInvalid, onBlur: onRangeChange, onChange: (time) => onChangeTo(time.currentTarget.value), type: "time", value: timeRange.timeTo })] }));
|
|
1275
1345
|
};
|
|
1276
1346
|
|
|
1277
1347
|
const cvaScheduleItem = cssClassVarianceUtilities.cvaMerge(["grid", "pb-4", "gap-2", "grid-cols-[60px,200px,60px,2fr]"]);
|
|
@@ -1298,7 +1368,7 @@ const Schedule = ({ className, dataTestId, schedule, onChange, invalidKeys = []
|
|
|
1298
1368
|
onChange(newSchedule);
|
|
1299
1369
|
};
|
|
1300
1370
|
return (jsxRuntime.jsx("div", { className: className, "data-testid": dataTestId, children: schedule.map(({ label, range, isActive, key, checkboxLabel, isAllDayActive }, index) => {
|
|
1301
|
-
return (jsxRuntime.jsxs("div", { className: cvaScheduleItem(), children: [jsxRuntime.jsx(Checkbox, { checked: isActive, dataTestId: `${dataTestId}-${key}-checkbox`, label: checkboxLabel, onChange: (event) => onActiveChange(Boolean(event.currentTarget.checked), index) }), jsxRuntime.jsx(reactComponents.Text, { className: cvaScheduleItemText(), size: "medium", subtle: !isActive, children: label }), jsxRuntime.jsx(Checkbox, { checked: isAllDayActive
|
|
1371
|
+
return (jsxRuntime.jsxs("div", { className: cvaScheduleItem(), children: [jsxRuntime.jsx(Checkbox, { checked: isActive, dataTestId: `${dataTestId}-${key}-checkbox`, label: checkboxLabel, onChange: (event) => onActiveChange(Boolean(event.currentTarget.checked), index) }), jsxRuntime.jsx(reactComponents.Text, { className: cvaScheduleItemText(), size: "medium", subtle: !isActive, children: label }), jsxRuntime.jsx(Checkbox, { checked: isAllDayActive ? isActive : undefined, dataTestId: `${dataTestId}-${key}-allday-checkbox`, disabled: !isActive, onChange: (event) => onAllDayChange(Boolean(event.currentTarget.checked), index) }), jsxRuntime.jsx(TimeRange, { dataTestId: `${dataTestId}-${key}-range`, disabled: !isActive || isAllDayActive, isInvalid: !!invalidKeys.find((invalidKey) => invalidKey === key), onChange: (newRange) => onRangeChange(newRange, index), range: range })] }, key + label));
|
|
1302
1372
|
}) }));
|
|
1303
1373
|
};
|
|
1304
1374
|
|
|
@@ -1346,32 +1416,19 @@ const parseSchedule = (scheduleString) => {
|
|
|
1346
1416
|
};
|
|
1347
1417
|
});
|
|
1348
1418
|
const filteredSchedule = schedule
|
|
1349
|
-
.filter(daySchedule =>
|
|
1350
|
-
.map(daySchedule => ({
|
|
1419
|
+
.filter(daySchedule => "range" in daySchedule && daySchedule.range)
|
|
1420
|
+
.map(daySchedule => ({
|
|
1421
|
+
day: daySchedule.day,
|
|
1422
|
+
range: daySchedule.range,
|
|
1423
|
+
isAllDay: daySchedule.isAllDay,
|
|
1424
|
+
}));
|
|
1351
1425
|
let variant;
|
|
1352
1426
|
switch (schedule.length) {
|
|
1353
1427
|
case 7:
|
|
1354
|
-
|
|
1355
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1356
|
-
return ((_b = (_a = collection === null || collection === void 0 ? void 0 : collection[0]) === null || _a === void 0 ? void 0 : _a.range) === null || _b === void 0 ? void 0 : _b.timeFrom) === ((_c = day === null || day === void 0 ? void 0 : day.range) === null || _c === void 0 ? void 0 : _c.timeFrom) &&
|
|
1357
|
-
((_e = (_d = collection === null || collection === void 0 ? void 0 : collection[0]) === null || _d === void 0 ? void 0 : _d.range) === null || _e === void 0 ? void 0 : _e.timeTo) === ((_f = day === null || day === void 0 ? void 0 : day.range) === null || _f === void 0 ? void 0 : _f.timeTo);
|
|
1358
|
-
});
|
|
1359
|
-
if (areEqual) {
|
|
1360
|
-
variant = exports.ScheduleVariant.ALL_DAYS;
|
|
1361
|
-
}
|
|
1362
|
-
else {
|
|
1363
|
-
variant = exports.ScheduleVariant.CUSTOM;
|
|
1364
|
-
}
|
|
1428
|
+
variant = isUniform(schedule) ? exports.ScheduleVariant.ALL_DAYS : exports.ScheduleVariant.CUSTOM;
|
|
1365
1429
|
break;
|
|
1366
1430
|
case 5:
|
|
1367
|
-
|
|
1368
|
-
const hasConsecutiveDays = schedule.every(({ day }, index) => day === days[index]);
|
|
1369
|
-
if (hasConsecutiveDays) {
|
|
1370
|
-
variant = exports.ScheduleVariant.WEEKDAYS;
|
|
1371
|
-
}
|
|
1372
|
-
else {
|
|
1373
|
-
variant = exports.ScheduleVariant.CUSTOM;
|
|
1374
|
-
}
|
|
1431
|
+
variant = hasConsecutiveDays(schedule) ? exports.ScheduleVariant.WEEKDAYS : exports.ScheduleVariant.CUSTOM;
|
|
1375
1432
|
break;
|
|
1376
1433
|
default:
|
|
1377
1434
|
return {
|
|
@@ -1393,7 +1450,7 @@ const parseSchedule = (scheduleString) => {
|
|
|
1393
1450
|
const serializeSchedule = (weekSchedule) => {
|
|
1394
1451
|
return weekSchedule.schedule
|
|
1395
1452
|
.filter(({ range, day, isAllDay }) => {
|
|
1396
|
-
const hasRange =
|
|
1453
|
+
const hasRange = range.timeFrom && range.timeTo;
|
|
1397
1454
|
switch (weekSchedule.variant) {
|
|
1398
1455
|
case exports.ScheduleVariant.WEEKDAYS:
|
|
1399
1456
|
return day <= 5 && hasRange;
|
|
@@ -1412,6 +1469,25 @@ const serializeSchedule = (weekSchedule) => {
|
|
|
1412
1469
|
})
|
|
1413
1470
|
.join(",");
|
|
1414
1471
|
};
|
|
1472
|
+
/**
|
|
1473
|
+
* Checks if a list of schedule objects have the same ranges
|
|
1474
|
+
*
|
|
1475
|
+
* @param {RawSchedule[]} schedule List of schedule objects
|
|
1476
|
+
* @returns {boolean} Whether the schedule is uniform
|
|
1477
|
+
*/
|
|
1478
|
+
const isUniform = (schedule) => {
|
|
1479
|
+
return schedule.every((day, _, collection) => { var _a, _b, _c, _d, _e, _f; return ((_b = (_a = collection[0]) === null || _a === void 0 ? void 0 : _a.range) === null || _b === void 0 ? void 0 : _b.timeFrom) === ((_c = day.range) === null || _c === void 0 ? void 0 : _c.timeFrom) && ((_e = (_d = collection[0]) === null || _d === void 0 ? void 0 : _d.range) === null || _e === void 0 ? void 0 : _e.timeTo) === ((_f = day.range) === null || _f === void 0 ? void 0 : _f.timeTo); });
|
|
1480
|
+
};
|
|
1481
|
+
/**
|
|
1482
|
+
* Checks if a list of schedule objects are consecutive days
|
|
1483
|
+
*
|
|
1484
|
+
* @param {RawSchedule[]} schedule List of schedule objects
|
|
1485
|
+
* @returns {boolean} Whether the schedule has consecutive days
|
|
1486
|
+
*/
|
|
1487
|
+
const hasConsecutiveDays = (schedule) => {
|
|
1488
|
+
const days = [1, 2, 3, 4, 5];
|
|
1489
|
+
return schedule.every(({ day }, index) => day === days[index]);
|
|
1490
|
+
};
|
|
1415
1491
|
|
|
1416
1492
|
/**
|
|
1417
1493
|
* A thin wrapper around the `BaseInput` component for text input fields.
|
|
@@ -1419,6 +1495,7 @@ const serializeSchedule = (weekSchedule) => {
|
|
|
1419
1495
|
* NOTE: If shown with a label, please use the `TextField` component instead.
|
|
1420
1496
|
*/
|
|
1421
1497
|
const TextInput = React.forwardRef((props, ref) => (jsxRuntime.jsx(BaseInput, Object.assign({ ref: ref, type: "text" }, props))));
|
|
1498
|
+
TextInput.displayName = "TextInput";
|
|
1422
1499
|
|
|
1423
1500
|
const cvaSearch = cssClassVarianceUtilities.cvaMerge([
|
|
1424
1501
|
"shadow-none",
|
|
@@ -1426,21 +1503,13 @@ const cvaSearch = cssClassVarianceUtilities.cvaMerge([
|
|
|
1426
1503
|
"component-search-background",
|
|
1427
1504
|
"hover:component-search-background",
|
|
1428
1505
|
"hover:component-search-focus-hover",
|
|
1429
|
-
"focus:component-search-focus-hover",
|
|
1430
|
-
"focus-within:component-search-focus-within",
|
|
1431
1506
|
"transition-all",
|
|
1432
1507
|
"duration-300",
|
|
1433
1508
|
], {
|
|
1434
1509
|
variants: {
|
|
1435
1510
|
border: { true: ["!component-search-borderless"], false: "" },
|
|
1436
1511
|
widenOnFocus: {
|
|
1437
|
-
true: [
|
|
1438
|
-
"component-search-width",
|
|
1439
|
-
"component-search-widen",
|
|
1440
|
-
"hover:component-search-widen",
|
|
1441
|
-
"focus-within:component-search-widen-focus",
|
|
1442
|
-
"focus-within:w-full",
|
|
1443
|
-
],
|
|
1512
|
+
true: ["component-search-width", "component-search-widen", "hover:component-search-widen"],
|
|
1444
1513
|
false: "w-full",
|
|
1445
1514
|
},
|
|
1446
1515
|
},
|
|
@@ -1454,35 +1523,30 @@ const cvaSearch = cssClassVarianceUtilities.cvaMerge([
|
|
|
1454
1523
|
*/
|
|
1455
1524
|
const Search = React.forwardRef((_a, ref) => {
|
|
1456
1525
|
var { className, placeholder = "Search", value, widenInputOnFocus, hideBorderWhenNotInFocus = false, disabled, onKeyUp, onChange, onFocus, onBlur, name, onClear, dataTestId, autoComplete = "on" } = _a, rest = __rest(_a, ["className", "placeholder", "value", "widenInputOnFocus", "hideBorderWhenNotInFocus", "disabled", "onKeyUp", "onChange", "onFocus", "onBlur", "name", "onClear", "dataTestId", "autoComplete"]);
|
|
1457
|
-
return (jsxRuntime.jsx(TextInput, Object.assign({}, rest, { autoComplete: autoComplete, className: cvaSearch({ className, border: hideBorderWhenNotInFocus, widenOnFocus: widenInputOnFocus }), dataTestId: dataTestId, disabled: disabled, name: name, onBlur: onBlur, onChange: onChange, onFocus: onFocus, onKeyUp: onKeyUp, placeholder: placeholder, prefix: jsxRuntime.jsx(reactComponents.Icon, { name: "MagnifyingGlass", size: "medium" }), ref: ref, suffix: onClear ? (jsxRuntime.jsx("button", { className: "flex", "data-testid": dataTestId
|
|
1526
|
+
return (jsxRuntime.jsx(TextInput, Object.assign({}, rest, { autoComplete: autoComplete, className: cvaSearch({ className, border: hideBorderWhenNotInFocus, widenOnFocus: widenInputOnFocus }), dataTestId: dataTestId, disabled: disabled, name: name, onBlur: onBlur, onChange: onChange, onFocus: onFocus, onKeyUp: onKeyUp, placeholder: placeholder, prefix: jsxRuntime.jsx(reactComponents.Icon, { name: "MagnifyingGlass", size: "medium" }), ref: ref, suffix: onClear ? (jsxRuntime.jsx("button", { className: "flex", "data-testid": dataTestId ? `${dataTestId}_suffix_component` : null, onClick: () => {
|
|
1458
1527
|
onClear();
|
|
1459
1528
|
}, children: jsxRuntime.jsx(reactComponents.Icon, { name: "XMark", size: "small" }) })) : undefined, value: value })));
|
|
1460
1529
|
});
|
|
1530
|
+
Search.displayName = "Search";
|
|
1461
1531
|
|
|
1462
1532
|
const cvaSelect = cssClassVarianceUtilities.cvaMerge([
|
|
1463
1533
|
"relative",
|
|
1464
1534
|
"flex",
|
|
1465
1535
|
"shadow-sm",
|
|
1466
1536
|
"rounded-lg",
|
|
1467
|
-
"border",
|
|
1468
1537
|
"border-slate-300",
|
|
1469
|
-
"focus-within:ring-2",
|
|
1470
|
-
"focus-within:ring-inset",
|
|
1471
|
-
"focus-within:ring-primary-600",
|
|
1472
|
-
"focus-within:border-slate-400",
|
|
1473
1538
|
"hover:border-slate-400",
|
|
1474
1539
|
"hover:bg-slate-50",
|
|
1475
1540
|
"bg-white",
|
|
1476
1541
|
"transition",
|
|
1477
|
-
"overflow-hidden",
|
|
1478
1542
|
], {
|
|
1479
1543
|
variants: {
|
|
1480
1544
|
invalid: {
|
|
1481
|
-
true: "border-red-600 text-red-600
|
|
1545
|
+
true: "border border-red-600 text-red-600 hover:border-red-600",
|
|
1482
1546
|
false: "",
|
|
1483
1547
|
},
|
|
1484
1548
|
disabled: {
|
|
1485
|
-
true: "!bg-slate-100",
|
|
1549
|
+
true: "!bg-slate-100 hover:border-slate-300",
|
|
1486
1550
|
false: "",
|
|
1487
1551
|
},
|
|
1488
1552
|
},
|
|
@@ -1491,10 +1555,56 @@ const cvaSelect = cssClassVarianceUtilities.cvaMerge([
|
|
|
1491
1555
|
disabled: false,
|
|
1492
1556
|
},
|
|
1493
1557
|
});
|
|
1494
|
-
const
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1558
|
+
const cvaSelectControl = cssClassVarianceUtilities.cvaMerge([], {
|
|
1559
|
+
variants: {
|
|
1560
|
+
isDisabled: {
|
|
1561
|
+
true: "!bg-slate-100",
|
|
1562
|
+
false: "",
|
|
1563
|
+
},
|
|
1564
|
+
prefix: {
|
|
1565
|
+
true: ["ps-7"],
|
|
1566
|
+
false: "",
|
|
1567
|
+
},
|
|
1568
|
+
invalid: {
|
|
1569
|
+
true: "!border-0",
|
|
1570
|
+
false: "",
|
|
1571
|
+
},
|
|
1572
|
+
},
|
|
1573
|
+
defaultVariants: {
|
|
1574
|
+
isDisabled: false,
|
|
1575
|
+
prefix: false,
|
|
1576
|
+
invalid: false,
|
|
1577
|
+
},
|
|
1578
|
+
});
|
|
1579
|
+
const cvaSelectIcon = cssClassVarianceUtilities.cvaMerge([
|
|
1580
|
+
"mr-2",
|
|
1581
|
+
"flex",
|
|
1582
|
+
"cursor-pointer",
|
|
1583
|
+
"items-center",
|
|
1584
|
+
"justify-center",
|
|
1585
|
+
"text-slate-400",
|
|
1586
|
+
"hover:text-slate-500",
|
|
1587
|
+
]);
|
|
1588
|
+
const cvaSelectPrefix = cssClassVarianceUtilities.cvaMerge([
|
|
1589
|
+
"flex",
|
|
1590
|
+
"justify-center",
|
|
1591
|
+
"items-center",
|
|
1592
|
+
"text-slate-400",
|
|
1593
|
+
"pl-2",
|
|
1594
|
+
"absolute",
|
|
1595
|
+
"inset-y-0",
|
|
1596
|
+
]);
|
|
1597
|
+
const cvaSelectXIcon = cssClassVarianceUtilities.cvaMerge([
|
|
1598
|
+
"mr-2",
|
|
1599
|
+
"flex",
|
|
1600
|
+
"cursor-pointer",
|
|
1601
|
+
"items-center",
|
|
1602
|
+
"justify-center",
|
|
1603
|
+
"text-slate-400",
|
|
1604
|
+
"hover:text-slate-500",
|
|
1605
|
+
"ml-1",
|
|
1606
|
+
]);
|
|
1607
|
+
const cvaSelectMenuList = cssClassVarianceUtilities.cvaMerge([], {
|
|
1498
1608
|
variants: {
|
|
1499
1609
|
menuIsOpen: {
|
|
1500
1610
|
true: "animate-fade-in-fast",
|
|
@@ -1518,6 +1628,8 @@ function isMultiValue(arg) {
|
|
|
1518
1628
|
return Array.isArray(arg);
|
|
1519
1629
|
}
|
|
1520
1630
|
function isGroupBase(arg) {
|
|
1631
|
+
// This is apparently needed
|
|
1632
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1521
1633
|
return arg.options !== undefined;
|
|
1522
1634
|
}
|
|
1523
1635
|
const isSelectedOption = (option, selected) => {
|
|
@@ -1553,7 +1665,7 @@ const getOrderedOptions = (options, value) => {
|
|
|
1553
1665
|
.filter(option => !isSelectedOption(option, value))
|
|
1554
1666
|
.map(option => removeSelectedFromGroups(option, value));
|
|
1555
1667
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1556
|
-
return orderedValues.concat(selectableOptions)
|
|
1668
|
+
return orderedValues.concat(selectableOptions);
|
|
1557
1669
|
}
|
|
1558
1670
|
return options || [];
|
|
1559
1671
|
};
|
|
@@ -1614,7 +1726,7 @@ const TagsContainer = ({ items, width = "100%", itemsGap = 5, postFix, disabled
|
|
|
1614
1726
|
const itemsCount = items.length;
|
|
1615
1727
|
React__default["default"].useLayoutEffect(() => {
|
|
1616
1728
|
var _a;
|
|
1617
|
-
availableWidth.current = ((_a = containerRef
|
|
1729
|
+
availableWidth.current = ((_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0;
|
|
1618
1730
|
}, [containerRef]);
|
|
1619
1731
|
const onWidthKnownHandler = ({ width: reportedWidth }) => {
|
|
1620
1732
|
childrenWidth.current.push({ width: reportedWidth + itemsGap });
|
|
@@ -1626,7 +1738,7 @@ const TagsContainer = ({ items, width = "100%", itemsGap = 5, postFix, disabled
|
|
|
1626
1738
|
return previous + current.width;
|
|
1627
1739
|
}, 0);
|
|
1628
1740
|
let counter = 0;
|
|
1629
|
-
const availableSpace = (
|
|
1741
|
+
const availableSpace = (availableWidth.current || 0) - counterWidth;
|
|
1630
1742
|
const renderedElements = items
|
|
1631
1743
|
.concat({ text: "", onClick: () => null, disabled: false }) // reserved element for a potential counter
|
|
1632
1744
|
.map((item, index) => {
|
|
@@ -1675,7 +1787,7 @@ const TagsContainer = ({ items, width = "100%", itemsGap = 5, postFix, disabled
|
|
|
1675
1787
|
* @param {JSX.Element} dropdownIcon an custom dropdown icon
|
|
1676
1788
|
* @returns {Partial<SelectComponents<Option, boolean, GroupBase<Option>>> | undefined} components object to override react-select default components
|
|
1677
1789
|
*/
|
|
1678
|
-
const useCustomComponents = (componentsProps, disabled, menuIsOpen, refMenuIsEnabled, dataTestId, maxSelectedDisplayCount, dropdownIcon) => {
|
|
1790
|
+
const useCustomComponents = (componentsProps, disabled, menuIsOpen, refMenuIsEnabled, dataTestId, maxSelectedDisplayCount, dropdownIcon, prefix, hasError) => {
|
|
1679
1791
|
const [t] = useTranslation();
|
|
1680
1792
|
// perhaps it should not be wrap in memo (causing some issues with opening and closing on mobiles)
|
|
1681
1793
|
const customComponents = React__namespace.useMemo(() => {
|
|
@@ -1683,9 +1795,12 @@ const useCustomComponents = (componentsProps, disabled, menuIsOpen, refMenuIsEna
|
|
|
1683
1795
|
var _a;
|
|
1684
1796
|
if (props.isMulti && Array.isArray(props.children) && props.children.length > 0) {
|
|
1685
1797
|
const PLACEHOLDER_KEY = "placeholder";
|
|
1798
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1686
1799
|
const key = props && props.children && props.children[0] ? (_a = props.children[0]) === null || _a === void 0 ? void 0 : _a.key : "";
|
|
1800
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1687
1801
|
const values = props && props.children ? props.children[0] : [];
|
|
1688
1802
|
const tags = key === PLACEHOLDER_KEY ? [] : values;
|
|
1803
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1689
1804
|
const searchInput = props && props.children && props.children[1];
|
|
1690
1805
|
return (jsxRuntime.jsx(ReactSelect.components.ValueContainer, Object.assign({}, props, { isDisabled: props.selectProps.isDisabled, children: maxSelectedDisplayCount === undefined ? (jsxRuntime.jsx(TagsContainer, { disabled: disabled, items: tags
|
|
1691
1806
|
? tags.map(({ props: tagProps }) => {
|
|
@@ -1694,27 +1809,26 @@ const useCustomComponents = (componentsProps, disabled, menuIsOpen, refMenuIsEna
|
|
|
1694
1809
|
onClick: disabled
|
|
1695
1810
|
? undefined
|
|
1696
1811
|
: (e) => {
|
|
1697
|
-
var _a, _b;
|
|
1698
1812
|
refMenuIsEnabled.current = false;
|
|
1699
|
-
|
|
1813
|
+
tagProps.removeProps.onClick && tagProps.removeProps.onClick(e);
|
|
1700
1814
|
},
|
|
1701
1815
|
disabled: disabled,
|
|
1702
1816
|
};
|
|
1703
1817
|
})
|
|
1704
|
-
: [], postFix: searchInput, width: "100%" })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [tags
|
|
1705
|
-
tags.slice(0, maxSelectedDisplayCount).map(({ props: tagProps }) => {
|
|
1706
|
-
var _a
|
|
1707
|
-
return (jsxRuntime.jsx(reactComponents.Tag, { className: "inline-flex shrink-0", color: disabled ? "unknown" : "primary", dataTestId: tagProps.children ? `${
|
|
1708
|
-
var _a, _b;
|
|
1818
|
+
: [], postFix: searchInput, width: "100%" })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [tags
|
|
1819
|
+
? tags.slice(0, maxSelectedDisplayCount).map(({ props: tagProps }) => {
|
|
1820
|
+
var _a;
|
|
1821
|
+
return (jsxRuntime.jsx(reactComponents.Tag, { className: "inline-flex shrink-0", color: disabled ? "unknown" : "primary", dataTestId: tagProps.children ? `${tagProps.children.toString()}-tag` : undefined, onClose: e => {
|
|
1709
1822
|
e.stopPropagation();
|
|
1710
1823
|
refMenuIsEnabled.current = false;
|
|
1711
|
-
|
|
1712
|
-
}, children: tagProps.children }, (
|
|
1713
|
-
})
|
|
1824
|
+
tagProps.removeProps.onClick && tagProps.removeProps.onClick(e);
|
|
1825
|
+
}, children: tagProps.children }, (_a = tagProps.children) === null || _a === void 0 ? void 0 : _a.toString()));
|
|
1826
|
+
})
|
|
1827
|
+
: null, tags && tags.length > maxSelectedDisplayCount ? (jsxRuntime.jsxs(reactComponents.Tag, { color: "neutral", dataTestId: "counter-tag", children: ["+", tags.length - maxSelectedDisplayCount] })) : null, searchInput] })) })));
|
|
1714
1828
|
}
|
|
1715
1829
|
return (jsxRuntime.jsx(ReactSelect.components.ValueContainer, Object.assign({}, props, { isDisabled: props.selectProps.isDisabled, children: props.children })));
|
|
1716
1830
|
}, LoadingIndicator: props => {
|
|
1717
|
-
return jsxRuntime.jsx(reactComponents.Spinner, { className: "mt-1.5
|
|
1831
|
+
return jsxRuntime.jsx(reactComponents.Spinner, { className: "mr-1 mt-1.5", size: "small" });
|
|
1718
1832
|
}, DropdownIndicator: props => {
|
|
1719
1833
|
const icon = props.selectProps.menuIsOpen ? (jsxRuntime.jsx(reactComponents.Icon, { name: "ChevronUp", size: "medium" })) : (jsxRuntime.jsx(reactComponents.Icon, { name: "ChevronDown", size: "medium" }));
|
|
1720
1834
|
return props.selectProps.isLoading ? null : (jsxRuntime.jsx(ReactSelect.components.DropdownIndicator, Object.assign({}, props, { children: jsxRuntime.jsx("div", { className: cvaSelectIcon(), children: dropdownIcon ? dropdownIcon : icon }) })));
|
|
@@ -1722,9 +1836,13 @@ const useCustomComponents = (componentsProps, disabled, menuIsOpen, refMenuIsEna
|
|
|
1722
1836
|
if (disabled) {
|
|
1723
1837
|
return null;
|
|
1724
1838
|
}
|
|
1725
|
-
return (jsxRuntime.jsx(ReactSelect.components.ClearIndicator, Object.assign({}, props, { children: jsxRuntime.jsx("div", { className: cvaSelectXIcon(), "data-testid": dataTestId
|
|
1839
|
+
return (jsxRuntime.jsx(ReactSelect.components.ClearIndicator, Object.assign({}, props, { children: jsxRuntime.jsx("div", { className: cvaSelectXIcon(), "data-testid": dataTestId ? `${dataTestId}-XMarkIcon` : null, onClick: props.clearValue, children: jsxRuntime.jsx(reactComponents.Icon, { name: "XCircle", size: "medium", title: t("clearIndicator.icon.tooltip.clearAll") }) }) })));
|
|
1726
1840
|
}, Control: props => {
|
|
1727
|
-
return jsxRuntime.jsx(ReactSelect.components.Control, Object.assign({}, props, { className:
|
|
1841
|
+
return (jsxRuntime.jsx(ReactSelect.components.Control, Object.assign({}, props, { className: cvaSelectControl({
|
|
1842
|
+
isDisabled: props.isDisabled,
|
|
1843
|
+
prefix: prefix ? true : false,
|
|
1844
|
+
invalid: hasError,
|
|
1845
|
+
}) })));
|
|
1728
1846
|
}, SingleValue: props => {
|
|
1729
1847
|
return (jsxRuntime.jsx(ReactSelect.components.SingleValue, Object.assign({}, props, { className: props.isDisabled ? "text-slate-700" : "", children: jsxRuntime.jsx("div", { "data-testid": dataTestId + "-singleValue", children: props.children }) })));
|
|
1730
1848
|
}, Menu: props => {
|
|
@@ -1764,18 +1882,16 @@ const useCustomComponents = (componentsProps, disabled, menuIsOpen, refMenuIsEna
|
|
|
1764
1882
|
const useCustomStyles = (refContainer, refPrefix, maxSelectedDisplayCount, styles, disabled) => {
|
|
1765
1883
|
const customStyles = React__namespace.useMemo(() => {
|
|
1766
1884
|
return Object.assign({ control: base => {
|
|
1767
|
-
return Object.assign(Object.assign({}, base), {
|
|
1768
|
-
border: "0",
|
|
1769
|
-
}, backgroundColor: "" });
|
|
1885
|
+
return Object.assign(Object.assign({}, base), { borderRadius: "var(--border-radius-lg)", backgroundColor: "" });
|
|
1770
1886
|
}, singleValue: base => (Object.assign({}, base)), multiValue: base => (Object.assign({}, base)), multiValueLabel: base => (Object.assign({}, base)), indicatorsContainer: base => (Object.assign(Object.assign({}, base), (disabled && { display: "none" }))), indicatorSeparator: () => ({
|
|
1771
1887
|
width: "0px",
|
|
1772
1888
|
}), menu: base => {
|
|
1773
1889
|
return Object.assign(Object.assign({}, base), { width: "100%", marginTop: "4px", marginBottom: "18px", transition: "all 1s ease-in-out" });
|
|
1774
|
-
}, input: base => (Object.assign(Object.assign({}, base), { marginLeft: "0px" })), placeholder: base => (Object.assign({}, base)), option: () => ({}), menuPortal: base => (Object.assign(Object.assign({}, base), { width:
|
|
1890
|
+
}, input: base => (Object.assign(Object.assign({}, base), { marginLeft: "0px" })), placeholder: base => (Object.assign({}, base)), option: () => ({}), menuPortal: base => (Object.assign(Object.assign({}, base), { width: refContainer.current ? `${refContainer.current.clientWidth}px` : base.width, transform: "translate(0px, 0px)", backgroundColor: "#ffffff", borderRadius: "var(--border-radius-lg)", zIndex: 20, borderColor: "rgb(var(--color-slate-300))", boxShadow: "var(--tw-ring-inset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)" })), menuList: base => {
|
|
1775
1891
|
return Object.assign(Object.assign({}, base), { position: "relative", padding: "var(--spacing-1)", display: "grid", gap: "var(--spacing-1)", width: "100%", borderRadius: "0px", boxShadow: "none", paddingTop: "0px" });
|
|
1776
1892
|
}, valueContainer: base => {
|
|
1777
1893
|
return Object.assign(Object.assign({}, base), { flexWrap: maxSelectedDisplayCount !== undefined ? "wrap" : "nowrap", gap: "0.25rem" });
|
|
1778
|
-
}, container: base => (Object.assign(Object.assign({}, base), {
|
|
1894
|
+
}, container: base => (Object.assign(Object.assign({}, base), { width: "100%" })), dropdownIndicator: base => (Object.assign(Object.assign({}, base), { padding: "0px" })), clearIndicator: base => {
|
|
1779
1895
|
return Object.assign(Object.assign({}, base), { padding: "0px" });
|
|
1780
1896
|
} }, styles);
|
|
1781
1897
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -1797,7 +1913,7 @@ const useSelect = (_a) => {
|
|
|
1797
1913
|
const { customStyles } = useCustomStyles(refContainer, refPrefix, maxSelectedDisplayCount, styles, disabled);
|
|
1798
1914
|
const [menuIsOpen, setMenuIsOpen] = React__default["default"].useState((_b = props.menuIsOpen) !== null && _b !== void 0 ? _b : false);
|
|
1799
1915
|
const refMenuIsEnabled = React__default["default"].useRef(true);
|
|
1800
|
-
const customComponents = useCustomComponents(components, disabled || false, menuIsOpen, refMenuIsEnabled, dataTestId, maxSelectedDisplayCount, dropdownIcon);
|
|
1916
|
+
const customComponents = useCustomComponents(components, disabled || false, menuIsOpen, refMenuIsEnabled, dataTestId, maxSelectedDisplayCount, dropdownIcon, prefix, hasError);
|
|
1801
1917
|
const menuPlacement = "auto";
|
|
1802
1918
|
const openMenuHandler = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1803
1919
|
onMenuOpen && onMenuOpen();
|
|
@@ -1840,7 +1956,7 @@ const useSelect = (_a) => {
|
|
|
1840
1956
|
*/
|
|
1841
1957
|
const CreatableSelect = (props) => {
|
|
1842
1958
|
const { className, placeholder } = props, rest = __rest(props, ["className", "placeholder"]);
|
|
1843
|
-
const { id, dataTestId = "creatableSelect", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, value, options, onChange, isLoading, classNamePrefix = dataTestId
|
|
1959
|
+
const { id, dataTestId = "creatableSelect", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, value, options, onChange, isLoading, classNamePrefix = dataTestId, onMenuScrollToBottom, filterOption, onInputChange, isSearchable, isClearable = false, readOnly, openMenuOnClick = !disabled, openMenuOnFocus = !disabled, allowCreateWhileLoading, onCreateOption, } = rest;
|
|
1844
1960
|
const { refContainer, refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler, orderedOptions, } = useSelect(props);
|
|
1845
1961
|
const creatableSelectProps = {
|
|
1846
1962
|
value,
|
|
@@ -1870,9 +1986,11 @@ const CreatableSelect = (props) => {
|
|
|
1870
1986
|
onInputChange,
|
|
1871
1987
|
allowCreateWhileLoading,
|
|
1872
1988
|
onCreateOption,
|
|
1989
|
+
isDisabled: disabled || props.isDisabled,
|
|
1990
|
+
readOnly,
|
|
1873
1991
|
};
|
|
1874
1992
|
const renderAsDisabled = rest.disabled || rest.readOnly || rest.isDisabled; // TODO remove one of the disable props from the type
|
|
1875
|
-
return (jsxRuntime.jsxs("div", { className: cvaSelect({ invalid: hasError, disabled: disabled || readOnly, className }), "data-testid": dataTestId, ref: refContainer, children: [prefix !== undefined && (jsxRuntime.jsx("div", { className: cvaSelectPrefix(), "data-testid": dataTestId
|
|
1993
|
+
return (jsxRuntime.jsxs("div", { className: cvaSelect({ invalid: hasError, disabled: disabled || readOnly, className }), "data-testid": dataTestId, ref: refContainer, children: [prefix !== undefined && (jsxRuntime.jsx("div", { className: cvaSelectPrefix(), "data-testid": dataTestId ? `${dataTestId}-prefix` : null, ref: refPrefix, children: prefix })), async ? (jsxRuntime.jsx(ReactAsyncCreatableSelect__default["default"], Object.assign({}, rest, creatableSelectProps, async, { onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, placeholder: renderAsDisabled ? null : placeholder }))) : (jsxRuntime.jsx(ReactCreatableSelect__default["default"], Object.assign({}, rest, creatableSelectProps, { hideSelectedOptions: false, isMulti: isMulti, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, options: filterOption ? orderedOptions : options, placeholder: renderAsDisabled ? null : placeholder })))] }));
|
|
1876
1994
|
};
|
|
1877
1995
|
CreatableSelect.displayName = "CreatableSelect";
|
|
1878
1996
|
|
|
@@ -1884,7 +2002,7 @@ CreatableSelect.displayName = "CreatableSelect";
|
|
|
1884
2002
|
*/
|
|
1885
2003
|
const Select = (props) => {
|
|
1886
2004
|
const { className, placeholder } = props, rest = __rest(props, ["className", "placeholder"]);
|
|
1887
|
-
const { id, dataTestId = "select", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, menuPosition = "absolute", value, options, onChange, isLoading, classNamePrefix = dataTestId
|
|
2005
|
+
const { id, dataTestId = "select", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, menuPosition = "absolute", value, options, onChange, isLoading, classNamePrefix = dataTestId, onMenuScrollToBottom, filterOption, onInputChange, isSearchable, isClearable = false, readOnly, openMenuOnClick = !disabled, openMenuOnFocus = !disabled, hideSelectedOptions = false, } = props;
|
|
1888
2006
|
const { refContainer, refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler, orderedOptions, } = useSelect(props);
|
|
1889
2007
|
const selectProps = {
|
|
1890
2008
|
value,
|
|
@@ -1913,9 +2031,11 @@ const Select = (props) => {
|
|
|
1913
2031
|
onMenuScrollToBottom,
|
|
1914
2032
|
onInputChange,
|
|
1915
2033
|
hideSelectedOptions,
|
|
2034
|
+
isDisabled: disabled || props.isDisabled,
|
|
2035
|
+
readOnly,
|
|
1916
2036
|
};
|
|
1917
2037
|
const renderAsDisabled = rest.disabled || rest.readOnly || rest.isDisabled; // TODO remove one of the disable props from the type
|
|
1918
|
-
return (jsxRuntime.jsxs("div", { className: cvaSelect({ invalid: hasError, disabled: disabled || readOnly, className }), "data-testid": dataTestId, ref: refContainer, children: [prefix !== undefined && (jsxRuntime.jsx("div", { className: cvaSelectPrefix(), "data-testid": dataTestId
|
|
2038
|
+
return (jsxRuntime.jsxs("div", { className: cvaSelect({ invalid: hasError, disabled: disabled || readOnly, className }), "data-testid": dataTestId, ref: refContainer, children: [prefix !== undefined && (jsxRuntime.jsx("div", { className: cvaSelectPrefix(), "data-testid": dataTestId ? `${dataTestId}-prefix` : null, ref: refPrefix, children: prefix })), async ? (jsxRuntime.jsx(ReactAsyncSelect__default["default"], Object.assign({}, rest, selectProps, async, { menuPosition: menuPosition, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, placeholder: renderAsDisabled ? null : placeholder }))) : (jsxRuntime.jsx(ReactSelect__default["default"], Object.assign({}, rest, selectProps, { isMulti: isMulti, menuPosition: menuPosition, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, options: filterOption ? orderedOptions : options, placeholder: renderAsDisabled ? null : placeholder })))] }));
|
|
1919
2039
|
};
|
|
1920
2040
|
Select.displayName = "Select";
|
|
1921
2041
|
|
|
@@ -1968,6 +2088,7 @@ const FormFieldSelectAdapter = React.forwardRef((_a, ref) => {
|
|
|
1968
2088
|
setInnerValue(!e ? "" : e.value);
|
|
1969
2089
|
}, value: selectedOption, defaultValue: selectedOption }))] }));
|
|
1970
2090
|
});
|
|
2091
|
+
FormFieldSelectAdapter.displayName = "FormFieldSelectAdapter";
|
|
1971
2092
|
|
|
1972
2093
|
/**
|
|
1973
2094
|
* The CreatableSelectField component is a CreatableSelect component wrapped in the FromGroup component.
|
|
@@ -1984,6 +2105,7 @@ const CreatableSelectField = React.forwardRef((_a, ref) => {
|
|
|
1984
2105
|
const creatableSelectOnlyProps = { allowCreateWhileLoading, onCreateOption };
|
|
1985
2106
|
return (jsxRuntime.jsx(FormFieldSelectAdapter, Object.assign({}, props, { ref: ref, children: convertedProps => jsxRuntime.jsx(CreatableSelect, Object.assign({}, convertedProps, creatableSelectOnlyProps)) })));
|
|
1986
2107
|
});
|
|
2108
|
+
CreatableSelectField.displayName = "CreatableSelectField";
|
|
1987
2109
|
|
|
1988
2110
|
/**
|
|
1989
2111
|
* The SelectField component is a Select component wrapped in the FromGroup component.
|
|
@@ -1999,6 +2121,7 @@ const SelectField = React.forwardRef((_a, ref) => {
|
|
|
1999
2121
|
var props = __rest(_a, []);
|
|
2000
2122
|
return (jsxRuntime.jsx(FormFieldSelectAdapter, Object.assign({}, props, { ref: ref, children: convertedProps => jsxRuntime.jsx(Select, Object.assign({}, convertedProps)) })));
|
|
2001
2123
|
});
|
|
2124
|
+
SelectField.displayName = "SelectField";
|
|
2002
2125
|
|
|
2003
2126
|
const cvaTextArea = cssClassVarianceUtilities.cvaMerge([
|
|
2004
2127
|
cvaInputBase(),
|
|
@@ -2010,7 +2133,6 @@ const cvaTextArea = cssClassVarianceUtilities.cvaMerge([
|
|
|
2010
2133
|
"text-base",
|
|
2011
2134
|
"text-slate-900",
|
|
2012
2135
|
"placeholder-slate-400",
|
|
2013
|
-
"focus-visible:outline-none",
|
|
2014
2136
|
"w-full",
|
|
2015
2137
|
"h-20",
|
|
2016
2138
|
"transition",
|
|
@@ -2041,6 +2163,7 @@ const TextArea = React__namespace.forwardRef((_a, ref) => {
|
|
|
2041
2163
|
var { id, name, value, rows, disabled, placeholder, readOnly, tabIndex, onChange, onFocus, onBlur, maxLength, resize = "vertical", defaultValue, required, dataTestId, isInvalid, className } = _a, rest = __rest(_a, ["id", "name", "value", "rows", "disabled", "placeholder", "readOnly", "tabIndex", "onChange", "onFocus", "onBlur", "maxLength", "resize", "defaultValue", "required", "dataTestId", "isInvalid", "className"]);
|
|
2042
2164
|
return (jsxRuntime.jsx("textarea", Object.assign({ className: cvaTextArea({ className, resize, invalid: isInvalid, disabled }), defaultValue: defaultValue, disabled: disabled, id: id, maxLength: maxLength, name: name, onBlur: onBlur, onFocus: onFocus, placeholder: placeholder, readOnly: readOnly, ref: ref, required: required, rows: rows, tabIndex: tabIndex, value: value }, rest, { "data-testid": dataTestId, onChange: onChange })));
|
|
2043
2165
|
});
|
|
2166
|
+
TextArea.displayName = "TextArea";
|
|
2044
2167
|
|
|
2045
2168
|
/**
|
|
2046
2169
|
* The TextLengthIndicator component shows a `{length}/{maxLength}` label.
|
|
@@ -2064,9 +2187,10 @@ const TextAreaField = React__namespace.forwardRef((_a, ref) => {
|
|
|
2064
2187
|
onChange(event);
|
|
2065
2188
|
}
|
|
2066
2189
|
}, [onChange]);
|
|
2067
|
-
return (jsxRuntime.jsx(FormGroup, { className:
|
|
2068
|
-
(
|
|
2190
|
+
return (jsxRuntime.jsx(FormGroup, { className: tailwindMerge.twMerge(className, "grid", "grid-rows-[auto_1fr_auto]"), dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, helpAddon: helpAddon ||
|
|
2191
|
+
(typeof maxLength === "number" && jsxRuntime.jsx(TextLengthIndicator, { length: valueLength, maxLength: maxLength })), helpText: errorMessage || helpText, htmlFor: htmlForId, isInvalid: renderAsInvalid, label: label, required: rest.required, tip: tip, children: jsxRuntime.jsx(TextArea, Object.assign({ "aria-labelledby": htmlForId + "-label", id: htmlForId, isInvalid: renderAsInvalid, maxLength: maxLength, ref: ref, value: value }, rest, { className: "h-auto", dataTestId: dataTestId, onChange: handleChange })) }));
|
|
2069
2192
|
});
|
|
2193
|
+
TextAreaField.displayName = "TextAreaField";
|
|
2070
2194
|
|
|
2071
2195
|
/**
|
|
2072
2196
|
* Text fields enable the user to interact with and input content and data. This component can be used for long and short form entries. Allow the size of the text input box to reflect the length of the content you expect the user to enter.
|
|
@@ -2086,9 +2210,10 @@ const TextField = React__namespace.forwardRef((_a, ref) => {
|
|
|
2086
2210
|
onChange(event);
|
|
2087
2211
|
}
|
|
2088
2212
|
}, [onChange]);
|
|
2089
|
-
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId
|
|
2090
|
-
(
|
|
2213
|
+
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, helpAddon: helpAddon ||
|
|
2214
|
+
(typeof maxLength === "number" && jsxRuntime.jsx(TextLengthIndicator, { length: valueLength, maxLength: maxLength })), helpText: (renderAsInvalid && errorMessage) || helpText, htmlFor: htmlFor, isInvalid: renderAsInvalid, label: label, required: rest.required, tip: tip, children: jsxRuntime.jsx(TextInput, Object.assign({ "aria-labelledby": htmlFor + "-label", id: htmlFor, isInvalid: renderAsInvalid, maxLength: maxLength, ref: ref, value: value }, rest, { className: className, dataTestId: dataTestId, onChange: handleChange })) }));
|
|
2091
2215
|
});
|
|
2216
|
+
TextField.displayName = "TextField";
|
|
2092
2217
|
|
|
2093
2218
|
/**
|
|
2094
2219
|
* TimeRangeField Description. <-- Please add a proper Description this is used in Storybook.
|
|
@@ -2100,21 +2225,12 @@ const TimeRangeField = (_a) => {
|
|
|
2100
2225
|
var { className, dataTestId, onChange, isInvalid, errorMessage, label, tip, disabled, children, helpText, id } = _a, rest = __rest(_a, ["className", "dataTestId", "onChange", "isInvalid", "errorMessage", "label", "tip", "disabled", "children", "helpText", "id"]);
|
|
2101
2226
|
const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
|
|
2102
2227
|
const htmlFor = id ? id : "timeRangeField-" + uuid.v4();
|
|
2103
|
-
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId
|
|
2228
|
+
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, disabled: disabled, helpText: (renderAsInvalid && errorMessage) || helpText, htmlFor: htmlFor, isInvalid: renderAsInvalid, label: label, tip: tip, children: jsxRuntime.jsx(TimeRange, Object.assign({ className: className, dataTestId: dataTestId, disabled: disabled, isInvalid: renderAsInvalid, onChange: onChange }, rest, { children: children })) }));
|
|
2104
2229
|
};
|
|
2105
2230
|
|
|
2106
2231
|
const cvaToggleWrapper = cssClassVarianceUtilities.cvaMerge(["flex", "gap-2", "items-center"]);
|
|
2107
2232
|
cssClassVarianceUtilities.cvaMerge(["relative"]);
|
|
2108
|
-
const cvaToggleTrack = cssClassVarianceUtilities.cvaMerge([
|
|
2109
|
-
"shrink-0",
|
|
2110
|
-
"p-1",
|
|
2111
|
-
"cursor-pointer",
|
|
2112
|
-
"rounded-full",
|
|
2113
|
-
"bg-slate-300",
|
|
2114
|
-
"focus:bg-slate-400",
|
|
2115
|
-
"hover:bg-slate-400",
|
|
2116
|
-
"active:bg-slate-500",
|
|
2117
|
-
], {
|
|
2233
|
+
const cvaToggleTrack = cssClassVarianceUtilities.cvaMerge(["shrink-0", "p-1", "cursor-pointer", "rounded-full", "bg-slate-300", "hover:bg-slate-400", "active:bg-slate-500"], {
|
|
2118
2234
|
variants: {
|
|
2119
2235
|
size: {
|
|
2120
2236
|
small: ["w-8", "h-4"],
|
|
@@ -2125,7 +2241,7 @@ const cvaToggleTrack = cssClassVarianceUtilities.cvaMerge([
|
|
|
2125
2241
|
false: "",
|
|
2126
2242
|
},
|
|
2127
2243
|
toggled: {
|
|
2128
|
-
true: ["bg-primary-600", "
|
|
2244
|
+
true: ["bg-primary-600", "hover:bg-primary-700", "active:bg-primary-800"],
|
|
2129
2245
|
false: "",
|
|
2130
2246
|
},
|
|
2131
2247
|
},
|
|
@@ -2175,11 +2291,12 @@ const Toggle = React__namespace.forwardRef(({ toggled = false, onChange, onClick
|
|
|
2175
2291
|
const showLabelContainer = Boolean(name || description);
|
|
2176
2292
|
const showDescription = Boolean(description);
|
|
2177
2293
|
const getTestId = (suffix) => `${dataTestId}-${suffix}`;
|
|
2178
|
-
return (jsxRuntime.jsx("span", { className: className, "data-testid": getTestId("outer-wrapper"), onClick: onClick, children: jsxRuntime.jsxs("label", { className: cvaToggleWrapper(), "data-testid": getTestId("wrapper"), htmlFor: id, children: [jsxRuntime.jsx("span", { className: cvaToggleTrack({ disabled, size, toggled }), "data-testid": getTestId("track"), children: jsxRuntime.jsx("span", { className: cvaToggleThumb({ toggled }), "data-testid": getTestId("thumb") }) }), showLabelContainer
|
|
2294
|
+
return (jsxRuntime.jsx("span", { className: className, "data-testid": getTestId("outer-wrapper"), onClick: onClick, children: jsxRuntime.jsxs("label", { className: cvaToggleWrapper(), "data-testid": getTestId("wrapper"), htmlFor: id, children: [jsxRuntime.jsx("span", { className: cvaToggleTrack({ disabled, size, toggled }), "data-testid": getTestId("track"), children: jsxRuntime.jsx("span", { className: cvaToggleThumb({ toggled }), "data-testid": getTestId("thumb") }) }), showLabelContainer ? (jsxRuntime.jsxs("span", { className: cvaToggleLabelContainer(), "data-testid": getTestId("label-container"), children: [jsxRuntime.jsx(Label, { className: cvaToggleLabel(), "data-testid": getTestId("label"), disabled: disabled, children: name }), showDescription ? (jsxRuntime.jsx("span", { className: cvaToggleDescription({ disabled }), "data-testid": getTestId("description"), children: description })) : null] })) : null, jsxRuntime.jsx("input", { "aria-checked": toggled, checked: toggled, className: cvaToggleInput(), "data-testid": getTestId("input"), disabled: disabled, id: id, name: name, onBlur: onBlur, onChange: e => {
|
|
2179
2295
|
e.stopPropagation();
|
|
2180
2296
|
onChange(!toggled, e);
|
|
2181
2297
|
}, ref: ref, required: required, tabIndex: tabIndex, type: "checkbox" })] }) }));
|
|
2182
2298
|
});
|
|
2299
|
+
Toggle.displayName = "Toggle";
|
|
2183
2300
|
|
|
2184
2301
|
const cvaUploadInputField = cssClassVarianceUtilities.cvaMerge([
|
|
2185
2302
|
"px-0",
|
|
@@ -2208,6 +2325,7 @@ const UploadInput = React.forwardRef((_a, ref) => {
|
|
|
2208
2325
|
}
|
|
2209
2326
|
}, ref: ref, type: "file" }, rest)) }));
|
|
2210
2327
|
});
|
|
2328
|
+
UploadInput.displayName = "UploadInput";
|
|
2211
2329
|
|
|
2212
2330
|
/**
|
|
2213
2331
|
* Upload fields enable the user to upload Files.
|
|
@@ -2218,6 +2336,7 @@ const UploadField = React.forwardRef((_a, ref) => {
|
|
|
2218
2336
|
const htmlForId = id ? id : "uploadField-" + uuid.v4();
|
|
2219
2337
|
return (jsxRuntime.jsx(FormGroup, { dataTestId: `${dataTestId}-FormGroup`, helpText: errorMessage || helpText, htmlFor: htmlForId, isInvalid: renderAsInvalid, label: label, required: rest.required, tip: tip, children: jsxRuntime.jsx(UploadInput, Object.assign({ "aria-labelledby": htmlForId + "-label", id: htmlForId, isInvalid: renderAsInvalid, ref: ref }, rest, { className: className, dataTestId: dataTestId })) }));
|
|
2220
2338
|
});
|
|
2339
|
+
UploadField.displayName = "UploadField";
|
|
2221
2340
|
|
|
2222
2341
|
/**
|
|
2223
2342
|
* @description Validate given url id.
|
|
@@ -2243,8 +2362,9 @@ const UrlInput = React.forwardRef((_a, ref) => {
|
|
|
2243
2362
|
var { dataTestId, isInvalid, disabled = false, fieldSize = "medium", disableAction = false, value, defaultValue } = _a, rest = __rest(_a, ["dataTestId", "isInvalid", "disabled", "fieldSize", "disableAction", "value", "defaultValue"]);
|
|
2244
2363
|
const [url, setUrl] = React.useState((value === null || value === void 0 ? void 0 : value.toString()) || (defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.toString()));
|
|
2245
2364
|
const renderAsInvalid = (url && typeof url === "string" && !validateUrlAddress(url)) || isInvalid;
|
|
2246
|
-
return (jsxRuntime.jsx(BaseInput, Object.assign({ dataTestId: dataTestId
|
|
2365
|
+
return (jsxRuntime.jsx(BaseInput, Object.assign({ dataTestId: dataTestId ? `${dataTestId}-url-input` : undefined, disabled: disabled, id: "url-input", isInvalid: renderAsInvalid, onChange: e => setUrl(e.target.value), placeholder: rest.placeholder || "https://www.example.com", ref: ref, type: "url", value: url }, rest, { actions: !disableAction && (jsxRuntime.jsx(ActionButton, { dataTestId: (dataTestId && `${dataTestId}-url-input-Icon`) || "url-input-action-icon", disabled: renderAsInvalid || disableAction, iconSize: fieldSize, type: "WEB_ADDRESS", value: url })) })));
|
|
2247
2366
|
});
|
|
2367
|
+
UrlInput.displayName = "UrlField";
|
|
2248
2368
|
|
|
2249
2369
|
/**
|
|
2250
2370
|
* The UrlField component is used to enter url.
|
|
@@ -2259,8 +2379,9 @@ const UrlField = React.forwardRef((_a, ref) => {
|
|
|
2259
2379
|
return typeof inputValue === "string";
|
|
2260
2380
|
}
|
|
2261
2381
|
const renderAsInvalid = !!errorMessage || (value && isString(value) && !validateUrlAddress(value)) || isInvalid;
|
|
2262
|
-
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId
|
|
2382
|
+
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, disabled: rest.disabled, helpAddon: helpAddon, helpText: renderAsInvalid ? errorMessage : helpText, htmlFor: htmlForId, isInvalid: renderAsInvalid, label: label, required: rest.required, tip: tip, children: jsxRuntime.jsx(UrlInput, Object.assign({ "aria-labelledby": htmlForId + "-label", id: htmlForId, isInvalid: renderAsInvalid, ref: ref, value: value || defaultValue }, rest, { className: className, dataTestId: dataTestId })) }));
|
|
2263
2383
|
});
|
|
2384
|
+
UrlField.displayName = "UrlField";
|
|
2264
2385
|
|
|
2265
2386
|
/**
|
|
2266
2387
|
* Custom hook to get phone number validation rules.
|
|
@@ -2277,7 +2398,7 @@ const useGetPhoneValidationRules = () => {
|
|
|
2277
2398
|
const pattern = {
|
|
2278
2399
|
validate: (value) => {
|
|
2279
2400
|
const validationResult = t(`phoneField.error.${validatePhoneNumber(value)}`);
|
|
2280
|
-
return !validationResult || value
|
|
2401
|
+
return !validationResult || !value || validationResult;
|
|
2281
2402
|
},
|
|
2282
2403
|
};
|
|
2283
2404
|
return !skipValidation
|
|
@@ -2418,6 +2539,7 @@ exports.countryCodeToFlagEmoji = countryCodeToFlagEmoji;
|
|
|
2418
2539
|
exports.cvaActionButton = cvaActionButton;
|
|
2419
2540
|
exports.cvaActionContainer = cvaActionContainer;
|
|
2420
2541
|
exports.cvaInput = cvaInput;
|
|
2542
|
+
exports.cvaInputAction = cvaInputAction;
|
|
2421
2543
|
exports.cvaInputAddon = cvaInputAddon;
|
|
2422
2544
|
exports.cvaInputAddonAfter = cvaInputAddonAfter;
|
|
2423
2545
|
exports.cvaInputAddonBefore = cvaInputAddonBefore;
|
|
@@ -2428,6 +2550,7 @@ exports.cvaInputField = cvaInputField;
|
|
|
2428
2550
|
exports.cvaInputPrefix = cvaInputPrefix;
|
|
2429
2551
|
exports.cvaInputSuffix = cvaInputSuffix;
|
|
2430
2552
|
exports.cvaSelect = cvaSelect;
|
|
2553
|
+
exports.cvaSelectControl = cvaSelectControl;
|
|
2431
2554
|
exports.cvaSelectCounter = cvaSelectCounter;
|
|
2432
2555
|
exports.cvaSelectDynamicTagContainer = cvaSelectDynamicTagContainer;
|
|
2433
2556
|
exports.cvaSelectIcon = cvaSelectIcon;
|