@trackunit/react-form-components 0.0.452 → 0.0.453
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 +130 -95
- package/index.esm.js +130 -95
- package/package.json +3 -2
- package/src/components/ActionButton/ActionButton.d.ts +1 -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/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/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
|
|
|
@@ -307,7 +308,7 @@ const cvaInputSuffix = cssClassVarianceUtilities.cvaMerge(["flex", "justify-cent
|
|
|
307
308
|
* This is a base used by our other input components such as TextInput, NumberInput, PasswordInput, etc.
|
|
308
309
|
*/
|
|
309
310
|
const BaseInput = React__namespace.forwardRef((_a, ref) => {
|
|
310
|
-
var _b
|
|
311
|
+
var _b;
|
|
311
312
|
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
313
|
const renderAsDisabled = rest.disabled || rest.readOnly;
|
|
313
314
|
const innerRef = React__namespace.useRef(null);
|
|
@@ -318,15 +319,16 @@ const BaseInput = React__namespace.forwardRef((_a, ref) => {
|
|
|
318
319
|
invalid: isInvalid,
|
|
319
320
|
size: fieldSize,
|
|
320
321
|
className,
|
|
321
|
-
}), "data-testid": dataTestId
|
|
322
|
+
}), "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 && addonBefore !== prefix ? (jsxRuntime.jsx("div", { className: cvaInputPrefix({
|
|
322
323
|
disabled: renderAsDisabled,
|
|
323
|
-
}), "data-testid": dataTestId
|
|
324
|
+
}), "data-testid": dataTestId ? `${dataTestId}-prefix` : null, children: prefix })) : null, jsxRuntime.jsx("input", Object.assign({ "aria-required": rest.required, className: cvaInputField({ size: fieldSize, disabled: renderAsDisabled, className: inputClassName }), "data-testid": dataTestId, placeholder: renderAsDisabled ? undefined : placeholder, ref: innerRef }, rest, { readOnly: rest.readOnly || nonInteractive })), suffix && addonBefore !== suffix ? (jsxRuntime.jsx("div", { className: cvaInputSuffix({
|
|
324
325
|
disabled: renderAsDisabled,
|
|
325
|
-
}), "data-testid": dataTestId
|
|
326
|
+
}), "data-testid": dataTestId ? `${dataTestId}-suffix` : null, children: suffix })) : null, rest.readOnly === true &&
|
|
326
327
|
showDefaultActions &&
|
|
327
|
-
((_b = innerRef
|
|
328
|
-
|
|
328
|
+
((_b = innerRef.current) === null || _b === void 0 ? void 0 : _b.value.length) &&
|
|
329
|
+
innerRef.current.value.length > 0 ? (jsxRuntime.jsx(ActionButton, { type: "COPY", value: innerRef }, "default-copy-action")) : null, actions && addonBefore !== actions ? actions : null, addonAfter && addonBefore !== addonAfter ? (jsxRuntime.jsx("div", { className: cvaInputAddonAfter(), "data-testid": dataTestId ? `${dataTestId}-addonAfter` : null, children: addonAfter })) : null] }));
|
|
329
330
|
});
|
|
331
|
+
BaseInput.displayName = "BaseInput";
|
|
330
332
|
|
|
331
333
|
const cvaLabel = cssClassVarianceUtilities.cvaMerge([
|
|
332
334
|
"text-base",
|
|
@@ -519,10 +521,10 @@ const Checkbox = React__namespace.forwardRef((_a, ref) => {
|
|
|
519
521
|
var _a, _b;
|
|
520
522
|
e.preventDefault();
|
|
521
523
|
if ("Space" === e.code) {
|
|
522
|
-
(_a = internalRef
|
|
524
|
+
(_a = internalRef.current) === null || _a === void 0 ? void 0 : _a.click();
|
|
523
525
|
}
|
|
524
526
|
if ("Enter" === e.code) {
|
|
525
|
-
(_b = internalRef
|
|
527
|
+
(_b = internalRef.current) === null || _b === void 0 ? void 0 : _b.click();
|
|
526
528
|
}
|
|
527
529
|
};
|
|
528
530
|
const [labelRef, setLabelRef] = React__namespace.useState(null);
|
|
@@ -530,16 +532,17 @@ const Checkbox = React__namespace.forwardRef((_a, ref) => {
|
|
|
530
532
|
onLabelRefChange && labelRef && onLabelRefChange(labelRef);
|
|
531
533
|
}, [labelRef, onLabelRefChange]);
|
|
532
534
|
const uuid = rest.id;
|
|
533
|
-
return (jsxRuntime.jsxs("label", { className: cvaCheckboxContainer({ className }), "data-testid": dataTestId
|
|
535
|
+
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
536
|
disabled: isReadonly,
|
|
535
537
|
invalid: isReadonly ? false : isInvalid,
|
|
536
538
|
state: indeterminate ? "indeterminate" : checked ? "selected" : "deselected",
|
|
537
|
-
}), id: uuid, tabIndex: isReadonly ? -1 : tabIndex, children: icon }), label
|
|
539
|
+
}), id: uuid, tabIndex: isReadonly ? -1 : tabIndex, children: icon }), label ? (jsxRuntime.jsx("span", { className: "flex", children: jsxRuntime.jsx("span", { className: cvaLabel({
|
|
538
540
|
invalid: isReadonly ? false : isInvalid,
|
|
539
541
|
disabled: isReadonly,
|
|
540
542
|
className: "cursor-pointer",
|
|
541
|
-
}), id: `checkbox-label-${label}`, ref: labelReference => setLabelRef(labelReference), children: label }) })), suffix] }));
|
|
543
|
+
}), id: `checkbox-label-${label}`, ref: labelReference => setLabelRef(labelReference), children: label }) })) : null, suffix] }));
|
|
542
544
|
});
|
|
545
|
+
Checkbox.displayName = "Checkbox";
|
|
543
546
|
|
|
544
547
|
/**
|
|
545
548
|
* The Label component is used for labels for input fields.
|
|
@@ -579,7 +582,7 @@ const cvaHelpAddon = cssClassVarianceUtilities.cvaMerge(["ml-auto"]);
|
|
|
579
582
|
* @returns {JSX.Element} FormGroup component
|
|
580
583
|
*/
|
|
581
584
|
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
|
|
585
|
+
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
586
|
};
|
|
584
587
|
|
|
585
588
|
/**
|
|
@@ -590,8 +593,9 @@ const FormGroup = ({ isInvalid, helpText, helpAddon, tip, className, dataTestId,
|
|
|
590
593
|
const CheckboxField = React.forwardRef((_a, ref) => {
|
|
591
594
|
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
595
|
const htmlForId = id ? id : "checkboxField-" + uuid.v4();
|
|
593
|
-
return (jsxRuntime.jsx(FormGroup, { className: "flex flex-col gap-1", dataTestId: dataTestId
|
|
596
|
+
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
597
|
});
|
|
598
|
+
CheckboxField.displayName = "CheckboxField";
|
|
595
599
|
|
|
596
600
|
/**
|
|
597
601
|
* Validates if the given value is a valid hex color.
|
|
@@ -624,16 +628,17 @@ const ColorField = React.forwardRef((_a, ref) => {
|
|
|
624
628
|
}
|
|
625
629
|
}, [onChange]);
|
|
626
630
|
const renderAsInvalid = !!errorMessage || (value && typeof value === "string" && !isValidHEXColor(value)) || isInvalid;
|
|
627
|
-
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId
|
|
631
|
+
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
632
|
disabled: false,
|
|
629
633
|
invalid: false,
|
|
630
634
|
className,
|
|
631
|
-
}), "data-testid": dataTestId
|
|
632
|
-
if (innerRef
|
|
635
|
+
}), "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: () => {
|
|
636
|
+
if (innerRef.current) {
|
|
633
637
|
innerRef.current.click();
|
|
634
638
|
}
|
|
635
639
|
}, variant: "ghost-neutral" })] }) }));
|
|
636
640
|
});
|
|
641
|
+
ColorField.displayName = "ColorField";
|
|
637
642
|
|
|
638
643
|
/**
|
|
639
644
|
* A wrapper around BaseInput with a pop-up day picker.
|
|
@@ -645,8 +650,9 @@ const DateInput = React.forwardRef((_a, ref) => {
|
|
|
645
650
|
const formatDateToInputString = (date) => isDate.isValidDate(date) ? dateFns.format(date, "yyyy-MM-dd") : date;
|
|
646
651
|
// Chrome and Firefox need their default icon to have datepicker functionality.
|
|
647
652
|
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
|
|
653
|
+
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
654
|
});
|
|
655
|
+
DateInput.displayName = "DateInput";
|
|
650
656
|
|
|
651
657
|
/**
|
|
652
658
|
* The date field component is used for entering date values.
|
|
@@ -659,8 +665,9 @@ const DateField = React.forwardRef((_a, ref) => {
|
|
|
659
665
|
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
666
|
const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
|
|
661
667
|
const htmlForId = id ? id : "dateField-" + uuid.v4();
|
|
662
|
-
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId
|
|
668
|
+
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
669
|
});
|
|
670
|
+
DateField.displayName = "DateField";
|
|
664
671
|
|
|
665
672
|
const cvaDropZone = cssClassVarianceUtilities.cvaMerge([
|
|
666
673
|
"flex",
|
|
@@ -750,7 +757,7 @@ const DropZone = (_a) => {
|
|
|
750
757
|
e.preventDefault();
|
|
751
758
|
e.stopPropagation();
|
|
752
759
|
setDragActive(false);
|
|
753
|
-
if (e.dataTransfer.files
|
|
760
|
+
if (e.dataTransfer.files[0] && !disabled) {
|
|
754
761
|
filesSelected(e.dataTransfer.files);
|
|
755
762
|
setFileDropped(true);
|
|
756
763
|
}
|
|
@@ -770,7 +777,7 @@ const DropZone = (_a) => {
|
|
|
770
777
|
e.preventDefault();
|
|
771
778
|
e.stopPropagation();
|
|
772
779
|
}
|
|
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
|
|
780
|
+
}, 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
781
|
};
|
|
775
782
|
|
|
776
783
|
// Doing the same check as we do on the backend
|
|
@@ -811,9 +818,9 @@ const EmailInput = React__namespace.forwardRef((_a, ref) => {
|
|
|
811
818
|
setEmail(newValue);
|
|
812
819
|
}, [onChange]);
|
|
813
820
|
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)));
|
|
821
|
+
return (jsxRuntime.jsx(BaseInput, Object.assign({ actions: email && email.length > 0 ? (jsxRuntime.jsx(ActionButton, { dataTestId: dataTestId ? `${dataTestId}-emailIcon` : undefined, disabled: disabled, iconSize: fieldSize, onClick: sendEmail, type: "EMAIL", value: email })) : null, dataTestId: dataTestId, isInvalid: renderAsInvalid, onChange: handleChange, placeholder: rest.placeholder || "mail@example.com", ref: ref, type: "email" }, rest)));
|
|
816
822
|
});
|
|
823
|
+
EmailInput.displayName = "EmailInput";
|
|
817
824
|
|
|
818
825
|
/**
|
|
819
826
|
* The EmailField component is used to enter email.
|
|
@@ -833,8 +840,9 @@ const EmailField = React.forwardRef((_a, ref) => {
|
|
|
833
840
|
onChange(event);
|
|
834
841
|
}
|
|
835
842
|
}, [onChange]);
|
|
836
|
-
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId
|
|
843
|
+
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
844
|
});
|
|
845
|
+
EmailField.displayName = "EmailField";
|
|
838
846
|
|
|
839
847
|
/**
|
|
840
848
|
* A thin wrapper around the `BaseInput` component for number input fields.
|
|
@@ -844,6 +852,7 @@ const EmailField = React.forwardRef((_a, ref) => {
|
|
|
844
852
|
const NumberInput = React.forwardRef((props, ref) => {
|
|
845
853
|
return jsxRuntime.jsx(BaseInput, Object.assign({ ref: ref, type: "number" }, props, { value: props.value }));
|
|
846
854
|
});
|
|
855
|
+
NumberInput.displayName = "NumberInput";
|
|
847
856
|
|
|
848
857
|
/**
|
|
849
858
|
* The number field component is used for entering numeric values and includes controls for incrementally increasing or decreasing the value.
|
|
@@ -856,8 +865,9 @@ const NumberField = React.forwardRef((_a, ref) => {
|
|
|
856
865
|
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
866
|
const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
|
|
858
867
|
const htmlForId = id ? id : "numberField-" + uuid.v4();
|
|
859
|
-
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId
|
|
868
|
+
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
869
|
});
|
|
870
|
+
NumberField.displayName = "NumberField";
|
|
861
871
|
|
|
862
872
|
const cvaOptionCardLabel = cssClassVarianceUtilities.cvaMerge([
|
|
863
873
|
cvaInputBase(),
|
|
@@ -891,11 +901,11 @@ const cvaOptionCardContainer = cssClassVarianceUtilities.cvaMerge(["contents"]);
|
|
|
891
901
|
const OptionCard = React.forwardRef((_a, ref) => {
|
|
892
902
|
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
903
|
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 }))] }))] })] }));
|
|
904
|
+
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
|
|
905
|
+
? React.cloneElement(icon, { className: `${icon.props.className} text-secondary-400` })
|
|
906
|
+
: 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
907
|
});
|
|
908
|
+
OptionCard.displayName = "OptionCard";
|
|
899
909
|
|
|
900
910
|
/**
|
|
901
911
|
* A thin wrapper around the `BaseInput` component for password input fields.
|
|
@@ -906,6 +916,7 @@ const PasswordInput = React.forwardRef((props, ref) => {
|
|
|
906
916
|
const [showPassword, setShowPassword] = React.useState(false);
|
|
907
917
|
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
918
|
});
|
|
919
|
+
PasswordInput.displayName = "PasswordInput";
|
|
909
920
|
|
|
910
921
|
/**
|
|
911
922
|
* Password fields enter a password or other confidential information. Characters are masked as they are typed.
|
|
@@ -921,8 +932,9 @@ const PasswordField = React.forwardRef((_a, ref) => {
|
|
|
921
932
|
const handleChange = React.useCallback((event) => {
|
|
922
933
|
onChange === null || onChange === void 0 ? void 0 : onChange(event);
|
|
923
934
|
}, [onChange]);
|
|
924
|
-
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId
|
|
935
|
+
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
936
|
});
|
|
937
|
+
PasswordField.displayName = "PasswordField";
|
|
926
938
|
|
|
927
939
|
/**
|
|
928
940
|
* @param phoneNumber - a phone number as a string
|
|
@@ -1033,10 +1045,9 @@ const PhoneInput = React.forwardRef((_a, ref) => {
|
|
|
1033
1045
|
onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
|
|
1034
1046
|
fieldIsFocused.current = true;
|
|
1035
1047
|
}, [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)) }));
|
|
1048
|
+
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: 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
1049
|
});
|
|
1050
|
+
PhoneInput.displayName = "PhoneInput";
|
|
1040
1051
|
|
|
1041
1052
|
/**
|
|
1042
1053
|
* The PhoneField component is used to enter phone number.
|
|
@@ -1058,8 +1069,9 @@ const PhoneField = React.forwardRef((_a, ref) => {
|
|
|
1058
1069
|
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
1070
|
const htmlForId = id ? id : "phoneField-" + uuid.v4();
|
|
1060
1071
|
const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
|
|
1061
|
-
return (jsxRuntime.jsx(FormGroup, { className: className, dataTestId: dataTestId
|
|
1072
|
+
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
1073
|
});
|
|
1074
|
+
PhoneField.displayName = "PhoneField";
|
|
1063
1075
|
|
|
1064
1076
|
/**
|
|
1065
1077
|
* The PhoneFieldWithController component is a wrapper for the PhoneField component to connect it to react-hook-form.
|
|
@@ -1070,6 +1082,7 @@ const PhoneFieldWithController = React.forwardRef((_a, ref) => {
|
|
|
1070
1082
|
var { control, controllerProps, name, value } = _a, rest = __rest(_a, ["control", "controllerProps", "name", "value"]);
|
|
1071
1083
|
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
1084
|
});
|
|
1085
|
+
PhoneFieldWithController.displayName = "PhoneFieldWithController";
|
|
1073
1086
|
|
|
1074
1087
|
/**
|
|
1075
1088
|
* Validates a phone number
|
|
@@ -1082,7 +1095,7 @@ const validatePhoneNumber = (phoneNumber) => {
|
|
|
1082
1095
|
asYouType.input(phoneNumber);
|
|
1083
1096
|
const countryCode = asYouType.getCallingCode();
|
|
1084
1097
|
const national = asYouType.getNationalNumber();
|
|
1085
|
-
const safePhoneNumber = getPhoneNumberWithPlus(phoneNumber
|
|
1098
|
+
const safePhoneNumber = getPhoneNumberWithPlus(phoneNumber.trim());
|
|
1086
1099
|
const number = parsePhoneNumberFromString__default["default"](safePhoneNumber);
|
|
1087
1100
|
if (phoneNumber && parsePhoneNumberFromString.isValidPhoneNumber(phoneNumber)) {
|
|
1088
1101
|
return undefined;
|
|
@@ -1223,7 +1236,7 @@ const RadioGroupContext = React__namespace.createContext(null);
|
|
|
1223
1236
|
* @returns {JSX.Element} RadioGroup component
|
|
1224
1237
|
*/
|
|
1225
1238
|
const RadioGroup = ({ children, id, name, value, disabled, onChange, label, inline, className, dataTestId, isInvalid, }) => {
|
|
1226
|
-
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId
|
|
1239
|
+
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
1240
|
id,
|
|
1228
1241
|
value,
|
|
1229
1242
|
name: name || id,
|
|
@@ -1243,11 +1256,11 @@ RadioGroup.displayName = "RadioGroup";
|
|
|
1243
1256
|
const RadioItem = ({ label, value, dataTestId, className, description, }) => {
|
|
1244
1257
|
const groupCtx = React__namespace.useContext(RadioGroupContext);
|
|
1245
1258
|
const isChecked = (groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.value) === value;
|
|
1246
|
-
return (jsxRuntime.jsxs("label", { className: cvaRadioItemWrapper({ className }), "data-testid": dataTestId
|
|
1259
|
+
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
1260
|
checked: isChecked,
|
|
1248
1261
|
disabled: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled,
|
|
1249
1262
|
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
|
|
1263
|
+
}), "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
1264
|
};
|
|
1252
1265
|
|
|
1253
1266
|
const cvaTimeRange = cssClassVarianceUtilities.cvaMerge(["flex", "flex-1", "items-center", "gap-4", "border-transparent", "rounded-md"]);
|
|
@@ -1259,7 +1272,6 @@ const cvaTimeRange = cssClassVarianceUtilities.cvaMerge(["flex", "flex-1", "item
|
|
|
1259
1272
|
* @returns {JSX.Element} TimeRange component
|
|
1260
1273
|
*/
|
|
1261
1274
|
const TimeRange = ({ id, className, dataTestId, children, range, onChange, disabled, isInvalid, }) => {
|
|
1262
|
-
var _a, _b;
|
|
1263
1275
|
const [timeRange, setTimeRange] = React__default["default"].useState(range !== null && range !== void 0 ? range : {
|
|
1264
1276
|
timeFrom: "",
|
|
1265
1277
|
timeTo: "",
|
|
@@ -1271,7 +1283,7 @@ const TimeRange = ({ id, className, dataTestId, children, range, onChange, disab
|
|
|
1271
1283
|
setTimeRange(prev => (Object.assign(Object.assign({}, prev), { timeTo })));
|
|
1272
1284
|
};
|
|
1273
1285
|
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:
|
|
1286
|
+
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
1287
|
};
|
|
1276
1288
|
|
|
1277
1289
|
const cvaScheduleItem = cssClassVarianceUtilities.cvaMerge(["grid", "pb-4", "gap-2", "grid-cols-[60px,200px,60px,2fr]"]);
|
|
@@ -1298,7 +1310,7 @@ const Schedule = ({ className, dataTestId, schedule, onChange, invalidKeys = []
|
|
|
1298
1310
|
onChange(newSchedule);
|
|
1299
1311
|
};
|
|
1300
1312
|
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
|
|
1313
|
+
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
1314
|
}) }));
|
|
1303
1315
|
};
|
|
1304
1316
|
|
|
@@ -1346,32 +1358,19 @@ const parseSchedule = (scheduleString) => {
|
|
|
1346
1358
|
};
|
|
1347
1359
|
});
|
|
1348
1360
|
const filteredSchedule = schedule
|
|
1349
|
-
.filter(daySchedule =>
|
|
1350
|
-
.map(daySchedule => ({
|
|
1361
|
+
.filter(daySchedule => "range" in daySchedule && daySchedule.range)
|
|
1362
|
+
.map(daySchedule => ({
|
|
1363
|
+
day: daySchedule.day,
|
|
1364
|
+
range: daySchedule.range,
|
|
1365
|
+
isAllDay: daySchedule.isAllDay,
|
|
1366
|
+
}));
|
|
1351
1367
|
let variant;
|
|
1352
1368
|
switch (schedule.length) {
|
|
1353
1369
|
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
|
-
}
|
|
1370
|
+
variant = isUniform(schedule) ? exports.ScheduleVariant.ALL_DAYS : exports.ScheduleVariant.CUSTOM;
|
|
1365
1371
|
break;
|
|
1366
1372
|
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
|
-
}
|
|
1373
|
+
variant = hasConsecutiveDays(schedule) ? exports.ScheduleVariant.WEEKDAYS : exports.ScheduleVariant.CUSTOM;
|
|
1375
1374
|
break;
|
|
1376
1375
|
default:
|
|
1377
1376
|
return {
|
|
@@ -1393,7 +1392,7 @@ const parseSchedule = (scheduleString) => {
|
|
|
1393
1392
|
const serializeSchedule = (weekSchedule) => {
|
|
1394
1393
|
return weekSchedule.schedule
|
|
1395
1394
|
.filter(({ range, day, isAllDay }) => {
|
|
1396
|
-
const hasRange =
|
|
1395
|
+
const hasRange = range.timeFrom && range.timeTo;
|
|
1397
1396
|
switch (weekSchedule.variant) {
|
|
1398
1397
|
case exports.ScheduleVariant.WEEKDAYS:
|
|
1399
1398
|
return day <= 5 && hasRange;
|
|
@@ -1412,6 +1411,25 @@ const serializeSchedule = (weekSchedule) => {
|
|
|
1412
1411
|
})
|
|
1413
1412
|
.join(",");
|
|
1414
1413
|
};
|
|
1414
|
+
/**
|
|
1415
|
+
* Checks if a list of schedule objects have the same ranges
|
|
1416
|
+
*
|
|
1417
|
+
* @param {RawSchedule[]} schedule List of schedule objects
|
|
1418
|
+
* @returns {boolean} Whether the schedule is uniform
|
|
1419
|
+
*/
|
|
1420
|
+
const isUniform = (schedule) => {
|
|
1421
|
+
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); });
|
|
1422
|
+
};
|
|
1423
|
+
/**
|
|
1424
|
+
* Checks if a list of schedule objects are consecutive days
|
|
1425
|
+
*
|
|
1426
|
+
* @param {RawSchedule[]} schedule List of schedule objects
|
|
1427
|
+
* @returns {boolean} Whether the schedule has consecutive days
|
|
1428
|
+
*/
|
|
1429
|
+
const hasConsecutiveDays = (schedule) => {
|
|
1430
|
+
const days = [1, 2, 3, 4, 5];
|
|
1431
|
+
return schedule.every(({ day }, index) => day === days[index]);
|
|
1432
|
+
};
|
|
1415
1433
|
|
|
1416
1434
|
/**
|
|
1417
1435
|
* A thin wrapper around the `BaseInput` component for text input fields.
|
|
@@ -1419,6 +1437,7 @@ const serializeSchedule = (weekSchedule) => {
|
|
|
1419
1437
|
* NOTE: If shown with a label, please use the `TextField` component instead.
|
|
1420
1438
|
*/
|
|
1421
1439
|
const TextInput = React.forwardRef((props, ref) => (jsxRuntime.jsx(BaseInput, Object.assign({ ref: ref, type: "text" }, props))));
|
|
1440
|
+
TextInput.displayName = "TextInput";
|
|
1422
1441
|
|
|
1423
1442
|
const cvaSearch = cssClassVarianceUtilities.cvaMerge([
|
|
1424
1443
|
"shadow-none",
|
|
@@ -1454,10 +1473,11 @@ const cvaSearch = cssClassVarianceUtilities.cvaMerge([
|
|
|
1454
1473
|
*/
|
|
1455
1474
|
const Search = React.forwardRef((_a, ref) => {
|
|
1456
1475
|
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
|
|
1476
|
+
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
1477
|
onClear();
|
|
1459
1478
|
}, children: jsxRuntime.jsx(reactComponents.Icon, { name: "XMark", size: "small" }) })) : undefined, value: value })));
|
|
1460
1479
|
});
|
|
1480
|
+
Search.displayName = "Search";
|
|
1461
1481
|
|
|
1462
1482
|
const cvaSelect = cssClassVarianceUtilities.cvaMerge([
|
|
1463
1483
|
"relative",
|
|
@@ -1518,6 +1538,8 @@ function isMultiValue(arg) {
|
|
|
1518
1538
|
return Array.isArray(arg);
|
|
1519
1539
|
}
|
|
1520
1540
|
function isGroupBase(arg) {
|
|
1541
|
+
// This is apparently needed
|
|
1542
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1521
1543
|
return arg.options !== undefined;
|
|
1522
1544
|
}
|
|
1523
1545
|
const isSelectedOption = (option, selected) => {
|
|
@@ -1553,7 +1575,7 @@ const getOrderedOptions = (options, value) => {
|
|
|
1553
1575
|
.filter(option => !isSelectedOption(option, value))
|
|
1554
1576
|
.map(option => removeSelectedFromGroups(option, value));
|
|
1555
1577
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1556
|
-
return orderedValues.concat(selectableOptions)
|
|
1578
|
+
return orderedValues.concat(selectableOptions);
|
|
1557
1579
|
}
|
|
1558
1580
|
return options || [];
|
|
1559
1581
|
};
|
|
@@ -1614,7 +1636,7 @@ const TagsContainer = ({ items, width = "100%", itemsGap = 5, postFix, disabled
|
|
|
1614
1636
|
const itemsCount = items.length;
|
|
1615
1637
|
React__default["default"].useLayoutEffect(() => {
|
|
1616
1638
|
var _a;
|
|
1617
|
-
availableWidth.current = ((_a = containerRef
|
|
1639
|
+
availableWidth.current = ((_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0;
|
|
1618
1640
|
}, [containerRef]);
|
|
1619
1641
|
const onWidthKnownHandler = ({ width: reportedWidth }) => {
|
|
1620
1642
|
childrenWidth.current.push({ width: reportedWidth + itemsGap });
|
|
@@ -1626,7 +1648,7 @@ const TagsContainer = ({ items, width = "100%", itemsGap = 5, postFix, disabled
|
|
|
1626
1648
|
return previous + current.width;
|
|
1627
1649
|
}, 0);
|
|
1628
1650
|
let counter = 0;
|
|
1629
|
-
const availableSpace = (
|
|
1651
|
+
const availableSpace = (availableWidth.current || 0) - counterWidth;
|
|
1630
1652
|
const renderedElements = items
|
|
1631
1653
|
.concat({ text: "", onClick: () => null, disabled: false }) // reserved element for a potential counter
|
|
1632
1654
|
.map((item, index) => {
|
|
@@ -1683,9 +1705,12 @@ const useCustomComponents = (componentsProps, disabled, menuIsOpen, refMenuIsEna
|
|
|
1683
1705
|
var _a;
|
|
1684
1706
|
if (props.isMulti && Array.isArray(props.children) && props.children.length > 0) {
|
|
1685
1707
|
const PLACEHOLDER_KEY = "placeholder";
|
|
1708
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1686
1709
|
const key = props && props.children && props.children[0] ? (_a = props.children[0]) === null || _a === void 0 ? void 0 : _a.key : "";
|
|
1710
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1687
1711
|
const values = props && props.children ? props.children[0] : [];
|
|
1688
1712
|
const tags = key === PLACEHOLDER_KEY ? [] : values;
|
|
1713
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1689
1714
|
const searchInput = props && props.children && props.children[1];
|
|
1690
1715
|
return (jsxRuntime.jsx(ReactSelect.components.ValueContainer, Object.assign({}, props, { isDisabled: props.selectProps.isDisabled, children: maxSelectedDisplayCount === undefined ? (jsxRuntime.jsx(TagsContainer, { disabled: disabled, items: tags
|
|
1691
1716
|
? tags.map(({ props: tagProps }) => {
|
|
@@ -1694,27 +1719,26 @@ const useCustomComponents = (componentsProps, disabled, menuIsOpen, refMenuIsEna
|
|
|
1694
1719
|
onClick: disabled
|
|
1695
1720
|
? undefined
|
|
1696
1721
|
: (e) => {
|
|
1697
|
-
var _a, _b;
|
|
1698
1722
|
refMenuIsEnabled.current = false;
|
|
1699
|
-
|
|
1723
|
+
tagProps.removeProps.onClick && tagProps.removeProps.onClick(e);
|
|
1700
1724
|
},
|
|
1701
1725
|
disabled: disabled,
|
|
1702
1726
|
};
|
|
1703
1727
|
})
|
|
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;
|
|
1728
|
+
: [], postFix: searchInput, width: "100%" })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [tags
|
|
1729
|
+
? tags.slice(0, maxSelectedDisplayCount).map(({ props: tagProps }) => {
|
|
1730
|
+
var _a;
|
|
1731
|
+
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
1732
|
e.stopPropagation();
|
|
1710
1733
|
refMenuIsEnabled.current = false;
|
|
1711
|
-
|
|
1712
|
-
}, children: tagProps.children }, (
|
|
1713
|
-
})
|
|
1734
|
+
tagProps.removeProps.onClick && tagProps.removeProps.onClick(e);
|
|
1735
|
+
}, children: tagProps.children }, (_a = tagProps.children) === null || _a === void 0 ? void 0 : _a.toString()));
|
|
1736
|
+
})
|
|
1737
|
+
: null, tags && tags.length > maxSelectedDisplayCount ? (jsxRuntime.jsxs(reactComponents.Tag, { color: "neutral", dataTestId: "counter-tag", children: ["+", tags.length - maxSelectedDisplayCount] })) : null, searchInput] })) })));
|
|
1714
1738
|
}
|
|
1715
1739
|
return (jsxRuntime.jsx(ReactSelect.components.ValueContainer, Object.assign({}, props, { isDisabled: props.selectProps.isDisabled, children: props.children })));
|
|
1716
1740
|
}, LoadingIndicator: props => {
|
|
1717
|
-
return jsxRuntime.jsx(reactComponents.Spinner, { className: "mt-1.5
|
|
1741
|
+
return jsxRuntime.jsx(reactComponents.Spinner, { className: "mr-1 mt-1.5", size: "small" });
|
|
1718
1742
|
}, DropdownIndicator: props => {
|
|
1719
1743
|
const icon = props.selectProps.menuIsOpen ? (jsxRuntime.jsx(reactComponents.Icon, { name: "ChevronUp", size: "medium" })) : (jsxRuntime.jsx(reactComponents.Icon, { name: "ChevronDown", size: "medium" }));
|
|
1720
1744
|
return props.selectProps.isLoading ? null : (jsxRuntime.jsx(ReactSelect.components.DropdownIndicator, Object.assign({}, props, { children: jsxRuntime.jsx("div", { className: cvaSelectIcon(), children: dropdownIcon ? dropdownIcon : icon }) })));
|
|
@@ -1722,7 +1746,7 @@ const useCustomComponents = (componentsProps, disabled, menuIsOpen, refMenuIsEna
|
|
|
1722
1746
|
if (disabled) {
|
|
1723
1747
|
return null;
|
|
1724
1748
|
}
|
|
1725
|
-
return (jsxRuntime.jsx(ReactSelect.components.ClearIndicator, Object.assign({}, props, { children: jsxRuntime.jsx("div", { className: cvaSelectXIcon(), "data-testid": dataTestId
|
|
1749
|
+
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
1750
|
}, Control: props => {
|
|
1727
1751
|
return jsxRuntime.jsx(ReactSelect.components.Control, Object.assign({}, props, { className: props.isDisabled ? "bg-slate-100" : "" }));
|
|
1728
1752
|
}, SingleValue: props => {
|
|
@@ -1771,7 +1795,7 @@ const useCustomStyles = (refContainer, refPrefix, maxSelectedDisplayCount, style
|
|
|
1771
1795
|
width: "0px",
|
|
1772
1796
|
}), menu: base => {
|
|
1773
1797
|
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:
|
|
1798
|
+
}, 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: refPrefix.current ? `translate(-${refPrefix.current.clientWidth + 2}px)` : "translate(-2px)", 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
1799
|
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
1800
|
}, valueContainer: base => {
|
|
1777
1801
|
return Object.assign(Object.assign({}, base), { flexWrap: maxSelectedDisplayCount !== undefined ? "wrap" : "nowrap", gap: "0.25rem" });
|
|
@@ -1840,7 +1864,7 @@ const useSelect = (_a) => {
|
|
|
1840
1864
|
*/
|
|
1841
1865
|
const CreatableSelect = (props) => {
|
|
1842
1866
|
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
|
|
1867
|
+
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
1868
|
const { refContainer, refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler, orderedOptions, } = useSelect(props);
|
|
1845
1869
|
const creatableSelectProps = {
|
|
1846
1870
|
value,
|
|
@@ -1872,7 +1896,7 @@ const CreatableSelect = (props) => {
|
|
|
1872
1896
|
onCreateOption,
|
|
1873
1897
|
};
|
|
1874
1898
|
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
|
|
1899
|
+
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
1900
|
};
|
|
1877
1901
|
CreatableSelect.displayName = "CreatableSelect";
|
|
1878
1902
|
|
|
@@ -1884,7 +1908,7 @@ CreatableSelect.displayName = "CreatableSelect";
|
|
|
1884
1908
|
*/
|
|
1885
1909
|
const Select = (props) => {
|
|
1886
1910
|
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
|
|
1911
|
+
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
1912
|
const { refContainer, refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler, orderedOptions, } = useSelect(props);
|
|
1889
1913
|
const selectProps = {
|
|
1890
1914
|
value,
|
|
@@ -1915,7 +1939,7 @@ const Select = (props) => {
|
|
|
1915
1939
|
hideSelectedOptions,
|
|
1916
1940
|
};
|
|
1917
1941
|
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
|
|
1942
|
+
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
1943
|
};
|
|
1920
1944
|
Select.displayName = "Select";
|
|
1921
1945
|
|
|
@@ -1968,6 +1992,7 @@ const FormFieldSelectAdapter = React.forwardRef((_a, ref) => {
|
|
|
1968
1992
|
setInnerValue(!e ? "" : e.value);
|
|
1969
1993
|
}, value: selectedOption, defaultValue: selectedOption }))] }));
|
|
1970
1994
|
});
|
|
1995
|
+
FormFieldSelectAdapter.displayName = "FormFieldSelectAdapter";
|
|
1971
1996
|
|
|
1972
1997
|
/**
|
|
1973
1998
|
* The CreatableSelectField component is a CreatableSelect component wrapped in the FromGroup component.
|
|
@@ -1984,6 +2009,7 @@ const CreatableSelectField = React.forwardRef((_a, ref) => {
|
|
|
1984
2009
|
const creatableSelectOnlyProps = { allowCreateWhileLoading, onCreateOption };
|
|
1985
2010
|
return (jsxRuntime.jsx(FormFieldSelectAdapter, Object.assign({}, props, { ref: ref, children: convertedProps => jsxRuntime.jsx(CreatableSelect, Object.assign({}, convertedProps, creatableSelectOnlyProps)) })));
|
|
1986
2011
|
});
|
|
2012
|
+
CreatableSelectField.displayName = "CreatableSelectField";
|
|
1987
2013
|
|
|
1988
2014
|
/**
|
|
1989
2015
|
* The SelectField component is a Select component wrapped in the FromGroup component.
|
|
@@ -1999,6 +2025,7 @@ const SelectField = React.forwardRef((_a, ref) => {
|
|
|
1999
2025
|
var props = __rest(_a, []);
|
|
2000
2026
|
return (jsxRuntime.jsx(FormFieldSelectAdapter, Object.assign({}, props, { ref: ref, children: convertedProps => jsxRuntime.jsx(Select, Object.assign({}, convertedProps)) })));
|
|
2001
2027
|
});
|
|
2028
|
+
SelectField.displayName = "SelectField";
|
|
2002
2029
|
|
|
2003
2030
|
const cvaTextArea = cssClassVarianceUtilities.cvaMerge([
|
|
2004
2031
|
cvaInputBase(),
|
|
@@ -2041,6 +2068,7 @@ const TextArea = React__namespace.forwardRef((_a, ref) => {
|
|
|
2041
2068
|
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
2069
|
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
2070
|
});
|
|
2071
|
+
TextArea.displayName = "TextArea";
|
|
2044
2072
|
|
|
2045
2073
|
/**
|
|
2046
2074
|
* The TextLengthIndicator component shows a `{length}/{maxLength}` label.
|
|
@@ -2064,9 +2092,10 @@ const TextAreaField = React__namespace.forwardRef((_a, ref) => {
|
|
|
2064
2092
|
onChange(event);
|
|
2065
2093
|
}
|
|
2066
2094
|
}, [onChange]);
|
|
2067
|
-
return (jsxRuntime.jsx(FormGroup, { className:
|
|
2068
|
-
(
|
|
2095
|
+
return (jsxRuntime.jsx(FormGroup, { className: tailwindMerge.twMerge(className, "grid", "grid-rows-[auto_1fr_auto]"), dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, helpAddon: helpAddon ||
|
|
2096
|
+
(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
2097
|
});
|
|
2098
|
+
TextAreaField.displayName = "TextAreaField";
|
|
2070
2099
|
|
|
2071
2100
|
/**
|
|
2072
2101
|
* 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 +2115,10 @@ const TextField = React__namespace.forwardRef((_a, ref) => {
|
|
|
2086
2115
|
onChange(event);
|
|
2087
2116
|
}
|
|
2088
2117
|
}, [onChange]);
|
|
2089
|
-
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId
|
|
2090
|
-
(
|
|
2118
|
+
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, helpAddon: helpAddon ||
|
|
2119
|
+
(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", disabled: rest.readOnly, id: htmlFor, isInvalid: renderAsInvalid, maxLength: maxLength, ref: ref, value: value }, rest, { className: className, dataTestId: dataTestId, onChange: handleChange })) }));
|
|
2091
2120
|
});
|
|
2121
|
+
TextField.displayName = "TextField";
|
|
2092
2122
|
|
|
2093
2123
|
/**
|
|
2094
2124
|
* TimeRangeField Description. <-- Please add a proper Description this is used in Storybook.
|
|
@@ -2100,7 +2130,7 @@ const TimeRangeField = (_a) => {
|
|
|
2100
2130
|
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
2131
|
const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
|
|
2102
2132
|
const htmlFor = id ? id : "timeRangeField-" + uuid.v4();
|
|
2103
|
-
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId
|
|
2133
|
+
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
2134
|
};
|
|
2105
2135
|
|
|
2106
2136
|
const cvaToggleWrapper = cssClassVarianceUtilities.cvaMerge(["flex", "gap-2", "items-center"]);
|
|
@@ -2175,11 +2205,12 @@ const Toggle = React__namespace.forwardRef(({ toggled = false, onChange, onClick
|
|
|
2175
2205
|
const showLabelContainer = Boolean(name || description);
|
|
2176
2206
|
const showDescription = Boolean(description);
|
|
2177
2207
|
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
|
|
2208
|
+
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
2209
|
e.stopPropagation();
|
|
2180
2210
|
onChange(!toggled, e);
|
|
2181
2211
|
}, ref: ref, required: required, tabIndex: tabIndex, type: "checkbox" })] }) }));
|
|
2182
2212
|
});
|
|
2213
|
+
Toggle.displayName = "Toggle";
|
|
2183
2214
|
|
|
2184
2215
|
const cvaUploadInputField = cssClassVarianceUtilities.cvaMerge([
|
|
2185
2216
|
"px-0",
|
|
@@ -2208,6 +2239,7 @@ const UploadInput = React.forwardRef((_a, ref) => {
|
|
|
2208
2239
|
}
|
|
2209
2240
|
}, ref: ref, type: "file" }, rest)) }));
|
|
2210
2241
|
});
|
|
2242
|
+
UploadInput.displayName = "UploadInput";
|
|
2211
2243
|
|
|
2212
2244
|
/**
|
|
2213
2245
|
* Upload fields enable the user to upload Files.
|
|
@@ -2218,6 +2250,7 @@ const UploadField = React.forwardRef((_a, ref) => {
|
|
|
2218
2250
|
const htmlForId = id ? id : "uploadField-" + uuid.v4();
|
|
2219
2251
|
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
2252
|
});
|
|
2253
|
+
UploadField.displayName = "UploadField";
|
|
2221
2254
|
|
|
2222
2255
|
/**
|
|
2223
2256
|
* @description Validate given url id.
|
|
@@ -2243,8 +2276,9 @@ const UrlInput = React.forwardRef((_a, ref) => {
|
|
|
2243
2276
|
var { dataTestId, isInvalid, disabled = false, fieldSize = "medium", disableAction = false, value, defaultValue } = _a, rest = __rest(_a, ["dataTestId", "isInvalid", "disabled", "fieldSize", "disableAction", "value", "defaultValue"]);
|
|
2244
2277
|
const [url, setUrl] = React.useState((value === null || value === void 0 ? void 0 : value.toString()) || (defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.toString()));
|
|
2245
2278
|
const renderAsInvalid = (url && typeof url === "string" && !validateUrlAddress(url)) || isInvalid;
|
|
2246
|
-
return (jsxRuntime.jsx(BaseInput, Object.assign({ dataTestId: dataTestId
|
|
2279
|
+
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 || disabled, iconSize: fieldSize, type: "WEB_ADDRESS", value: url })) })));
|
|
2247
2280
|
});
|
|
2281
|
+
UrlInput.displayName = "UrlField";
|
|
2248
2282
|
|
|
2249
2283
|
/**
|
|
2250
2284
|
* The UrlField component is used to enter url.
|
|
@@ -2259,8 +2293,9 @@ const UrlField = React.forwardRef((_a, ref) => {
|
|
|
2259
2293
|
return typeof inputValue === "string";
|
|
2260
2294
|
}
|
|
2261
2295
|
const renderAsInvalid = !!errorMessage || (value && isString(value) && !validateUrlAddress(value)) || isInvalid;
|
|
2262
|
-
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId
|
|
2296
|
+
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", disabled: rest.disabled, id: htmlForId, isInvalid: renderAsInvalid, ref: ref, value: value || defaultValue }, rest, { className: className, dataTestId: dataTestId })) }));
|
|
2263
2297
|
});
|
|
2298
|
+
UrlField.displayName = "UrlField";
|
|
2264
2299
|
|
|
2265
2300
|
/**
|
|
2266
2301
|
* Custom hook to get phone number validation rules.
|
|
@@ -2277,7 +2312,7 @@ const useGetPhoneValidationRules = () => {
|
|
|
2277
2312
|
const pattern = {
|
|
2278
2313
|
validate: (value) => {
|
|
2279
2314
|
const validationResult = t(`phoneField.error.${validatePhoneNumber(value)}`);
|
|
2280
|
-
return !validationResult || value
|
|
2315
|
+
return !validationResult || !value || validationResult;
|
|
2281
2316
|
},
|
|
2282
2317
|
};
|
|
2283
2318
|
return !skipValidation
|