@trackunit/react-form-components 0.0.459 → 0.0.461
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 +136 -59
- package/index.esm.js +136 -59
- package/package.json +1 -1
- package/src/components/BaseInput/BaseInput.d.ts +4 -1
- package/src/components/BaseInput/DisabledForReasonsTip.d.ts +16 -0
- package/src/components/FormGroup/FormGroup.d.ts +2 -10
- package/src/components/FormGroup/FormGroup.variants.d.ts +1 -3
- 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 +3 -1
- package/src/components/Select/useCustomComponents.d.ts +14 -2
- package/src/components/Select/useCustomStyles.d.ts +7 -1
- package/src/components/Select/useSelect.d.ts +7 -5
- package/src/components/TimeRangeField/TimeRangeField.d.ts +1 -1
- package/src/translation.d.ts +2 -2
package/index.cjs.js
CHANGED
|
@@ -53,6 +53,8 @@ var defaultTranslations = {
|
|
|
53
53
|
"clearIndicator.icon.tooltip.clearAll": "Clear all",
|
|
54
54
|
"dropzone.input.title": "Drag-and-drop file input",
|
|
55
55
|
"dropzone.label.default": "<clickable>Browse</clickable> or drag files here...",
|
|
56
|
+
"field.notEditable.tooltip": "This field is not editable",
|
|
57
|
+
"field.required.asterisk.tooltip": "This field is required",
|
|
56
58
|
"phoneField.error.INVALID_COUNTRY": "The country code is not valid",
|
|
57
59
|
"phoneField.error.INVALID_LENGTH": "The phone number is not valid",
|
|
58
60
|
"phoneField.error.INVALID_NUMBER": "The phone number is not valid",
|
|
@@ -384,6 +386,22 @@ const cvaInputAction = cssClassVarianceUtilities.cvaMerge(["absolute", "end-0.5"
|
|
|
384
386
|
],
|
|
385
387
|
});
|
|
386
388
|
|
|
389
|
+
/**
|
|
390
|
+
* Icon with explanation tooltip for why an input is locked or disabled.
|
|
391
|
+
* If locked, a permission lacks but the input **can** sometimes be edited.
|
|
392
|
+
* If disabled, the input **cannot** be edited and is only ever for displaying information.
|
|
393
|
+
*
|
|
394
|
+
* @param {DisabledForReasons} props - The reasons for the disabled state.
|
|
395
|
+
* @param {DisabledKind} kind - The kind of disabled state. If locked, the input can sometimes be edited. If disabled, the input cannot be edited.
|
|
396
|
+
*/
|
|
397
|
+
const DisabledForReasonsTip = ({ reasons, kind }) => {
|
|
398
|
+
const [t] = useTranslation();
|
|
399
|
+
if (!reasons || reasons.length === 0) {
|
|
400
|
+
jsxRuntime.jsx(reactComponents.Tooltip, { label: t("field.notEditable.tooltip"), children: jsxRuntime.jsx(reactComponents.Icon, { name: kind === "disabled" ? "QuestionMarkCircle" : "LockClosed", size: "small" }) });
|
|
401
|
+
}
|
|
402
|
+
return (jsxRuntime.jsx(reactComponents.Tooltip, { label: jsxRuntime.jsx("ul", { className: typeof reasons === "string" || (reasons === null || reasons === void 0 ? void 0 : reasons.length) === 1 ? "list-inside" : "list-disc", children: typeof reasons === "string" ? jsxRuntime.jsx("li", { children: reasons }) : reasons === null || reasons === void 0 ? void 0 : reasons.map(reason => jsxRuntime.jsx("li", { children: reason }, reason)) }), placement: "top", children: jsxRuntime.jsx(reactComponents.Icon, { name: "LockClosed", size: "small" }) }));
|
|
403
|
+
};
|
|
404
|
+
|
|
387
405
|
/**
|
|
388
406
|
* A base input component that can be used for text inputs, password inputs, etc.
|
|
389
407
|
* A reference to the input element is provided as the `ref` prop.
|
|
@@ -395,7 +413,7 @@ const cvaInputAction = cssClassVarianceUtilities.cvaMerge(["absolute", "end-0.5"
|
|
|
395
413
|
const BaseInput = React__namespace.forwardRef((_a, ref) => {
|
|
396
414
|
var _b;
|
|
397
415
|
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"]);
|
|
398
|
-
const renderAsDisabled = rest.disabled || rest.readOnly;
|
|
416
|
+
const renderAsDisabled = Boolean(rest.disabled) || rest.readOnly;
|
|
399
417
|
const innerRef = React__namespace.useRef(null);
|
|
400
418
|
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
401
419
|
React__namespace.useImperativeHandle(ref, () => innerRef.current, []);
|
|
@@ -414,7 +432,9 @@ const BaseInput = React__namespace.forwardRef((_a, ref) => {
|
|
|
414
432
|
className: inputClassName,
|
|
415
433
|
addonBefore: addonBefore !== undefined,
|
|
416
434
|
prefix: !compareReactNodes(addonBefore, prefix),
|
|
417
|
-
}), "data-testid": dataTestId, placeholder: renderAsDisabled ? undefined : placeholder, ref: innerRef }, rest, { disabled: renderAsDisabled, readOnly: rest.readOnly || nonInteractive })),
|
|
435
|
+
}), "data-testid": dataTestId, placeholder: renderAsDisabled ? undefined : placeholder, ref: innerRef }, rest, { disabled: renderAsDisabled, readOnly: rest.readOnly || nonInteractive })), typeof rest.disabled === "object" ? (jsxRuntime.jsx("div", { className: cvaInputSuffix({
|
|
436
|
+
disabled: false,
|
|
437
|
+
}), "data-testid": dataTestId ? `${dataTestId}-locked` : undefined, children: jsxRuntime.jsx(DisabledForReasonsTip, Object.assign({}, rest.disabled)) })) : null, suffix && addonBefore !== suffix ? (jsxRuntime.jsx("div", { className: cvaInputSuffix({
|
|
418
438
|
disabled: renderAsDisabled,
|
|
419
439
|
addonAfter: addonAfter !== undefined && !compareReactNodes(addonBefore, addonAfter),
|
|
420
440
|
actions: (actions && !compareReactNodes(addonBefore, actions)) || false,
|
|
@@ -631,14 +651,7 @@ const Label = ({ id, htmlFor, children, className, dataTestId, disabled, isInval
|
|
|
631
651
|
return (jsxRuntime.jsx("label", { className: cvaLabel({ invalid: isInvalid, disabled, className }), "data-testid": dataTestId, htmlFor: htmlFor || "", id: id || "", children: children }));
|
|
632
652
|
};
|
|
633
653
|
|
|
634
|
-
const cvaFormGroup = cssClassVarianceUtilities.cvaMerge(["component-formGroup-gap"]
|
|
635
|
-
variants: {
|
|
636
|
-
disabled: {
|
|
637
|
-
true: "pointer-events-none",
|
|
638
|
-
false: "",
|
|
639
|
-
},
|
|
640
|
-
},
|
|
641
|
-
});
|
|
654
|
+
const cvaFormGroup = cssClassVarianceUtilities.cvaMerge(["component-formGroup-gap"]);
|
|
642
655
|
const cvaFormGroupContainerBefore = cssClassVarianceUtilities.cvaMerge(["flex", "mb-1", "items-center"]);
|
|
643
656
|
const cvaFormGroupContainerAfter = cssClassVarianceUtilities.cvaMerge(["flex", "justify-between", "mt-1", "text-xs", "text-slate-500"], {
|
|
644
657
|
variants: {
|
|
@@ -657,8 +670,9 @@ const cvaHelpAddon = cssClassVarianceUtilities.cvaMerge(["ml-auto"]);
|
|
|
657
670
|
* @param {FormGroupProps} props - The props for the FormGroup component
|
|
658
671
|
* @returns {JSX.Element} FormGroup component
|
|
659
672
|
*/
|
|
660
|
-
const FormGroup = ({ isInvalid, helpText, helpAddon, tip, className, dataTestId, label, htmlFor, children,
|
|
661
|
-
|
|
673
|
+
const FormGroup = ({ isInvalid, helpText, helpAddon, tip, className, dataTestId, label, htmlFor, children, required = false, }) => {
|
|
674
|
+
const [t] = useTranslation();
|
|
675
|
+
return (jsxRuntime.jsxs("div", { className: cvaFormGroup({ 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(reactComponents.Tooltip, { "data-testid": "required-asterisk", label: t("field.required.asterisk.tooltip"), children: "*" })) : null] })) : null, tip ? (jsxRuntime.jsx(reactComponents.Tooltip, { dataTestId: dataTestId ? `${dataTestId}-tooltip` : undefined, 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] })] }));
|
|
662
676
|
};
|
|
663
677
|
|
|
664
678
|
/**
|
|
@@ -669,7 +683,7 @@ const FormGroup = ({ isInvalid, helpText, helpAddon, tip, className, dataTestId,
|
|
|
669
683
|
const CheckboxField = React.forwardRef((_a, ref) => {
|
|
670
684
|
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"]);
|
|
671
685
|
const htmlForId = id ? id : "checkboxField-" + uuid.v4();
|
|
672
|
-
return (jsxRuntime.jsx(FormGroup, { className: "flex flex-col gap-1", dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined,
|
|
686
|
+
return (jsxRuntime.jsx(FormGroup, { className: "flex flex-col gap-1", dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, 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)) }));
|
|
673
687
|
});
|
|
674
688
|
CheckboxField.displayName = "CheckboxField";
|
|
675
689
|
|
|
@@ -704,11 +718,11 @@ const ColorField = React.forwardRef((_a, ref) => {
|
|
|
704
718
|
}
|
|
705
719
|
}, [onChange]);
|
|
706
720
|
const renderAsInvalid = !!errorMessage || (value && typeof value === "string" && !isValidHEXColor(value)) || isInvalid;
|
|
707
|
-
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined,
|
|
721
|
+
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.jsxs("div", { className: cvaInput({
|
|
708
722
|
disabled: false,
|
|
709
723
|
invalid: false,
|
|
710
724
|
className,
|
|
711
|
-
}), "data-testid": dataTestId ? `${dataTestId}-container` :
|
|
725
|
+
}), "data-testid": dataTestId ? `${dataTestId}-container` : undefined, children: [jsxRuntime.jsx("input", { "aria-labelledby": htmlForId + "-label-text", className: cvaInputField({ disabled: false }), "data-testid": dataTestId ? `${dataTestId}-textField` : undefined, 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
726
|
if (innerRef.current) {
|
|
713
727
|
innerRef.current.click();
|
|
714
728
|
}
|
|
@@ -741,7 +755,7 @@ const DateField = React.forwardRef((_a, ref) => {
|
|
|
741
755
|
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"]);
|
|
742
756
|
const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
|
|
743
757
|
const htmlForId = id ? id : "dateField-" + uuid.v4();
|
|
744
|
-
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined,
|
|
758
|
+
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(DateInput, Object.assign({ "aria-labelledby": htmlForId + "-label", defaultValue: defaultValue, id: htmlForId, isInvalid: renderAsInvalid, ref: ref }, rest, { className: className, dataTestId: dataTestId })) }));
|
|
745
759
|
});
|
|
746
760
|
DateField.displayName = "DateField";
|
|
747
761
|
|
|
@@ -916,7 +930,7 @@ const EmailField = React.forwardRef((_a, ref) => {
|
|
|
916
930
|
onChange(event);
|
|
917
931
|
}
|
|
918
932
|
}, [onChange]);
|
|
919
|
-
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined,
|
|
933
|
+
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(EmailInput, Object.assign({ "aria-labelledby": htmlForId + "-label", defaultValue: defaultValue, disabled: disabled, id: htmlForId, isInvalid: renderAsInvalid, onChange: handleChange, ref: ref, value: value }, rest, { className: className, dataTestId: dataTestId })) }));
|
|
920
934
|
});
|
|
921
935
|
EmailField.displayName = "EmailField";
|
|
922
936
|
|
|
@@ -1145,7 +1159,7 @@ const PhoneField = React.forwardRef((_a, ref) => {
|
|
|
1145
1159
|
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"]);
|
|
1146
1160
|
const htmlForId = id ? id : "phoneField-" + uuid.v4();
|
|
1147
1161
|
const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
|
|
1148
|
-
return (jsxRuntime.jsx(FormGroup, { className: className, dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined,
|
|
1162
|
+
return (jsxRuntime.jsx(FormGroup, { className: className, 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(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)) }));
|
|
1149
1163
|
});
|
|
1150
1164
|
PhoneField.displayName = "PhoneField";
|
|
1151
1165
|
|
|
@@ -1585,15 +1599,14 @@ const cvaSelectIcon = cssClassVarianceUtilities.cvaMerge([
|
|
|
1585
1599
|
"text-slate-400",
|
|
1586
1600
|
"hover:text-slate-500",
|
|
1587
1601
|
]);
|
|
1588
|
-
const
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
]);
|
|
1602
|
+
const cvaSelectPrefixSuffix = cssClassVarianceUtilities.cvaMerge(["flex", "justify-center", "items-center", "text-slate-400", "absolute", "inset-y-0"], {
|
|
1603
|
+
variants: {
|
|
1604
|
+
kind: {
|
|
1605
|
+
prefix: ["pl-3", "left-0"],
|
|
1606
|
+
suffix: ["pr-3", "right-0"],
|
|
1607
|
+
},
|
|
1608
|
+
},
|
|
1609
|
+
});
|
|
1597
1610
|
const cvaSelectXIcon = cssClassVarianceUtilities.cvaMerge([
|
|
1598
1611
|
"mr-2",
|
|
1599
1612
|
"flex",
|
|
@@ -1784,10 +1797,12 @@ const TagsContainer = ({ items, width = "100%", itemsGap = 5, postFix, disabled
|
|
|
1784
1797
|
* @param {React.MutableRefObject<boolean>} refMenuIsEnabled a flag to block menu from open
|
|
1785
1798
|
* @param {string} dataTestId a test id
|
|
1786
1799
|
* @param {number} maxSelectedDisplayCount a number of max display count
|
|
1787
|
-
*
|
|
1800
|
+
* @param {JSX.Element} dropdownIcon an custom dropdown icon
|
|
1801
|
+
* @param {boolean} hasError decide to override hasError variant
|
|
1802
|
+
* @param {JSX.Element} prefix a prefix element
|
|
1788
1803
|
* @returns {Partial<SelectComponents<Option, boolean, GroupBase<Option>>> | undefined} components object to override react-select default components
|
|
1789
1804
|
*/
|
|
1790
|
-
const useCustomComponents = (componentsProps, disabled,
|
|
1805
|
+
const useCustomComponents = ({ componentsProps, disabled, readOnly, refMenuIsEnabled, dataTestId, maxSelectedDisplayCount, dropdownIcon, prefix, hasError, }) => {
|
|
1791
1806
|
const [t] = useTranslation();
|
|
1792
1807
|
// perhaps it should not be wrap in memo (causing some issues with opening and closing on mobiles)
|
|
1793
1808
|
const customComponents = React__namespace.useMemo(() => {
|
|
@@ -1827,11 +1842,11 @@ const useCustomComponents = (componentsProps, disabled, menuIsOpen, refMenuIsEna
|
|
|
1827
1842
|
: null, tags && tags.length > maxSelectedDisplayCount ? (jsxRuntime.jsxs(reactComponents.Tag, { color: "neutral", dataTestId: "counter-tag", children: ["+", tags.length - maxSelectedDisplayCount] })) : null, searchInput] })) })));
|
|
1828
1843
|
}
|
|
1829
1844
|
return (jsxRuntime.jsx(ReactSelect.components.ValueContainer, Object.assign({}, props, { isDisabled: props.selectProps.isDisabled, children: props.children })));
|
|
1830
|
-
}, LoadingIndicator:
|
|
1831
|
-
return jsxRuntime.jsx(reactComponents.Spinner, { className: "mr-
|
|
1845
|
+
}, LoadingIndicator: () => {
|
|
1846
|
+
return jsxRuntime.jsx(reactComponents.Spinner, { centering: "vertically", className: "mr-2", size: "small" });
|
|
1832
1847
|
}, DropdownIndicator: props => {
|
|
1833
1848
|
const icon = props.selectProps.menuIsOpen ? (jsxRuntime.jsx(reactComponents.Icon, { name: "ChevronUp", size: "medium" })) : (jsxRuntime.jsx(reactComponents.Icon, { name: "ChevronDown", size: "medium" }));
|
|
1834
|
-
return props.selectProps.isLoading ? null : (jsxRuntime.jsx(ReactSelect.components.DropdownIndicator, Object.assign({}, props, { children: jsxRuntime.jsx("div", { className: cvaSelectIcon(), children: dropdownIcon ? dropdownIcon : icon }) })));
|
|
1849
|
+
return props.selectProps.isLoading || props.selectProps.isDisabled || readOnly ? null : (jsxRuntime.jsx(ReactSelect.components.DropdownIndicator, Object.assign({}, props, { children: jsxRuntime.jsx("div", { className: cvaSelectIcon(), children: dropdownIcon !== null && dropdownIcon !== void 0 ? dropdownIcon : icon }) })));
|
|
1835
1850
|
}, IndicatorSeparator: () => null, ClearIndicator: props => {
|
|
1836
1851
|
if (disabled) {
|
|
1837
1852
|
return null;
|
|
@@ -1879,7 +1894,7 @@ const useCustomComponents = (componentsProps, disabled, menuIsOpen, refMenuIsEna
|
|
|
1879
1894
|
* @param {StylesConfig<Option, IsMulti, Group> | undefined} styles a optional object to override styles of react-select
|
|
1880
1895
|
* @returns {StylesConfig<Option, boolean>} styles to override in select
|
|
1881
1896
|
*/
|
|
1882
|
-
const useCustomStyles = (refContainer, refPrefix, maxSelectedDisplayCount, styles, disabled) => {
|
|
1897
|
+
const useCustomStyles = ({ refContainer, refPrefix, maxSelectedDisplayCount, styles, disabled, }) => {
|
|
1883
1898
|
const customStyles = React__namespace.useMemo(() => {
|
|
1884
1899
|
return Object.assign({ control: base => {
|
|
1885
1900
|
return Object.assign(Object.assign({}, base), { borderRadius: "var(--border-radius-lg)", backgroundColor: "" });
|
|
@@ -1887,7 +1902,7 @@ const useCustomStyles = (refContainer, refPrefix, maxSelectedDisplayCount, style
|
|
|
1887
1902
|
width: "0px",
|
|
1888
1903
|
}), menu: base => {
|
|
1889
1904
|
return Object.assign(Object.assign({}, base), { width: "100%", marginTop: "4px", marginBottom: "18px", transition: "all 1s ease-in-out" });
|
|
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,
|
|
1905
|
+
}, 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, 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 => {
|
|
1891
1906
|
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" });
|
|
1892
1907
|
}, valueContainer: base => {
|
|
1893
1908
|
return Object.assign(Object.assign({}, base), { flexWrap: maxSelectedDisplayCount !== undefined ? "wrap" : "nowrap", gap: "0.25rem" });
|
|
@@ -1903,20 +1918,36 @@ const useCustomStyles = (refContainer, refPrefix, maxSelectedDisplayCount, style
|
|
|
1903
1918
|
* A hook used by selects to share the common code
|
|
1904
1919
|
*
|
|
1905
1920
|
* @param {SelectProps} props - The props for the Select component
|
|
1906
|
-
* @returns {
|
|
1921
|
+
* @returns {UseSelectProps} Select component
|
|
1907
1922
|
*/
|
|
1908
1923
|
const useSelect = (_a) => {
|
|
1909
1924
|
var _b;
|
|
1910
1925
|
var { id, className, dataTestId = "select", prefix, async, dropdownIcon, maxMenuHeight = 200, label, hasError, disabled, isMulti, components, value, options, onChange, isLoading, classNamePrefix = "", onMenuOpen, onMenuClose, maxSelectedDisplayCount = undefined, isClearable = false, isSearchable = true, onMenuScrollToBottom, styles, filterOption, onInputChange } = _a, props = __rest(_a, ["id", "className", "dataTestId", "prefix", "async", "dropdownIcon", "maxMenuHeight", "label", "hasError", "disabled", "isMulti", "components", "value", "options", "onChange", "isLoading", "classNamePrefix", "onMenuOpen", "onMenuClose", "maxSelectedDisplayCount", "isClearable", "isSearchable", "onMenuScrollToBottom", "styles", "filterOption", "onInputChange"]);
|
|
1911
1926
|
const refContainer = React__default["default"].useRef(null);
|
|
1912
1927
|
const refPrefix = React__default["default"].useRef(null);
|
|
1913
|
-
const { customStyles } = useCustomStyles(
|
|
1928
|
+
const { customStyles } = useCustomStyles({
|
|
1929
|
+
refContainer,
|
|
1930
|
+
refPrefix,
|
|
1931
|
+
maxSelectedDisplayCount,
|
|
1932
|
+
styles,
|
|
1933
|
+
disabled: Boolean(disabled),
|
|
1934
|
+
});
|
|
1914
1935
|
const [menuIsOpen, setMenuIsOpen] = React__default["default"].useState((_b = props.menuIsOpen) !== null && _b !== void 0 ? _b : false);
|
|
1915
1936
|
const refMenuIsEnabled = React__default["default"].useRef(true);
|
|
1916
|
-
const customComponents = useCustomComponents(
|
|
1937
|
+
const customComponents = useCustomComponents({
|
|
1938
|
+
componentsProps: components,
|
|
1939
|
+
disabled: Boolean(disabled),
|
|
1940
|
+
readOnly: Boolean(props.readOnly),
|
|
1941
|
+
refMenuIsEnabled,
|
|
1942
|
+
dataTestId,
|
|
1943
|
+
maxSelectedDisplayCount,
|
|
1944
|
+
dropdownIcon,
|
|
1945
|
+
prefix,
|
|
1946
|
+
hasError,
|
|
1947
|
+
});
|
|
1917
1948
|
const menuPlacement = "auto";
|
|
1918
1949
|
const openMenuHandler = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1919
|
-
onMenuOpen
|
|
1950
|
+
onMenuOpen === null || onMenuOpen === void 0 ? void 0 : onMenuOpen();
|
|
1920
1951
|
if (refMenuIsEnabled.current) {
|
|
1921
1952
|
setMenuIsOpen(true);
|
|
1922
1953
|
}
|
|
@@ -1955,10 +1986,9 @@ const useSelect = (_a) => {
|
|
|
1955
1986
|
* @returns {JSX.Element} CreatableSelect component
|
|
1956
1987
|
*/
|
|
1957
1988
|
const CreatableSelect = (props) => {
|
|
1958
|
-
const {
|
|
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;
|
|
1989
|
+
const { id, dataTestId = "creatableSelect", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, value, options, onChange, isLoading, classNamePrefix = "creatableSelect", onMenuScrollToBottom, filterOption, onInputChange, isSearchable, isClearable = false, readOnly, openMenuOnClick = !disabled, openMenuOnFocus = !disabled, allowCreateWhileLoading, onCreateOption, } = props;
|
|
1960
1990
|
const { refContainer, refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler, orderedOptions, } = useSelect(props);
|
|
1961
|
-
const
|
|
1991
|
+
const reactCreatableSelectProps = React.useMemo(() => ({
|
|
1962
1992
|
value,
|
|
1963
1993
|
menuPlacement,
|
|
1964
1994
|
maxMenuHeight,
|
|
@@ -1986,11 +2016,35 @@ const CreatableSelect = (props) => {
|
|
|
1986
2016
|
onInputChange,
|
|
1987
2017
|
allowCreateWhileLoading,
|
|
1988
2018
|
onCreateOption,
|
|
1989
|
-
isDisabled: disabled
|
|
2019
|
+
isDisabled: Boolean(disabled),
|
|
2020
|
+
}), [
|
|
2021
|
+
allowCreateWhileLoading,
|
|
2022
|
+
classNamePrefix,
|
|
2023
|
+
customComponents,
|
|
2024
|
+
customStyles,
|
|
2025
|
+
dataTestId,
|
|
2026
|
+
disabled,
|
|
2027
|
+
id,
|
|
2028
|
+
isClearable,
|
|
2029
|
+
isLoading,
|
|
2030
|
+
isMulti,
|
|
2031
|
+
isSearchable,
|
|
2032
|
+
label,
|
|
2033
|
+
maxMenuHeight,
|
|
2034
|
+
menuIsOpen,
|
|
2035
|
+
menuPlacement,
|
|
2036
|
+
onChange,
|
|
2037
|
+
onCreateOption,
|
|
2038
|
+
onInputChange,
|
|
2039
|
+
onMenuScrollToBottom,
|
|
2040
|
+
openMenuOnClick,
|
|
2041
|
+
openMenuOnFocus,
|
|
2042
|
+
props.menuPortalTarget,
|
|
1990
2043
|
readOnly,
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
2044
|
+
value,
|
|
2045
|
+
]);
|
|
2046
|
+
const renderAsDisabled = Boolean(props.disabled) || props.readOnly;
|
|
2047
|
+
return (jsxRuntime.jsxs("div", { className: cvaSelect({ invalid: hasError, disabled: renderAsDisabled, className: props.className }), "data-testid": dataTestId, ref: refContainer, children: [prefix !== undefined ? (jsxRuntime.jsx("div", { className: cvaSelectPrefixSuffix({ kind: "prefix" }), "data-testid": dataTestId ? `${dataTestId}-prefix` : null, ref: refPrefix, children: prefix })) : null, async ? (jsxRuntime.jsx(ReactAsyncCreatableSelect__default["default"], Object.assign({}, props, reactCreatableSelectProps, async, { onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, placeholder: renderAsDisabled ? null : props.placeholder }))) : (jsxRuntime.jsx(ReactCreatableSelect__default["default"], Object.assign({}, props, reactCreatableSelectProps, { hideSelectedOptions: false, isMulti: isMulti, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, options: filterOption ? orderedOptions : options, placeholder: renderAsDisabled ? null : props.placeholder }))), typeof props.disabled === "object" ? (jsxRuntime.jsx("div", { className: cvaSelectPrefixSuffix({ kind: "suffix" }), "data-testid": dataTestId ? `${dataTestId}-locked` : null, children: jsxRuntime.jsx(DisabledForReasonsTip, Object.assign({}, props.disabled)) })) : null] }));
|
|
1994
2048
|
};
|
|
1995
2049
|
CreatableSelect.displayName = "CreatableSelect";
|
|
1996
2050
|
|
|
@@ -2001,10 +2055,9 @@ CreatableSelect.displayName = "CreatableSelect";
|
|
|
2001
2055
|
* @returns {JSX.Element} Select component
|
|
2002
2056
|
*/
|
|
2003
2057
|
const Select = (props) => {
|
|
2004
|
-
const {
|
|
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;
|
|
2058
|
+
const { id, dataTestId = "select", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, menuPosition = "absolute", value, options, onChange, isLoading, classNamePrefix = "select", onMenuScrollToBottom, filterOption, onInputChange, isSearchable, isClearable = false, readOnly, openMenuOnClick = !disabled, openMenuOnFocus = !disabled, hideSelectedOptions = false, } = props;
|
|
2006
2059
|
const { refContainer, refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler, orderedOptions, } = useSelect(props);
|
|
2007
|
-
const
|
|
2060
|
+
const reactSelectProps = React.useMemo(() => ({
|
|
2008
2061
|
value,
|
|
2009
2062
|
menuPlacement,
|
|
2010
2063
|
maxMenuHeight,
|
|
@@ -2031,11 +2084,34 @@ const Select = (props) => {
|
|
|
2031
2084
|
onMenuScrollToBottom,
|
|
2032
2085
|
onInputChange,
|
|
2033
2086
|
hideSelectedOptions,
|
|
2034
|
-
isDisabled: disabled
|
|
2087
|
+
isDisabled: Boolean(disabled),
|
|
2088
|
+
}), [
|
|
2089
|
+
classNamePrefix,
|
|
2090
|
+
customComponents,
|
|
2091
|
+
customStyles,
|
|
2092
|
+
dataTestId,
|
|
2093
|
+
disabled,
|
|
2094
|
+
hideSelectedOptions,
|
|
2095
|
+
id,
|
|
2096
|
+
isClearable,
|
|
2097
|
+
isLoading,
|
|
2098
|
+
isMulti,
|
|
2099
|
+
isSearchable,
|
|
2100
|
+
label,
|
|
2101
|
+
maxMenuHeight,
|
|
2102
|
+
menuIsOpen,
|
|
2103
|
+
menuPlacement,
|
|
2104
|
+
onChange,
|
|
2105
|
+
onInputChange,
|
|
2106
|
+
onMenuScrollToBottom,
|
|
2107
|
+
openMenuOnClick,
|
|
2108
|
+
openMenuOnFocus,
|
|
2109
|
+
props.menuPortalTarget,
|
|
2035
2110
|
readOnly,
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2111
|
+
value,
|
|
2112
|
+
]);
|
|
2113
|
+
const renderAsDisabled = Boolean(props.disabled) || props.readOnly;
|
|
2114
|
+
return (jsxRuntime.jsxs("div", { className: cvaSelect({ invalid: hasError, disabled: renderAsDisabled, className: props.className }), "data-testid": dataTestId, ref: refContainer, children: [prefix !== undefined ? (jsxRuntime.jsx("div", { className: cvaSelectPrefixSuffix({ kind: "prefix" }), "data-testid": dataTestId ? `${dataTestId}-prefix` : null, ref: refPrefix, children: prefix })) : null, async ? (jsxRuntime.jsx(ReactAsyncSelect__default["default"], Object.assign({}, props, reactSelectProps, async, { menuPosition: menuPosition, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, placeholder: renderAsDisabled ? null : props.placeholder }))) : (jsxRuntime.jsx(ReactSelect__default["default"], Object.assign({}, props, reactSelectProps, { isMulti: isMulti, menuPosition: menuPosition, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, options: filterOption ? orderedOptions : options, placeholder: renderAsDisabled ? null : props.placeholder }))), typeof props.disabled === "object" ? (jsxRuntime.jsx("div", { className: cvaSelectPrefixSuffix({ kind: "suffix" }), "data-testid": dataTestId ? `${dataTestId}-locked` : null, children: jsxRuntime.jsx(DisabledForReasonsTip, Object.assign({}, props.disabled)) })) : null] }));
|
|
2039
2115
|
};
|
|
2040
2116
|
Select.displayName = "Select";
|
|
2041
2117
|
|
|
@@ -2078,10 +2154,11 @@ const FormFieldSelectAdapter = React.forwardRef((_a, ref) => {
|
|
|
2078
2154
|
helpText: (renderAsInvalid && errorMessage) || helpText,
|
|
2079
2155
|
helpAddon,
|
|
2080
2156
|
tip,
|
|
2081
|
-
label,
|
|
2082
|
-
disabled, children: [jsxRuntime.jsx("select", { onChange, ref: innerRef, name, value: innerValue, hidden: true, children: optionsWithCurrentSelectionBackupOption.map(option => {
|
|
2157
|
+
label, children: [jsxRuntime.jsx("select", { onChange, ref: innerRef, name, value: innerValue, hidden: true, disabled: Boolean(disabled), children: optionsWithCurrentSelectionBackupOption.map(option => {
|
|
2083
2158
|
return (jsxRuntime.jsx("option", { value: option.value, children: option.label }, option.value));
|
|
2084
|
-
}) }), children(Object.assign(Object.assign({}, rest), { id,
|
|
2159
|
+
}) }), children(Object.assign(Object.assign({}, rest), { id,
|
|
2160
|
+
disabled,
|
|
2161
|
+
onBlur, options: optionsWithCurrentSelectionBackupOption, onChange: e => {
|
|
2085
2162
|
// If theres no value, set the inner value to an empty string
|
|
2086
2163
|
// A native select can not have a null value
|
|
2087
2164
|
// So even if react-select sends a null value, we need to convert it to an empty string
|
|
@@ -2222,10 +2299,10 @@ TextField.displayName = "TextField";
|
|
|
2222
2299
|
* @returns {JSX.Element} TimeRangeField component
|
|
2223
2300
|
*/
|
|
2224
2301
|
const TimeRangeField = (_a) => {
|
|
2225
|
-
var { className, dataTestId, onChange, isInvalid, errorMessage, label, tip,
|
|
2302
|
+
var { className, dataTestId, onChange, isInvalid, errorMessage, label, tip, children, helpText, id } = _a, rest = __rest(_a, ["className", "dataTestId", "onChange", "isInvalid", "errorMessage", "label", "tip", "children", "helpText", "id"]);
|
|
2226
2303
|
const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
|
|
2227
2304
|
const htmlFor = id ? id : "timeRangeField-" + uuid.v4();
|
|
2228
|
-
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined,
|
|
2305
|
+
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, helpText: (renderAsInvalid && errorMessage) || helpText, htmlFor: htmlFor, isInvalid: renderAsInvalid, label: label, tip: tip, children: jsxRuntime.jsx(TimeRange, Object.assign({ className: className, dataTestId: dataTestId, isInvalid: renderAsInvalid, onChange: onChange }, rest, { children: children })) }));
|
|
2229
2306
|
};
|
|
2230
2307
|
|
|
2231
2308
|
const cvaToggleWrapper = cssClassVarianceUtilities.cvaMerge(["flex", "gap-2", "items-center"]);
|
|
@@ -2379,7 +2456,7 @@ const UrlField = React.forwardRef((_a, ref) => {
|
|
|
2379
2456
|
return typeof inputValue === "string";
|
|
2380
2457
|
}
|
|
2381
2458
|
const renderAsInvalid = !!errorMessage || (value && isString(value) && !validateUrlAddress(value)) || isInvalid;
|
|
2382
|
-
return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined,
|
|
2459
|
+
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(UrlInput, Object.assign({ "aria-labelledby": htmlForId + "-label", id: htmlForId, isInvalid: renderAsInvalid, ref: ref, value: value || defaultValue }, rest, { className: className, dataTestId: dataTestId })) }));
|
|
2383
2460
|
});
|
|
2384
2461
|
UrlField.displayName = "UrlField";
|
|
2385
2462
|
|
|
@@ -2556,7 +2633,7 @@ exports.cvaSelectDynamicTagContainer = cvaSelectDynamicTagContainer;
|
|
|
2556
2633
|
exports.cvaSelectIcon = cvaSelectIcon;
|
|
2557
2634
|
exports.cvaSelectMenu = cvaSelectMenu;
|
|
2558
2635
|
exports.cvaSelectMenuList = cvaSelectMenuList;
|
|
2559
|
-
exports.
|
|
2636
|
+
exports.cvaSelectPrefixSuffix = cvaSelectPrefixSuffix;
|
|
2560
2637
|
exports.cvaSelectXIcon = cvaSelectXIcon;
|
|
2561
2638
|
exports.getCountryAbbreviation = getCountryAbbreviation;
|
|
2562
2639
|
exports.getOrderedOptions = getOrderedOptions;
|
package/index.esm.js
CHANGED
|
@@ -23,6 +23,8 @@ var defaultTranslations = {
|
|
|
23
23
|
"clearIndicator.icon.tooltip.clearAll": "Clear all",
|
|
24
24
|
"dropzone.input.title": "Drag-and-drop file input",
|
|
25
25
|
"dropzone.label.default": "<clickable>Browse</clickable> or drag files here...",
|
|
26
|
+
"field.notEditable.tooltip": "This field is not editable",
|
|
27
|
+
"field.required.asterisk.tooltip": "This field is required",
|
|
26
28
|
"phoneField.error.INVALID_COUNTRY": "The country code is not valid",
|
|
27
29
|
"phoneField.error.INVALID_LENGTH": "The phone number is not valid",
|
|
28
30
|
"phoneField.error.INVALID_NUMBER": "The phone number is not valid",
|
|
@@ -354,6 +356,22 @@ const cvaInputAction = cvaMerge(["absolute", "end-0.5"], {
|
|
|
354
356
|
],
|
|
355
357
|
});
|
|
356
358
|
|
|
359
|
+
/**
|
|
360
|
+
* Icon with explanation tooltip for why an input is locked or disabled.
|
|
361
|
+
* If locked, a permission lacks but the input **can** sometimes be edited.
|
|
362
|
+
* If disabled, the input **cannot** be edited and is only ever for displaying information.
|
|
363
|
+
*
|
|
364
|
+
* @param {DisabledForReasons} props - The reasons for the disabled state.
|
|
365
|
+
* @param {DisabledKind} kind - The kind of disabled state. If locked, the input can sometimes be edited. If disabled, the input cannot be edited.
|
|
366
|
+
*/
|
|
367
|
+
const DisabledForReasonsTip = ({ reasons, kind }) => {
|
|
368
|
+
const [t] = useTranslation();
|
|
369
|
+
if (!reasons || reasons.length === 0) {
|
|
370
|
+
jsx(Tooltip, { label: t("field.notEditable.tooltip"), children: jsx(Icon, { name: kind === "disabled" ? "QuestionMarkCircle" : "LockClosed", size: "small" }) });
|
|
371
|
+
}
|
|
372
|
+
return (jsx(Tooltip, { label: jsx("ul", { className: typeof reasons === "string" || (reasons === null || reasons === void 0 ? void 0 : reasons.length) === 1 ? "list-inside" : "list-disc", children: typeof reasons === "string" ? jsx("li", { children: reasons }) : reasons === null || reasons === void 0 ? void 0 : reasons.map(reason => jsx("li", { children: reason }, reason)) }), placement: "top", children: jsx(Icon, { name: "LockClosed", size: "small" }) }));
|
|
373
|
+
};
|
|
374
|
+
|
|
357
375
|
/**
|
|
358
376
|
* A base input component that can be used for text inputs, password inputs, etc.
|
|
359
377
|
* A reference to the input element is provided as the `ref` prop.
|
|
@@ -365,7 +383,7 @@ const cvaInputAction = cvaMerge(["absolute", "end-0.5"], {
|
|
|
365
383
|
const BaseInput = React.forwardRef((_a, ref) => {
|
|
366
384
|
var _b;
|
|
367
385
|
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"]);
|
|
368
|
-
const renderAsDisabled = rest.disabled || rest.readOnly;
|
|
386
|
+
const renderAsDisabled = Boolean(rest.disabled) || rest.readOnly;
|
|
369
387
|
const innerRef = React.useRef(null);
|
|
370
388
|
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
371
389
|
React.useImperativeHandle(ref, () => innerRef.current, []);
|
|
@@ -384,7 +402,9 @@ const BaseInput = React.forwardRef((_a, ref) => {
|
|
|
384
402
|
className: inputClassName,
|
|
385
403
|
addonBefore: addonBefore !== undefined,
|
|
386
404
|
prefix: !compareReactNodes(addonBefore, prefix),
|
|
387
|
-
}), "data-testid": dataTestId, placeholder: renderAsDisabled ? undefined : placeholder, ref: innerRef }, rest, { disabled: renderAsDisabled, readOnly: rest.readOnly || nonInteractive })),
|
|
405
|
+
}), "data-testid": dataTestId, placeholder: renderAsDisabled ? undefined : placeholder, ref: innerRef }, rest, { disabled: renderAsDisabled, readOnly: rest.readOnly || nonInteractive })), typeof rest.disabled === "object" ? (jsx("div", { className: cvaInputSuffix({
|
|
406
|
+
disabled: false,
|
|
407
|
+
}), "data-testid": dataTestId ? `${dataTestId}-locked` : undefined, children: jsx(DisabledForReasonsTip, Object.assign({}, rest.disabled)) })) : null, suffix && addonBefore !== suffix ? (jsx("div", { className: cvaInputSuffix({
|
|
388
408
|
disabled: renderAsDisabled,
|
|
389
409
|
addonAfter: addonAfter !== undefined && !compareReactNodes(addonBefore, addonAfter),
|
|
390
410
|
actions: (actions && !compareReactNodes(addonBefore, actions)) || false,
|
|
@@ -601,14 +621,7 @@ const Label = ({ id, htmlFor, children, className, dataTestId, disabled, isInval
|
|
|
601
621
|
return (jsx("label", { className: cvaLabel({ invalid: isInvalid, disabled, className }), "data-testid": dataTestId, htmlFor: htmlFor || "", id: id || "", children: children }));
|
|
602
622
|
};
|
|
603
623
|
|
|
604
|
-
const cvaFormGroup = cvaMerge(["component-formGroup-gap"]
|
|
605
|
-
variants: {
|
|
606
|
-
disabled: {
|
|
607
|
-
true: "pointer-events-none",
|
|
608
|
-
false: "",
|
|
609
|
-
},
|
|
610
|
-
},
|
|
611
|
-
});
|
|
624
|
+
const cvaFormGroup = cvaMerge(["component-formGroup-gap"]);
|
|
612
625
|
const cvaFormGroupContainerBefore = cvaMerge(["flex", "mb-1", "items-center"]);
|
|
613
626
|
const cvaFormGroupContainerAfter = cvaMerge(["flex", "justify-between", "mt-1", "text-xs", "text-slate-500"], {
|
|
614
627
|
variants: {
|
|
@@ -627,8 +640,9 @@ const cvaHelpAddon = cvaMerge(["ml-auto"]);
|
|
|
627
640
|
* @param {FormGroupProps} props - The props for the FormGroup component
|
|
628
641
|
* @returns {JSX.Element} FormGroup component
|
|
629
642
|
*/
|
|
630
|
-
const FormGroup = ({ isInvalid, helpText, helpAddon, tip, className, dataTestId, label, htmlFor, children,
|
|
631
|
-
|
|
643
|
+
const FormGroup = ({ isInvalid, helpText, helpAddon, tip, className, dataTestId, label, htmlFor, children, required = false, }) => {
|
|
644
|
+
const [t] = useTranslation();
|
|
645
|
+
return (jsxs("div", { className: cvaFormGroup({ className }), "data-testid": dataTestId, children: [jsxs("div", { className: cvaFormGroupContainerBefore(), children: [label ? (jsxs(Fragment, { children: [jsx(Label, { className: "component-formGroup-font", dataTestId: dataTestId ? `${dataTestId}-label` : undefined, htmlFor: htmlFor, id: htmlFor + "-label", children: label }), required ? (jsx(Tooltip, { "data-testid": "required-asterisk", label: t("field.required.asterisk.tooltip"), children: "*" })) : null] })) : null, tip ? (jsx(Tooltip, { dataTestId: dataTestId ? `${dataTestId}-tooltip` : undefined, label: tip, placement: "bottom" })) : null] }), children, jsxs("div", { className: cvaFormGroupContainerAfter({ invalid: isInvalid }), children: [helpText ? jsx("span", { "data-testid": dataTestId ? `${dataTestId}-helpText` : undefined, children: helpText }) : undefined, helpAddon ? (jsx("span", { className: cvaHelpAddon(), "data-testid": dataTestId ? `${dataTestId}-helpAddon` : null, children: helpAddon })) : null] })] }));
|
|
632
646
|
};
|
|
633
647
|
|
|
634
648
|
/**
|
|
@@ -639,7 +653,7 @@ const FormGroup = ({ isInvalid, helpText, helpAddon, tip, className, dataTestId,
|
|
|
639
653
|
const CheckboxField = forwardRef((_a, ref) => {
|
|
640
654
|
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"]);
|
|
641
655
|
const htmlForId = id ? id : "checkboxField-" + v4();
|
|
642
|
-
return (jsx(FormGroup, { className: "flex flex-col gap-1", dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined,
|
|
656
|
+
return (jsx(FormGroup, { className: "flex flex-col gap-1", dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, helpAddon: helpAddon, helpText: helpText, htmlFor: htmlForId, label: label, required: rest.required, tip: tip, children: jsx(Checkbox, Object.assign({ checked: checked, className: className, dataTestId: dataTestId, id: htmlForId, label: checkboxLabel, onChange: onChange, ref: ref }, rest)) }));
|
|
643
657
|
});
|
|
644
658
|
CheckboxField.displayName = "CheckboxField";
|
|
645
659
|
|
|
@@ -674,11 +688,11 @@ const ColorField = forwardRef((_a, ref) => {
|
|
|
674
688
|
}
|
|
675
689
|
}, [onChange]);
|
|
676
690
|
const renderAsInvalid = !!errorMessage || (value && typeof value === "string" && !isValidHEXColor(value)) || isInvalid;
|
|
677
|
-
return (jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined,
|
|
691
|
+
return (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: jsxs("div", { className: cvaInput({
|
|
678
692
|
disabled: false,
|
|
679
693
|
invalid: false,
|
|
680
694
|
className,
|
|
681
|
-
}), "data-testid": dataTestId ? `${dataTestId}-container` :
|
|
695
|
+
}), "data-testid": dataTestId ? `${dataTestId}-container` : undefined, children: [jsx("input", { "aria-labelledby": htmlForId + "-label-text", className: cvaInputField({ disabled: false }), "data-testid": dataTestId ? `${dataTestId}-textField` : undefined, onChange: handleChange, type: "text", value: value }), 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 }), jsx(IconButton, { className: "mr-1 self-center", icon: jsx(Icon, { name: "Pencil", type: "outline" }), onClick: () => {
|
|
682
696
|
if (innerRef.current) {
|
|
683
697
|
innerRef.current.click();
|
|
684
698
|
}
|
|
@@ -711,7 +725,7 @@ const DateField = forwardRef((_a, ref) => {
|
|
|
711
725
|
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"]);
|
|
712
726
|
const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
|
|
713
727
|
const htmlForId = id ? id : "dateField-" + v4();
|
|
714
|
-
return (jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined,
|
|
728
|
+
return (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: jsx(DateInput, Object.assign({ "aria-labelledby": htmlForId + "-label", defaultValue: defaultValue, id: htmlForId, isInvalid: renderAsInvalid, ref: ref }, rest, { className: className, dataTestId: dataTestId })) }));
|
|
715
729
|
});
|
|
716
730
|
DateField.displayName = "DateField";
|
|
717
731
|
|
|
@@ -886,7 +900,7 @@ const EmailField = forwardRef((_a, ref) => {
|
|
|
886
900
|
onChange(event);
|
|
887
901
|
}
|
|
888
902
|
}, [onChange]);
|
|
889
|
-
return (jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined,
|
|
903
|
+
return (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: jsx(EmailInput, Object.assign({ "aria-labelledby": htmlForId + "-label", defaultValue: defaultValue, disabled: disabled, id: htmlForId, isInvalid: renderAsInvalid, onChange: handleChange, ref: ref, value: value }, rest, { className: className, dataTestId: dataTestId })) }));
|
|
890
904
|
});
|
|
891
905
|
EmailField.displayName = "EmailField";
|
|
892
906
|
|
|
@@ -1115,7 +1129,7 @@ const PhoneField = forwardRef((_a, ref) => {
|
|
|
1115
1129
|
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"]);
|
|
1116
1130
|
const htmlForId = id ? id : "phoneField-" + v4();
|
|
1117
1131
|
const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
|
|
1118
|
-
return (jsx(FormGroup, { className: className, dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined,
|
|
1132
|
+
return (jsx(FormGroup, { className: className, dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, helpAddon: helpAddon, helpText: (renderAsInvalid && errorMessage) || helpText, htmlFor: htmlForId, isInvalid: renderAsInvalid, label: label, required: rest.required, tip: tip, children: 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)) }));
|
|
1119
1133
|
});
|
|
1120
1134
|
PhoneField.displayName = "PhoneField";
|
|
1121
1135
|
|
|
@@ -1555,15 +1569,14 @@ const cvaSelectIcon = cvaMerge([
|
|
|
1555
1569
|
"text-slate-400",
|
|
1556
1570
|
"hover:text-slate-500",
|
|
1557
1571
|
]);
|
|
1558
|
-
const
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
]);
|
|
1572
|
+
const cvaSelectPrefixSuffix = cvaMerge(["flex", "justify-center", "items-center", "text-slate-400", "absolute", "inset-y-0"], {
|
|
1573
|
+
variants: {
|
|
1574
|
+
kind: {
|
|
1575
|
+
prefix: ["pl-3", "left-0"],
|
|
1576
|
+
suffix: ["pr-3", "right-0"],
|
|
1577
|
+
},
|
|
1578
|
+
},
|
|
1579
|
+
});
|
|
1567
1580
|
const cvaSelectXIcon = cvaMerge([
|
|
1568
1581
|
"mr-2",
|
|
1569
1582
|
"flex",
|
|
@@ -1754,10 +1767,12 @@ const TagsContainer = ({ items, width = "100%", itemsGap = 5, postFix, disabled
|
|
|
1754
1767
|
* @param {React.MutableRefObject<boolean>} refMenuIsEnabled a flag to block menu from open
|
|
1755
1768
|
* @param {string} dataTestId a test id
|
|
1756
1769
|
* @param {number} maxSelectedDisplayCount a number of max display count
|
|
1757
|
-
*
|
|
1770
|
+
* @param {JSX.Element} dropdownIcon an custom dropdown icon
|
|
1771
|
+
* @param {boolean} hasError decide to override hasError variant
|
|
1772
|
+
* @param {JSX.Element} prefix a prefix element
|
|
1758
1773
|
* @returns {Partial<SelectComponents<Option, boolean, GroupBase<Option>>> | undefined} components object to override react-select default components
|
|
1759
1774
|
*/
|
|
1760
|
-
const useCustomComponents = (componentsProps, disabled,
|
|
1775
|
+
const useCustomComponents = ({ componentsProps, disabled, readOnly, refMenuIsEnabled, dataTestId, maxSelectedDisplayCount, dropdownIcon, prefix, hasError, }) => {
|
|
1761
1776
|
const [t] = useTranslation();
|
|
1762
1777
|
// perhaps it should not be wrap in memo (causing some issues with opening and closing on mobiles)
|
|
1763
1778
|
const customComponents = React.useMemo(() => {
|
|
@@ -1797,11 +1812,11 @@ const useCustomComponents = (componentsProps, disabled, menuIsOpen, refMenuIsEna
|
|
|
1797
1812
|
: null, tags && tags.length > maxSelectedDisplayCount ? (jsxs(Tag, { color: "neutral", dataTestId: "counter-tag", children: ["+", tags.length - maxSelectedDisplayCount] })) : null, searchInput] })) })));
|
|
1798
1813
|
}
|
|
1799
1814
|
return (jsx(components.ValueContainer, Object.assign({}, props, { isDisabled: props.selectProps.isDisabled, children: props.children })));
|
|
1800
|
-
}, LoadingIndicator:
|
|
1801
|
-
return jsx(Spinner, { className: "mr-
|
|
1815
|
+
}, LoadingIndicator: () => {
|
|
1816
|
+
return jsx(Spinner, { centering: "vertically", className: "mr-2", size: "small" });
|
|
1802
1817
|
}, DropdownIndicator: props => {
|
|
1803
1818
|
const icon = props.selectProps.menuIsOpen ? (jsx(Icon, { name: "ChevronUp", size: "medium" })) : (jsx(Icon, { name: "ChevronDown", size: "medium" }));
|
|
1804
|
-
return props.selectProps.isLoading ? null : (jsx(components.DropdownIndicator, Object.assign({}, props, { children: jsx("div", { className: cvaSelectIcon(), children: dropdownIcon ? dropdownIcon : icon }) })));
|
|
1819
|
+
return props.selectProps.isLoading || props.selectProps.isDisabled || readOnly ? null : (jsx(components.DropdownIndicator, Object.assign({}, props, { children: jsx("div", { className: cvaSelectIcon(), children: dropdownIcon !== null && dropdownIcon !== void 0 ? dropdownIcon : icon }) })));
|
|
1805
1820
|
}, IndicatorSeparator: () => null, ClearIndicator: props => {
|
|
1806
1821
|
if (disabled) {
|
|
1807
1822
|
return null;
|
|
@@ -1849,7 +1864,7 @@ const useCustomComponents = (componentsProps, disabled, menuIsOpen, refMenuIsEna
|
|
|
1849
1864
|
* @param {StylesConfig<Option, IsMulti, Group> | undefined} styles a optional object to override styles of react-select
|
|
1850
1865
|
* @returns {StylesConfig<Option, boolean>} styles to override in select
|
|
1851
1866
|
*/
|
|
1852
|
-
const useCustomStyles = (refContainer, refPrefix, maxSelectedDisplayCount, styles, disabled) => {
|
|
1867
|
+
const useCustomStyles = ({ refContainer, refPrefix, maxSelectedDisplayCount, styles, disabled, }) => {
|
|
1853
1868
|
const customStyles = React.useMemo(() => {
|
|
1854
1869
|
return Object.assign({ control: base => {
|
|
1855
1870
|
return Object.assign(Object.assign({}, base), { borderRadius: "var(--border-radius-lg)", backgroundColor: "" });
|
|
@@ -1857,7 +1872,7 @@ const useCustomStyles = (refContainer, refPrefix, maxSelectedDisplayCount, style
|
|
|
1857
1872
|
width: "0px",
|
|
1858
1873
|
}), menu: base => {
|
|
1859
1874
|
return Object.assign(Object.assign({}, base), { width: "100%", marginTop: "4px", marginBottom: "18px", transition: "all 1s ease-in-out" });
|
|
1860
|
-
}, 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,
|
|
1875
|
+
}, 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, 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 => {
|
|
1861
1876
|
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" });
|
|
1862
1877
|
}, valueContainer: base => {
|
|
1863
1878
|
return Object.assign(Object.assign({}, base), { flexWrap: maxSelectedDisplayCount !== undefined ? "wrap" : "nowrap", gap: "0.25rem" });
|
|
@@ -1873,20 +1888,36 @@ const useCustomStyles = (refContainer, refPrefix, maxSelectedDisplayCount, style
|
|
|
1873
1888
|
* A hook used by selects to share the common code
|
|
1874
1889
|
*
|
|
1875
1890
|
* @param {SelectProps} props - The props for the Select component
|
|
1876
|
-
* @returns {
|
|
1891
|
+
* @returns {UseSelectProps} Select component
|
|
1877
1892
|
*/
|
|
1878
1893
|
const useSelect = (_a) => {
|
|
1879
1894
|
var _b;
|
|
1880
1895
|
var { id, className, dataTestId = "select", prefix, async, dropdownIcon, maxMenuHeight = 200, label, hasError, disabled, isMulti, components, value, options, onChange, isLoading, classNamePrefix = "", onMenuOpen, onMenuClose, maxSelectedDisplayCount = undefined, isClearable = false, isSearchable = true, onMenuScrollToBottom, styles, filterOption, onInputChange } = _a, props = __rest(_a, ["id", "className", "dataTestId", "prefix", "async", "dropdownIcon", "maxMenuHeight", "label", "hasError", "disabled", "isMulti", "components", "value", "options", "onChange", "isLoading", "classNamePrefix", "onMenuOpen", "onMenuClose", "maxSelectedDisplayCount", "isClearable", "isSearchable", "onMenuScrollToBottom", "styles", "filterOption", "onInputChange"]);
|
|
1881
1896
|
const refContainer = React__default.useRef(null);
|
|
1882
1897
|
const refPrefix = React__default.useRef(null);
|
|
1883
|
-
const { customStyles } = useCustomStyles(
|
|
1898
|
+
const { customStyles } = useCustomStyles({
|
|
1899
|
+
refContainer,
|
|
1900
|
+
refPrefix,
|
|
1901
|
+
maxSelectedDisplayCount,
|
|
1902
|
+
styles,
|
|
1903
|
+
disabled: Boolean(disabled),
|
|
1904
|
+
});
|
|
1884
1905
|
const [menuIsOpen, setMenuIsOpen] = React__default.useState((_b = props.menuIsOpen) !== null && _b !== void 0 ? _b : false);
|
|
1885
1906
|
const refMenuIsEnabled = React__default.useRef(true);
|
|
1886
|
-
const customComponents = useCustomComponents(
|
|
1907
|
+
const customComponents = useCustomComponents({
|
|
1908
|
+
componentsProps: components,
|
|
1909
|
+
disabled: Boolean(disabled),
|
|
1910
|
+
readOnly: Boolean(props.readOnly),
|
|
1911
|
+
refMenuIsEnabled,
|
|
1912
|
+
dataTestId,
|
|
1913
|
+
maxSelectedDisplayCount,
|
|
1914
|
+
dropdownIcon,
|
|
1915
|
+
prefix,
|
|
1916
|
+
hasError,
|
|
1917
|
+
});
|
|
1887
1918
|
const menuPlacement = "auto";
|
|
1888
1919
|
const openMenuHandler = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1889
|
-
onMenuOpen
|
|
1920
|
+
onMenuOpen === null || onMenuOpen === void 0 ? void 0 : onMenuOpen();
|
|
1890
1921
|
if (refMenuIsEnabled.current) {
|
|
1891
1922
|
setMenuIsOpen(true);
|
|
1892
1923
|
}
|
|
@@ -1925,10 +1956,9 @@ const useSelect = (_a) => {
|
|
|
1925
1956
|
* @returns {JSX.Element} CreatableSelect component
|
|
1926
1957
|
*/
|
|
1927
1958
|
const CreatableSelect = (props) => {
|
|
1928
|
-
const {
|
|
1929
|
-
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;
|
|
1959
|
+
const { id, dataTestId = "creatableSelect", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, value, options, onChange, isLoading, classNamePrefix = "creatableSelect", onMenuScrollToBottom, filterOption, onInputChange, isSearchable, isClearable = false, readOnly, openMenuOnClick = !disabled, openMenuOnFocus = !disabled, allowCreateWhileLoading, onCreateOption, } = props;
|
|
1930
1960
|
const { refContainer, refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler, orderedOptions, } = useSelect(props);
|
|
1931
|
-
const
|
|
1961
|
+
const reactCreatableSelectProps = useMemo(() => ({
|
|
1932
1962
|
value,
|
|
1933
1963
|
menuPlacement,
|
|
1934
1964
|
maxMenuHeight,
|
|
@@ -1956,11 +1986,35 @@ const CreatableSelect = (props) => {
|
|
|
1956
1986
|
onInputChange,
|
|
1957
1987
|
allowCreateWhileLoading,
|
|
1958
1988
|
onCreateOption,
|
|
1959
|
-
isDisabled: disabled
|
|
1989
|
+
isDisabled: Boolean(disabled),
|
|
1990
|
+
}), [
|
|
1991
|
+
allowCreateWhileLoading,
|
|
1992
|
+
classNamePrefix,
|
|
1993
|
+
customComponents,
|
|
1994
|
+
customStyles,
|
|
1995
|
+
dataTestId,
|
|
1996
|
+
disabled,
|
|
1997
|
+
id,
|
|
1998
|
+
isClearable,
|
|
1999
|
+
isLoading,
|
|
2000
|
+
isMulti,
|
|
2001
|
+
isSearchable,
|
|
2002
|
+
label,
|
|
2003
|
+
maxMenuHeight,
|
|
2004
|
+
menuIsOpen,
|
|
2005
|
+
menuPlacement,
|
|
2006
|
+
onChange,
|
|
2007
|
+
onCreateOption,
|
|
2008
|
+
onInputChange,
|
|
2009
|
+
onMenuScrollToBottom,
|
|
2010
|
+
openMenuOnClick,
|
|
2011
|
+
openMenuOnFocus,
|
|
2012
|
+
props.menuPortalTarget,
|
|
1960
2013
|
readOnly,
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
2014
|
+
value,
|
|
2015
|
+
]);
|
|
2016
|
+
const renderAsDisabled = Boolean(props.disabled) || props.readOnly;
|
|
2017
|
+
return (jsxs("div", { className: cvaSelect({ invalid: hasError, disabled: renderAsDisabled, className: props.className }), "data-testid": dataTestId, ref: refContainer, children: [prefix !== undefined ? (jsx("div", { className: cvaSelectPrefixSuffix({ kind: "prefix" }), "data-testid": dataTestId ? `${dataTestId}-prefix` : null, ref: refPrefix, children: prefix })) : null, async ? (jsx(ReactAsyncCreatableSelect, Object.assign({}, props, reactCreatableSelectProps, async, { onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, placeholder: renderAsDisabled ? null : props.placeholder }))) : (jsx(ReactCreatableSelect, Object.assign({}, props, reactCreatableSelectProps, { hideSelectedOptions: false, isMulti: isMulti, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, options: filterOption ? orderedOptions : options, placeholder: renderAsDisabled ? null : props.placeholder }))), typeof props.disabled === "object" ? (jsx("div", { className: cvaSelectPrefixSuffix({ kind: "suffix" }), "data-testid": dataTestId ? `${dataTestId}-locked` : null, children: jsx(DisabledForReasonsTip, Object.assign({}, props.disabled)) })) : null] }));
|
|
1964
2018
|
};
|
|
1965
2019
|
CreatableSelect.displayName = "CreatableSelect";
|
|
1966
2020
|
|
|
@@ -1971,10 +2025,9 @@ CreatableSelect.displayName = "CreatableSelect";
|
|
|
1971
2025
|
* @returns {JSX.Element} Select component
|
|
1972
2026
|
*/
|
|
1973
2027
|
const Select = (props) => {
|
|
1974
|
-
const {
|
|
1975
|
-
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;
|
|
2028
|
+
const { id, dataTestId = "select", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, menuPosition = "absolute", value, options, onChange, isLoading, classNamePrefix = "select", onMenuScrollToBottom, filterOption, onInputChange, isSearchable, isClearable = false, readOnly, openMenuOnClick = !disabled, openMenuOnFocus = !disabled, hideSelectedOptions = false, } = props;
|
|
1976
2029
|
const { refContainer, refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler, orderedOptions, } = useSelect(props);
|
|
1977
|
-
const
|
|
2030
|
+
const reactSelectProps = useMemo(() => ({
|
|
1978
2031
|
value,
|
|
1979
2032
|
menuPlacement,
|
|
1980
2033
|
maxMenuHeight,
|
|
@@ -2001,11 +2054,34 @@ const Select = (props) => {
|
|
|
2001
2054
|
onMenuScrollToBottom,
|
|
2002
2055
|
onInputChange,
|
|
2003
2056
|
hideSelectedOptions,
|
|
2004
|
-
isDisabled: disabled
|
|
2057
|
+
isDisabled: Boolean(disabled),
|
|
2058
|
+
}), [
|
|
2059
|
+
classNamePrefix,
|
|
2060
|
+
customComponents,
|
|
2061
|
+
customStyles,
|
|
2062
|
+
dataTestId,
|
|
2063
|
+
disabled,
|
|
2064
|
+
hideSelectedOptions,
|
|
2065
|
+
id,
|
|
2066
|
+
isClearable,
|
|
2067
|
+
isLoading,
|
|
2068
|
+
isMulti,
|
|
2069
|
+
isSearchable,
|
|
2070
|
+
label,
|
|
2071
|
+
maxMenuHeight,
|
|
2072
|
+
menuIsOpen,
|
|
2073
|
+
menuPlacement,
|
|
2074
|
+
onChange,
|
|
2075
|
+
onInputChange,
|
|
2076
|
+
onMenuScrollToBottom,
|
|
2077
|
+
openMenuOnClick,
|
|
2078
|
+
openMenuOnFocus,
|
|
2079
|
+
props.menuPortalTarget,
|
|
2005
2080
|
readOnly,
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2081
|
+
value,
|
|
2082
|
+
]);
|
|
2083
|
+
const renderAsDisabled = Boolean(props.disabled) || props.readOnly;
|
|
2084
|
+
return (jsxs("div", { className: cvaSelect({ invalid: hasError, disabled: renderAsDisabled, className: props.className }), "data-testid": dataTestId, ref: refContainer, children: [prefix !== undefined ? (jsx("div", { className: cvaSelectPrefixSuffix({ kind: "prefix" }), "data-testid": dataTestId ? `${dataTestId}-prefix` : null, ref: refPrefix, children: prefix })) : null, async ? (jsx(ReactAsyncSelect, Object.assign({}, props, reactSelectProps, async, { menuPosition: menuPosition, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, placeholder: renderAsDisabled ? null : props.placeholder }))) : (jsx(ReactSelect, Object.assign({}, props, reactSelectProps, { isMulti: isMulti, menuPosition: menuPosition, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, options: filterOption ? orderedOptions : options, placeholder: renderAsDisabled ? null : props.placeholder }))), typeof props.disabled === "object" ? (jsx("div", { className: cvaSelectPrefixSuffix({ kind: "suffix" }), "data-testid": dataTestId ? `${dataTestId}-locked` : null, children: jsx(DisabledForReasonsTip, Object.assign({}, props.disabled)) })) : null] }));
|
|
2009
2085
|
};
|
|
2010
2086
|
Select.displayName = "Select";
|
|
2011
2087
|
|
|
@@ -2048,10 +2124,11 @@ const FormFieldSelectAdapter = forwardRef((_a, ref) => {
|
|
|
2048
2124
|
helpText: (renderAsInvalid && errorMessage) || helpText,
|
|
2049
2125
|
helpAddon,
|
|
2050
2126
|
tip,
|
|
2051
|
-
label,
|
|
2052
|
-
disabled, children: [jsx("select", { onChange, ref: innerRef, name, value: innerValue, hidden: true, children: optionsWithCurrentSelectionBackupOption.map(option => {
|
|
2127
|
+
label, children: [jsx("select", { onChange, ref: innerRef, name, value: innerValue, hidden: true, disabled: Boolean(disabled), children: optionsWithCurrentSelectionBackupOption.map(option => {
|
|
2053
2128
|
return (jsx("option", { value: option.value, children: option.label }, option.value));
|
|
2054
|
-
}) }), children(Object.assign(Object.assign({}, rest), { id,
|
|
2129
|
+
}) }), children(Object.assign(Object.assign({}, rest), { id,
|
|
2130
|
+
disabled,
|
|
2131
|
+
onBlur, options: optionsWithCurrentSelectionBackupOption, onChange: e => {
|
|
2055
2132
|
// If theres no value, set the inner value to an empty string
|
|
2056
2133
|
// A native select can not have a null value
|
|
2057
2134
|
// So even if react-select sends a null value, we need to convert it to an empty string
|
|
@@ -2192,10 +2269,10 @@ TextField.displayName = "TextField";
|
|
|
2192
2269
|
* @returns {JSX.Element} TimeRangeField component
|
|
2193
2270
|
*/
|
|
2194
2271
|
const TimeRangeField = (_a) => {
|
|
2195
|
-
var { className, dataTestId, onChange, isInvalid, errorMessage, label, tip,
|
|
2272
|
+
var { className, dataTestId, onChange, isInvalid, errorMessage, label, tip, children, helpText, id } = _a, rest = __rest(_a, ["className", "dataTestId", "onChange", "isInvalid", "errorMessage", "label", "tip", "children", "helpText", "id"]);
|
|
2196
2273
|
const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
|
|
2197
2274
|
const htmlFor = id ? id : "timeRangeField-" + v4();
|
|
2198
|
-
return (jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined,
|
|
2275
|
+
return (jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, helpText: (renderAsInvalid && errorMessage) || helpText, htmlFor: htmlFor, isInvalid: renderAsInvalid, label: label, tip: tip, children: jsx(TimeRange, Object.assign({ className: className, dataTestId: dataTestId, isInvalid: renderAsInvalid, onChange: onChange }, rest, { children: children })) }));
|
|
2199
2276
|
};
|
|
2200
2277
|
|
|
2201
2278
|
const cvaToggleWrapper = cvaMerge(["flex", "gap-2", "items-center"]);
|
|
@@ -2349,7 +2426,7 @@ const UrlField = forwardRef((_a, ref) => {
|
|
|
2349
2426
|
return typeof inputValue === "string";
|
|
2350
2427
|
}
|
|
2351
2428
|
const renderAsInvalid = !!errorMessage || (value && isString(value) && !validateUrlAddress(value)) || isInvalid;
|
|
2352
|
-
return (jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined,
|
|
2429
|
+
return (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: jsx(UrlInput, Object.assign({ "aria-labelledby": htmlForId + "-label", id: htmlForId, isInvalid: renderAsInvalid, ref: ref, value: value || defaultValue }, rest, { className: className, dataTestId: dataTestId })) }));
|
|
2353
2430
|
});
|
|
2354
2431
|
UrlField.displayName = "UrlField";
|
|
2355
2432
|
|
|
@@ -2457,4 +2534,4 @@ const useZodValidators = () => {
|
|
|
2457
2534
|
*/
|
|
2458
2535
|
setupLibraryTranslations();
|
|
2459
2536
|
|
|
2460
|
-
export { ActionButton, BaseInput, Checkbox, CheckboxField, ColorField, CreatableSelect, CreatableSelectField, DateField, DateInput, DropZone, EMAIL_REGEX, EmailField, EmailInput, FormFieldSelectAdapter, FormGroup, Label, MultiSelectMenuItem, NumberField, NumberInput, OptionCard, PasswordField, PasswordInput, PhoneField, PhoneFieldWithController, PhoneInput, RadioGroup, RadioItem, Schedule, ScheduleVariant, Search, Select, SelectField, SingleSelectMenuItem, TextArea, TextAreaField, TextField, TextInput, TimeRange, TimeRangeField, Toggle, UploadField, UploadInput, UrlField, UrlInput, checkIfPhoneNumberHasPlus, countryCodeToFlagEmoji, cvaActionButton, cvaActionContainer, cvaInput, cvaInputAction, cvaInputAddon, cvaInputAddonAfter, cvaInputAddonBefore, cvaInputBase, cvaInputBaseDisabled, cvaInputBaseInvalid, cvaInputField, cvaInputPrefix, cvaInputSuffix, cvaSelect, cvaSelectControl, cvaSelectCounter, cvaSelectDynamicTagContainer, cvaSelectIcon, cvaSelectMenu, cvaSelectMenuList,
|
|
2537
|
+
export { ActionButton, BaseInput, Checkbox, CheckboxField, ColorField, CreatableSelect, CreatableSelectField, DateField, DateInput, DropZone, EMAIL_REGEX, EmailField, EmailInput, FormFieldSelectAdapter, FormGroup, Label, MultiSelectMenuItem, NumberField, NumberInput, OptionCard, PasswordField, PasswordInput, PhoneField, PhoneFieldWithController, PhoneInput, RadioGroup, RadioItem, Schedule, ScheduleVariant, Search, Select, SelectField, SingleSelectMenuItem, TextArea, TextAreaField, TextField, TextInput, TimeRange, TimeRangeField, Toggle, UploadField, UploadInput, UrlField, UrlInput, checkIfPhoneNumberHasPlus, countryCodeToFlagEmoji, cvaActionButton, cvaActionContainer, cvaInput, cvaInputAction, cvaInputAddon, cvaInputAddonAfter, cvaInputAddonBefore, cvaInputBase, cvaInputBaseDisabled, cvaInputBaseInvalid, cvaInputField, cvaInputPrefix, cvaInputSuffix, cvaSelect, cvaSelectControl, cvaSelectCounter, cvaSelectDynamicTagContainer, cvaSelectIcon, cvaSelectMenu, cvaSelectMenuList, cvaSelectPrefixSuffix, cvaSelectXIcon, getCountryAbbreviation, getOrderedOptions, getPhoneNumberWithPlus, isInvalidCountryCode, isInvalidPhoneNumber, isMultiValue, isValidHEXColor, parseSchedule, serializeSchedule, useCustomComponents, useGetPhoneValidationRules, usePhoneInput, useZodValidators, validateEmailAddress, validatePhoneNumber, weekDay };
|
package/package.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { CommonProps } from "@trackunit/react-components";
|
|
2
|
+
import { MappedOmit } from "@trackunit/shared-utils";
|
|
2
3
|
import * as React from "react";
|
|
3
|
-
|
|
4
|
+
import { DisabledForReasons } from "./DisabledForReasonsTip";
|
|
5
|
+
type FilteredInputProps = MappedOmit<React.InputHTMLAttributes<HTMLInputElement>, "prefix" | "disabled">;
|
|
4
6
|
type FieldSize = "small" | "medium";
|
|
5
7
|
export interface BaseInputProps extends FilteredInputProps, CommonProps {
|
|
6
8
|
/**
|
|
@@ -65,6 +67,7 @@ export interface BaseInputProps extends FilteredInputProps, CommonProps {
|
|
|
65
67
|
* If true the input is readonly.
|
|
66
68
|
*/
|
|
67
69
|
readonly?: boolean;
|
|
70
|
+
disabled?: boolean | DisabledForReasons;
|
|
68
71
|
}
|
|
69
72
|
/**
|
|
70
73
|
* A base input component that can be used for text inputs, password inputs, etc.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
type DisabledKind = "locked" | "disabled";
|
|
3
|
+
export type DisabledForReasons = {
|
|
4
|
+
kind: DisabledKind;
|
|
5
|
+
reasons?: string | string[];
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Icon with explanation tooltip for why an input is locked or disabled.
|
|
9
|
+
* If locked, a permission lacks but the input **can** sometimes be edited.
|
|
10
|
+
* If disabled, the input **cannot** be edited and is only ever for displaying information.
|
|
11
|
+
*
|
|
12
|
+
* @param {DisabledForReasons} props - The reasons for the disabled state.
|
|
13
|
+
* @param {DisabledKind} kind - The kind of disabled state. If locked, the input can sometimes be edited. If disabled, the input cannot be edited.
|
|
14
|
+
*/
|
|
15
|
+
export declare const DisabledForReasonsTip: ({ reasons, kind }: DisabledForReasons) => JSX.Element;
|
|
16
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommonProps
|
|
1
|
+
import { CommonProps } from "@trackunit/react-components";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
export interface FormGroupProps extends CommonProps {
|
|
4
4
|
/**
|
|
@@ -23,15 +23,7 @@ export interface FormGroupProps extends CommonProps {
|
|
|
23
23
|
* If true the input is rendered in its invalid state.
|
|
24
24
|
*/
|
|
25
25
|
isInvalid?: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* If true interactions are disabled
|
|
28
|
-
*/
|
|
29
|
-
disabled?: boolean;
|
|
30
26
|
children?: React.ReactNode;
|
|
31
|
-
/**
|
|
32
|
-
* The props for setting the icon on tip.
|
|
33
|
-
*/
|
|
34
|
-
tipIconProps?: IconProps;
|
|
35
27
|
name?: string;
|
|
36
28
|
/**
|
|
37
29
|
* If true the input is required with an asterisk prepended to the label.
|
|
@@ -45,4 +37,4 @@ export interface FormGroupProps extends CommonProps {
|
|
|
45
37
|
* @param {FormGroupProps} props - The props for the FormGroup component
|
|
46
38
|
* @returns {JSX.Element} FormGroup component
|
|
47
39
|
*/
|
|
48
|
-
export declare const FormGroup: ({ isInvalid, helpText, helpAddon, tip, className, dataTestId, label, htmlFor, children,
|
|
40
|
+
export declare const FormGroup: ({ isInvalid, helpText, helpAddon, tip, className, dataTestId, label, htmlFor, children, required, }: FormGroupProps) => JSX.Element;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export declare const cvaFormGroup: (props?: (
|
|
2
|
-
disabled?: boolean | null | undefined;
|
|
3
|
-
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
1
|
+
export declare const cvaFormGroup: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
|
|
4
2
|
export declare const cvaFormGroupContainerBefore: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
|
|
5
3
|
export declare const cvaFormGroupContainerAfter: (props?: ({
|
|
6
4
|
invalid?: boolean | null | undefined;
|
|
@@ -17,6 +17,6 @@ export type CreatableSelectProps = {
|
|
|
17
17
|
* @returns {JSX.Element} CreatableSelect component
|
|
18
18
|
*/
|
|
19
19
|
export declare const CreatableSelect: {
|
|
20
|
-
<
|
|
20
|
+
<Option, IsAsync extends boolean = false, IsMulti extends boolean = false, Group extends GroupBase<Option> = GroupBase<Option>>(props: SelectProps<Option, IsAsync, IsMulti, Group> & CreatableSelectProps): JSX.Element;
|
|
21
21
|
displayName: string;
|
|
22
22
|
};
|
|
@@ -13,6 +13,6 @@ export interface SelectOption<TValue extends string> {
|
|
|
13
13
|
* @returns {JSX.Element} Select component
|
|
14
14
|
*/
|
|
15
15
|
export declare const Select: {
|
|
16
|
-
<
|
|
16
|
+
<Option, IsAsync extends boolean = false, IsMulti extends boolean = false, Group extends GroupBase<Option> = GroupBase<Option>>(props: SelectProps<Option, IsAsync, IsMulti, Group>): JSX.Element;
|
|
17
17
|
displayName: string;
|
|
18
18
|
};
|
|
@@ -8,7 +8,9 @@ export declare const cvaSelectControl: (props?: ({
|
|
|
8
8
|
invalid?: boolean | null | undefined;
|
|
9
9
|
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
10
10
|
export declare const cvaSelectIcon: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
|
|
11
|
-
export declare const
|
|
11
|
+
export declare const cvaSelectPrefixSuffix: (props?: ({
|
|
12
|
+
kind?: "prefix" | "suffix" | null | undefined;
|
|
13
|
+
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
12
14
|
export declare const cvaSelectXIcon: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
|
|
13
15
|
export declare const cvaSelectMenuList: (props?: ({
|
|
14
16
|
menuIsOpen?: boolean | null | undefined;
|
|
@@ -13,7 +13,19 @@ import { SelectComponents } from "react-select/dist/declarations/src/components"
|
|
|
13
13
|
* @param {React.MutableRefObject<boolean>} refMenuIsEnabled a flag to block menu from open
|
|
14
14
|
* @param {string} dataTestId a test id
|
|
15
15
|
* @param {number} maxSelectedDisplayCount a number of max display count
|
|
16
|
-
*
|
|
16
|
+
* @param {JSX.Element} dropdownIcon an custom dropdown icon
|
|
17
|
+
* @param {boolean} hasError decide to override hasError variant
|
|
18
|
+
* @param {JSX.Element} prefix a prefix element
|
|
17
19
|
* @returns {Partial<SelectComponents<Option, boolean, GroupBase<Option>>> | undefined} components object to override react-select default components
|
|
18
20
|
*/
|
|
19
|
-
export declare const useCustomComponents: <
|
|
21
|
+
export declare const useCustomComponents: <Option, IsMulti extends boolean = false, Group extends GroupBase<Option> = GroupBase<Option>>({ componentsProps, disabled, readOnly, refMenuIsEnabled, dataTestId, maxSelectedDisplayCount, dropdownIcon, prefix, hasError, }: {
|
|
22
|
+
componentsProps: Partial<SelectComponents<Option, IsMulti, Group>> | undefined;
|
|
23
|
+
disabled: boolean;
|
|
24
|
+
readOnly: boolean;
|
|
25
|
+
refMenuIsEnabled: React.MutableRefObject<boolean>;
|
|
26
|
+
dataTestId: string;
|
|
27
|
+
maxSelectedDisplayCount: number | undefined;
|
|
28
|
+
dropdownIcon?: JSX.Element;
|
|
29
|
+
prefix?: JSX.Element;
|
|
30
|
+
hasError?: boolean;
|
|
31
|
+
}) => Partial<SelectComponents<Option, IsMulti, Group>>;
|
|
@@ -9,6 +9,12 @@ import { GroupBase, StylesConfig } from "react-select";
|
|
|
9
9
|
* @param {StylesConfig<Option, IsMulti, Group> | undefined} styles a optional object to override styles of react-select
|
|
10
10
|
* @returns {StylesConfig<Option, boolean>} styles to override in select
|
|
11
11
|
*/
|
|
12
|
-
export declare const useCustomStyles: <Option, IsMulti extends boolean = false, Group extends GroupBase<Option> = GroupBase<Option>>(refContainer
|
|
12
|
+
export declare const useCustomStyles: <Option, IsMulti extends boolean = false, Group extends GroupBase<Option> = GroupBase<Option>>({ refContainer, refPrefix, maxSelectedDisplayCount, styles, disabled, }: {
|
|
13
|
+
refContainer: React.RefObject<HTMLDivElement>;
|
|
14
|
+
refPrefix: React.RefObject<HTMLDivElement>;
|
|
15
|
+
maxSelectedDisplayCount: number | undefined;
|
|
16
|
+
styles: StylesConfig<Option, IsMulti, Group> | undefined;
|
|
17
|
+
disabled: boolean | undefined;
|
|
18
|
+
}) => {
|
|
13
19
|
customStyles: StylesConfig<Option, IsMulti, Group>;
|
|
14
20
|
};
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { CommonProps } from "@trackunit/react-components";
|
|
2
|
+
import { MappedOmit } from "@trackunit/shared-utils";
|
|
2
3
|
import React from "react";
|
|
3
4
|
import { GroupBase, MenuPlacement, OptionsOrGroups, Props, StylesConfig } from "react-select";
|
|
4
5
|
import { SelectComponents } from "react-select/dist/declarations/src/components";
|
|
6
|
+
import { DisabledForReasons } from "../BaseInput/DisabledForReasonsTip";
|
|
5
7
|
export interface AsyncSelect<Option, Group extends GroupBase<Option> = GroupBase<Option>> {
|
|
6
8
|
loadOptions: (input: string) => void | Promise<OptionsOrGroups<Option, Group>>;
|
|
7
9
|
defaultOptions: OptionsOrGroups<Option, Group> | undefined;
|
|
8
10
|
cacheOptions: boolean;
|
|
9
11
|
}
|
|
10
|
-
export type SelectProps<Option, IsAsync extends boolean, IsMulti extends boolean, GroupType extends GroupBase<Option>> = CommonProps & Props<Option, IsMulti, GroupType> & {
|
|
12
|
+
export type SelectProps<Option, IsAsync extends boolean, IsMulti extends boolean, GroupType extends GroupBase<Option>> = CommonProps & MappedOmit<Props<Option, IsMulti, GroupType>, "isDisabled"> & {
|
|
11
13
|
/**
|
|
12
14
|
* An React element to render before the text in the select.
|
|
13
15
|
* This is typically used to render an icon.
|
|
@@ -27,7 +29,7 @@ export type SelectProps<Option, IsAsync extends boolean, IsMulti extends boolean
|
|
|
27
29
|
*
|
|
28
30
|
* @memberof SelectProps
|
|
29
31
|
*/
|
|
30
|
-
disabled?: boolean;
|
|
32
|
+
disabled?: boolean | DisabledForReasons;
|
|
31
33
|
/**
|
|
32
34
|
* An boolean flag to make the field readonly
|
|
33
35
|
*
|
|
@@ -121,7 +123,7 @@ export type SelectProps<Option, IsAsync extends boolean, IsMulti extends boolean
|
|
|
121
123
|
*/
|
|
122
124
|
hideSelectedOptions?: boolean;
|
|
123
125
|
};
|
|
124
|
-
interface
|
|
126
|
+
interface UseSelectProps<Option, IsMulti extends boolean = false, Group extends GroupBase<Option> = GroupBase<Option>> {
|
|
125
127
|
customStyles: StylesConfig<Option, IsMulti, Group>;
|
|
126
128
|
customComponents: Partial<SelectComponents<Option, IsMulti, Group>>;
|
|
127
129
|
refContainer: React.RefObject<HTMLDivElement>;
|
|
@@ -136,7 +138,7 @@ interface IUseSelect<Option, IsMulti extends boolean = false, Group extends Grou
|
|
|
136
138
|
* A hook used by selects to share the common code
|
|
137
139
|
*
|
|
138
140
|
* @param {SelectProps} props - The props for the Select component
|
|
139
|
-
* @returns {
|
|
141
|
+
* @returns {UseSelectProps} Select component
|
|
140
142
|
*/
|
|
141
|
-
export declare const useSelect: <Option, IsAsync extends boolean = false, IsMulti extends boolean = false, Group extends GroupBase<Option> = GroupBase<Option>>({ id, className, dataTestId, prefix, async, dropdownIcon, maxMenuHeight, label, hasError, disabled, isMulti, components, value, options, onChange, isLoading, classNamePrefix, onMenuOpen, onMenuClose, maxSelectedDisplayCount, isClearable, isSearchable, onMenuScrollToBottom, styles, filterOption, onInputChange, ...props }: SelectProps<Option, IsAsync, IsMulti, Group>) =>
|
|
143
|
+
export declare const useSelect: <Option, IsAsync extends boolean = false, IsMulti extends boolean = false, Group extends GroupBase<Option> = GroupBase<Option>>({ id, className, dataTestId, prefix, async, dropdownIcon, maxMenuHeight, label, hasError, disabled, isMulti, components, value, options, onChange, isLoading, classNamePrefix, onMenuOpen, onMenuClose, maxSelectedDisplayCount, isClearable, isSearchable, onMenuScrollToBottom, styles, filterOption, onInputChange, ...props }: SelectProps<Option, IsAsync, IsMulti, Group>) => UseSelectProps<Option, IsMulti, Group>;
|
|
142
144
|
export {};
|
|
@@ -14,5 +14,5 @@ export interface TimeRangeFieldProps extends TimeRangeProps, FormGroupExposedPro
|
|
|
14
14
|
* @param {TimeRangeFieldProps} props - The props for the TimeRangeField component
|
|
15
15
|
* @returns {JSX.Element} TimeRangeField component
|
|
16
16
|
*/
|
|
17
|
-
export declare const TimeRangeField: ({ className, dataTestId, onChange, isInvalid, errorMessage, label, tip,
|
|
17
|
+
export declare const TimeRangeField: ({ className, dataTestId, onChange, isInvalid, errorMessage, label, tip, children, helpText, id, ...rest }: TimeRangeFieldProps) => JSX.Element;
|
|
18
18
|
export {};
|
package/src/translation.d.ts
CHANGED
|
@@ -15,8 +15,8 @@ export declare const translations: TranslationResource<TranslationKeys>;
|
|
|
15
15
|
/**
|
|
16
16
|
* Local useTranslation for this specific library
|
|
17
17
|
*/
|
|
18
|
-
export declare const useTranslation: () => [TransForLibs<"clearIndicator.icon.tooltip.clearAll" | "dropzone.input.title" | "dropzone.label.default" | "phoneField.error.INVALID_COUNTRY" | "phoneField.error.INVALID_LENGTH" | "phoneField.error.INVALID_NUMBER" | "phoneField.error.NOT_A_NUMBER" | "phoneField.error.REQUIRED" | "phoneField.error.REQUIRED_COUNTRY" | "phoneField.error.TOO_LONG" | "phoneField.error.TOO_SHORT" | "phoneField.error.undefined">, import("i18next").i18n, boolean] & {
|
|
19
|
-
t: TransForLibs<"clearIndicator.icon.tooltip.clearAll" | "dropzone.input.title" | "dropzone.label.default" | "phoneField.error.INVALID_COUNTRY" | "phoneField.error.INVALID_LENGTH" | "phoneField.error.INVALID_NUMBER" | "phoneField.error.NOT_A_NUMBER" | "phoneField.error.REQUIRED" | "phoneField.error.REQUIRED_COUNTRY" | "phoneField.error.TOO_LONG" | "phoneField.error.TOO_SHORT" | "phoneField.error.undefined">;
|
|
18
|
+
export declare const useTranslation: () => [TransForLibs<"clearIndicator.icon.tooltip.clearAll" | "dropzone.input.title" | "dropzone.label.default" | "field.notEditable.tooltip" | "field.required.asterisk.tooltip" | "phoneField.error.INVALID_COUNTRY" | "phoneField.error.INVALID_LENGTH" | "phoneField.error.INVALID_NUMBER" | "phoneField.error.NOT_A_NUMBER" | "phoneField.error.REQUIRED" | "phoneField.error.REQUIRED_COUNTRY" | "phoneField.error.TOO_LONG" | "phoneField.error.TOO_SHORT" | "phoneField.error.undefined">, import("i18next").i18n, boolean] & {
|
|
19
|
+
t: TransForLibs<"clearIndicator.icon.tooltip.clearAll" | "dropzone.input.title" | "dropzone.label.default" | "field.notEditable.tooltip" | "field.required.asterisk.tooltip" | "phoneField.error.INVALID_COUNTRY" | "phoneField.error.INVALID_LENGTH" | "phoneField.error.INVALID_NUMBER" | "phoneField.error.NOT_A_NUMBER" | "phoneField.error.REQUIRED" | "phoneField.error.REQUIRED_COUNTRY" | "phoneField.error.TOO_LONG" | "phoneField.error.TOO_SHORT" | "phoneField.error.undefined">;
|
|
20
20
|
i18n: import("i18next").i18n;
|
|
21
21
|
ready: boolean;
|
|
22
22
|
};
|