@trackunit/react-form-components 0.1.116 → 0.1.117
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 +15 -77
- package/index.esm.js +16 -76
- package/package.json +1 -1
- package/src/components/Select/SelectMenuItem/SelectMenuItem.d.ts +7 -2
- package/src/components/Select/index.d.ts +0 -1
- package/src/components/Select/useCustomComponents.d.ts +2 -1
- package/src/components/Select/useSelect.d.ts +7 -2
- package/src/components/Select/shared.d.ts +0 -14
package/index.cjs.js
CHANGED
|
@@ -1824,64 +1824,14 @@ const cvaSelectDynamicTagContainer = cssClassVarianceUtilities.cvaMerge(["h-full
|
|
|
1824
1824
|
const cvaSelectCounter = cssClassVarianceUtilities.cvaMerge(["overflow-hidden", "whitespace-nowrap"]);
|
|
1825
1825
|
const cvaSelectMenu = cssClassVarianceUtilities.cvaMerge(["relative", "p-1", "grid", "gap-1"]);
|
|
1826
1826
|
|
|
1827
|
-
/**
|
|
1828
|
-
* @param {MultiValue<Option> | SingleValue<Option>} arg option to check type
|
|
1829
|
-
* @returns {arg is MultiValue<Option> } is Multivalue
|
|
1830
|
-
*/
|
|
1831
|
-
function isMultiValue(arg) {
|
|
1832
|
-
return Array.isArray(arg);
|
|
1833
|
-
}
|
|
1834
|
-
function isGroupBase(arg) {
|
|
1835
|
-
// This is apparently needed
|
|
1836
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1837
|
-
return arg.options !== undefined;
|
|
1838
|
-
}
|
|
1839
|
-
const isSelectedOption = (option, selected) => {
|
|
1840
|
-
if (isGroupBase(option)) {
|
|
1841
|
-
return false;
|
|
1842
|
-
}
|
|
1843
|
-
return isMultiValue(selected)
|
|
1844
|
-
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1845
|
-
selected.some(v => v.value === option.value)
|
|
1846
|
-
: // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1847
|
-
option.value === (selected === null || selected === void 0 ? void 0 : selected.value);
|
|
1848
|
-
};
|
|
1849
|
-
const removeSelectedFromGroups = (group, selected) => {
|
|
1850
|
-
if (isGroupBase(group)) {
|
|
1851
|
-
return { ...group, options: group.options.filter(option => !isSelectedOption(option, selected)) };
|
|
1852
|
-
}
|
|
1853
|
-
return group;
|
|
1854
|
-
};
|
|
1855
|
-
/**
|
|
1856
|
-
* @template IsMulti
|
|
1857
|
-
* @template Group
|
|
1858
|
-
* @param {OptionsOrGroups<Option, Group> | undefined} options An array of options to select from
|
|
1859
|
-
* @param {PropsValue<Option> | undefined} value Selected values
|
|
1860
|
-
* @returns {OptionsOrGroups<Option, Group>} An array of ordered options with selected on top
|
|
1861
|
-
*/
|
|
1862
|
-
const getOrderedOptions = (options, value) => {
|
|
1863
|
-
if (value && options) {
|
|
1864
|
-
const orderedValues = isMultiValue(value)
|
|
1865
|
-
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1866
|
-
[...value].sort((a, b) => a.label.localeCompare(b.label))
|
|
1867
|
-
: [value];
|
|
1868
|
-
const selectableOptions = options
|
|
1869
|
-
.filter(option => !isSelectedOption(option, value))
|
|
1870
|
-
.map(option => removeSelectedFromGroups(option, value));
|
|
1871
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1872
|
-
return orderedValues.concat(selectableOptions);
|
|
1873
|
-
}
|
|
1874
|
-
return options || [];
|
|
1875
|
-
};
|
|
1876
|
-
|
|
1877
1827
|
/**
|
|
1878
1828
|
* A single select menu item is a basic wrapper around Menu item designed to be used as a single value render in Select list
|
|
1879
1829
|
*
|
|
1880
1830
|
* @param {SelectMenuItemProps} props - The props for the SingleSelectMenuItem
|
|
1881
1831
|
* @returns {JSX.Element} SingleSelectMenuItem
|
|
1882
1832
|
*/
|
|
1883
|
-
const SingleSelectMenuItem = ({ label, icon, onClick, selected, dataTestId, disabled, }) => {
|
|
1884
|
-
return (jsxRuntime.jsx(reactComponents.MenuItem, { dataTestId: dataTestId, disabled: disabled, label: label, onClick: onClick, prefix: icon, selected: selected, suffix: selected ? jsxRuntime.jsx(reactComponents.Icon, { name: "Check", size: "small" }) : undefined }));
|
|
1833
|
+
const SingleSelectMenuItem = ({ label, icon, onClick, selected, dataTestId, disabled, optionLabelDescription, }) => {
|
|
1834
|
+
return (jsxRuntime.jsx(reactComponents.MenuItem, { dataTestId: dataTestId, disabled: disabled, label: label, onClick: onClick, optionLabelDescription: optionLabelDescription, prefix: icon, selected: selected, suffix: selected ? jsxRuntime.jsx(reactComponents.Icon, { name: "Check", size: "small" }) : undefined }));
|
|
1885
1835
|
};
|
|
1886
1836
|
/**
|
|
1887
1837
|
* A multi select menu item is a basic wrapper around Menu item designed to be used as a multi value render in Select list
|
|
@@ -1889,11 +1839,11 @@ const SingleSelectMenuItem = ({ label, icon, onClick, selected, dataTestId, disa
|
|
|
1889
1839
|
* @param {SelectMenuItemProps} props - The props for the MultiSelectMenuItem
|
|
1890
1840
|
* @returns {JSX.Element} multi select menu item
|
|
1891
1841
|
*/
|
|
1892
|
-
const MultiSelectMenuItem = ({ label, onClick, selected, dataTestId, disabled }) => {
|
|
1842
|
+
const MultiSelectMenuItem = ({ label, onClick, selected, dataTestId, disabled, optionLabelDescription, }) => {
|
|
1893
1843
|
return (jsxRuntime.jsx(reactComponents.MenuItem, { dataTestId: dataTestId, disabled: disabled, label: label, onClick: e => {
|
|
1894
1844
|
e.stopPropagation();
|
|
1895
1845
|
onClick && onClick(e);
|
|
1896
|
-
}, prefix: jsxRuntime.jsx(Checkbox, { checked: selected, disabled: disabled, onChange: () => null, onClick: e => {
|
|
1846
|
+
}, optionLabelDescription: optionLabelDescription, prefix: jsxRuntime.jsx(Checkbox, { checked: selected, disabled: disabled, onChange: () => null, onClick: e => {
|
|
1897
1847
|
e.stopPropagation();
|
|
1898
1848
|
}, readOnly: false }), selected: selected }));
|
|
1899
1849
|
};
|
|
@@ -1992,7 +1942,7 @@ const TagsContainer = ({ items, width = "100%", itemsGap = 5, postFix, disabled
|
|
|
1992
1942
|
* @param {JSX.Element} prefix a prefix element
|
|
1993
1943
|
* @returns {Partial<SelectComponents<Option, boolean, GroupBase<Option>>> | undefined} components object to override react-select default components
|
|
1994
1944
|
*/
|
|
1995
|
-
const useCustomComponents = ({ componentsProps, disabled, readOnly, refMenuIsEnabled, dataTestId, maxSelectedDisplayCount, dropdownIcon, prefix, hasError, }) => {
|
|
1945
|
+
const useCustomComponents = ({ componentsProps, disabled, readOnly, refMenuIsEnabled, dataTestId, maxSelectedDisplayCount, dropdownIcon, prefix, hasError, getOptionLabelDescription, }) => {
|
|
1996
1946
|
const [t] = useTranslation();
|
|
1997
1947
|
// perhaps it should not be wrap in memo (causing some issues with opening and closing on mobiles)
|
|
1998
1948
|
const customComponents = React__namespace.useMemo(() => {
|
|
@@ -2056,7 +2006,7 @@ const useCustomComponents = ({ componentsProps, disabled, readOnly, refMenuIsEna
|
|
|
2056
2006
|
}) }));
|
|
2057
2007
|
},
|
|
2058
2008
|
SingleValue: props => {
|
|
2059
|
-
return (jsxRuntime.jsx(ReactSelect.components.SingleValue, { ...props, className: props.isDisabled ? "text-slate-700" : "", children: jsxRuntime.
|
|
2009
|
+
return (jsxRuntime.jsx(ReactSelect.components.SingleValue, { ...props, className: props.isDisabled ? "text-slate-700" : "", children: jsxRuntime.jsxs("div", { "data-testid": dataTestId + "-singleValue", children: [props.children, getOptionLabelDescription ? (jsxRuntime.jsxs("span", { className: "text-secondary-400 ml-1", children: ["(", getOptionLabelDescription(props.data), ")"] })) : null] }) }));
|
|
2060
2010
|
},
|
|
2061
2011
|
Menu: props => {
|
|
2062
2012
|
return (jsxRuntime.jsx(ReactSelect.components.Menu, { ...props, className: cvaSelectMenuList({ menuIsOpen: props.selectProps.menuIsOpen }) }));
|
|
@@ -2086,7 +2036,7 @@ const useCustomComponents = ({ componentsProps, disabled, readOnly, refMenuIsEna
|
|
|
2086
2036
|
...props.innerProps,
|
|
2087
2037
|
role: "option",
|
|
2088
2038
|
onClick: () => { },
|
|
2089
|
-
}, children: props.isMulti ? (jsxRuntime.jsx(MultiSelectMenuItem, { ...componentProps, dataTestId: typeof props.label === "string" ? props.label : undefined, disabled: disabled })) : (jsxRuntime.jsx(SingleSelectMenuItem, { ...componentProps, dataTestId: typeof props.label === "string" ? props.label : undefined, disabled: disabled || props.isDisabled })) }));
|
|
2039
|
+
}, children: props.isMulti ? (jsxRuntime.jsx(MultiSelectMenuItem, { ...componentProps, dataTestId: typeof props.label === "string" ? props.label : undefined, disabled: disabled, optionLabelDescription: getOptionLabelDescription === null || getOptionLabelDescription === void 0 ? void 0 : getOptionLabelDescription(props.data) })) : (jsxRuntime.jsx(SingleSelectMenuItem, { ...componentProps, dataTestId: typeof props.label === "string" ? props.label : undefined, disabled: disabled || props.isDisabled, optionLabelDescription: getOptionLabelDescription === null || getOptionLabelDescription === void 0 ? void 0 : getOptionLabelDescription(props.data) })) }));
|
|
2090
2040
|
},
|
|
2091
2041
|
...componentsProps,
|
|
2092
2042
|
};
|
|
@@ -2203,7 +2153,7 @@ const useCustomStyles = ({ refContainer, refPrefix, maxSelectedDisplayCount, sty
|
|
|
2203
2153
|
* @param {SelectProps} props - The props for the Select component
|
|
2204
2154
|
* @returns {UseSelectProps} Select component
|
|
2205
2155
|
*/
|
|
2206
|
-
const useSelect = ({ 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, ...props }) => {
|
|
2156
|
+
const useSelect = ({ 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, getOptionLabelDescription, ...props }) => {
|
|
2207
2157
|
var _a;
|
|
2208
2158
|
const refContainer = React.useRef(null);
|
|
2209
2159
|
const refPrefix = React.useRef(null);
|
|
@@ -2226,6 +2176,7 @@ const useSelect = ({ id, className, dataTestId = "select", prefix, async, dropdo
|
|
|
2226
2176
|
dropdownIcon,
|
|
2227
2177
|
prefix,
|
|
2228
2178
|
hasError,
|
|
2179
|
+
getOptionLabelDescription,
|
|
2229
2180
|
});
|
|
2230
2181
|
const menuPlacement = "auto";
|
|
2231
2182
|
const openMenuHandler = async () => {
|
|
@@ -2241,16 +2192,6 @@ const useSelect = ({ id, className, dataTestId = "select", prefix, async, dropdo
|
|
|
2241
2192
|
setMenuIsOpen(false);
|
|
2242
2193
|
onMenuClose && onMenuClose();
|
|
2243
2194
|
};
|
|
2244
|
-
const orderedOptions = React.useMemo(() => {
|
|
2245
|
-
return disabled
|
|
2246
|
-
? getOrderedOptions(options, value).map(option => {
|
|
2247
|
-
return {
|
|
2248
|
-
...option,
|
|
2249
|
-
disabled: true,
|
|
2250
|
-
};
|
|
2251
|
-
})
|
|
2252
|
-
: getOrderedOptions(options, value);
|
|
2253
|
-
}, [options, value, disabled]);
|
|
2254
2195
|
return {
|
|
2255
2196
|
refContainer,
|
|
2256
2197
|
refPrefix,
|
|
@@ -2260,7 +2201,6 @@ const useSelect = ({ id, className, dataTestId = "select", prefix, async, dropdo
|
|
|
2260
2201
|
menuPlacement,
|
|
2261
2202
|
openMenuHandler,
|
|
2262
2203
|
closeMenuHandler,
|
|
2263
|
-
orderedOptions,
|
|
2264
2204
|
};
|
|
2265
2205
|
};
|
|
2266
2206
|
|
|
@@ -2271,8 +2211,8 @@ const useSelect = ({ id, className, dataTestId = "select", prefix, async, dropdo
|
|
|
2271
2211
|
* @returns {JSX.Element} CreatableSelect component
|
|
2272
2212
|
*/
|
|
2273
2213
|
const CreatableSelect = (props) => {
|
|
2274
|
-
const { id, dataTestId = "creatableSelect", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, value, options, onChange, isLoading, classNamePrefix = "creatableSelect", onMenuScrollToBottom,
|
|
2275
|
-
const { refContainer, refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler,
|
|
2214
|
+
const { id, dataTestId = "creatableSelect", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, value, options, onChange, isLoading, classNamePrefix = "creatableSelect", onMenuScrollToBottom, onInputChange, isSearchable, isClearable = false, readOnly, openMenuOnClick = !disabled, openMenuOnFocus = !disabled, allowCreateWhileLoading, onCreateOption, } = props;
|
|
2215
|
+
const { refContainer, refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler, } = useSelect(props);
|
|
2276
2216
|
const reactCreatableSelectProps = React.useMemo(() => ({
|
|
2277
2217
|
value,
|
|
2278
2218
|
menuPlacement,
|
|
@@ -2329,7 +2269,7 @@ const CreatableSelect = (props) => {
|
|
|
2329
2269
|
value,
|
|
2330
2270
|
]);
|
|
2331
2271
|
const renderAsDisabled = Boolean(props.disabled) || props.readOnly;
|
|
2332
|
-
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, { ...props, ...reactCreatableSelectProps, ...async, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, placeholder: renderAsDisabled ? null : props.placeholder })) : (jsxRuntime.jsx(ReactCreatableSelect, { ...props, ...reactCreatableSelectProps, hideSelectedOptions: false, isMulti: isMulti, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, options:
|
|
2272
|
+
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, { ...props, ...reactCreatableSelectProps, ...async, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, placeholder: renderAsDisabled ? null : props.placeholder })) : (jsxRuntime.jsx(ReactCreatableSelect, { ...props, ...reactCreatableSelectProps, hideSelectedOptions: false, isMulti: isMulti, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, options: 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, { ...props.disabled }) })) : null] }));
|
|
2333
2273
|
};
|
|
2334
2274
|
CreatableSelect.displayName = "CreatableSelect";
|
|
2335
2275
|
|
|
@@ -2340,8 +2280,8 @@ CreatableSelect.displayName = "CreatableSelect";
|
|
|
2340
2280
|
* @returns {JSX.Element} Select component
|
|
2341
2281
|
*/
|
|
2342
2282
|
const Select = (props) => {
|
|
2343
|
-
const { id, dataTestId = "select", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, menuPosition = "absolute", value, options, onChange, isLoading, classNamePrefix = "select", onMenuScrollToBottom,
|
|
2344
|
-
const { refContainer, refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler,
|
|
2283
|
+
const { id, dataTestId = "select", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, menuPosition = "absolute", value, options, onChange, isLoading, classNamePrefix = "select", onMenuScrollToBottom, onInputChange, isSearchable, isClearable = false, readOnly, openMenuOnClick = !disabled, openMenuOnFocus = !disabled, hideSelectedOptions = false, } = props;
|
|
2284
|
+
const { refContainer, refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler, } = useSelect(props);
|
|
2345
2285
|
const reactSelectProps = React.useMemo(() => ({
|
|
2346
2286
|
value,
|
|
2347
2287
|
menuPlacement,
|
|
@@ -2399,7 +2339,7 @@ const Select = (props) => {
|
|
|
2399
2339
|
value,
|
|
2400
2340
|
]);
|
|
2401
2341
|
const renderAsDisabled = Boolean(props.disabled) || props.readOnly;
|
|
2402
|
-
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, { ...props, ...reactSelectProps, ...async, menuPosition: menuPosition, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, placeholder: renderAsDisabled ? null : props.placeholder })) : (jsxRuntime.jsx(ReactSelect, { ...props, ...reactSelectProps, isMulti: isMulti, menuPosition: menuPosition, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, options:
|
|
2342
|
+
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, { ...props, ...reactSelectProps, ...async, menuPosition: menuPosition, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, placeholder: renderAsDisabled ? null : props.placeholder })) : (jsxRuntime.jsx(ReactSelect, { ...props, ...reactSelectProps, isMulti: isMulti, menuPosition: menuPosition, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, options: 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, { ...props.disabled }) })) : null] }));
|
|
2403
2343
|
};
|
|
2404
2344
|
Select.displayName = "Select";
|
|
2405
2345
|
|
|
@@ -2968,11 +2908,9 @@ exports.cvaSelectMenuList = cvaSelectMenuList;
|
|
|
2968
2908
|
exports.cvaSelectPrefixSuffix = cvaSelectPrefixSuffix;
|
|
2969
2909
|
exports.cvaSelectXIcon = cvaSelectXIcon;
|
|
2970
2910
|
exports.getCountryAbbreviation = getCountryAbbreviation;
|
|
2971
|
-
exports.getOrderedOptions = getOrderedOptions;
|
|
2972
2911
|
exports.getPhoneNumberWithPlus = getPhoneNumberWithPlus;
|
|
2973
2912
|
exports.isInvalidCountryCode = isInvalidCountryCode;
|
|
2974
2913
|
exports.isInvalidPhoneNumber = isInvalidPhoneNumber;
|
|
2975
|
-
exports.isMultiValue = isMultiValue;
|
|
2976
2914
|
exports.isValidHEXColor = isValidHEXColor;
|
|
2977
2915
|
exports.parseSchedule = parseSchedule;
|
|
2978
2916
|
exports.phoneErrorMessage = phoneErrorMessage;
|
package/index.esm.js
CHANGED
|
@@ -1805,64 +1805,14 @@ const cvaSelectDynamicTagContainer = cvaMerge(["h-full", "flex", "gap-1", "items
|
|
|
1805
1805
|
const cvaSelectCounter = cvaMerge(["overflow-hidden", "whitespace-nowrap"]);
|
|
1806
1806
|
const cvaSelectMenu = cvaMerge(["relative", "p-1", "grid", "gap-1"]);
|
|
1807
1807
|
|
|
1808
|
-
/**
|
|
1809
|
-
* @param {MultiValue<Option> | SingleValue<Option>} arg option to check type
|
|
1810
|
-
* @returns {arg is MultiValue<Option> } is Multivalue
|
|
1811
|
-
*/
|
|
1812
|
-
function isMultiValue(arg) {
|
|
1813
|
-
return Array.isArray(arg);
|
|
1814
|
-
}
|
|
1815
|
-
function isGroupBase(arg) {
|
|
1816
|
-
// This is apparently needed
|
|
1817
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1818
|
-
return arg.options !== undefined;
|
|
1819
|
-
}
|
|
1820
|
-
const isSelectedOption = (option, selected) => {
|
|
1821
|
-
if (isGroupBase(option)) {
|
|
1822
|
-
return false;
|
|
1823
|
-
}
|
|
1824
|
-
return isMultiValue(selected)
|
|
1825
|
-
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1826
|
-
selected.some(v => v.value === option.value)
|
|
1827
|
-
: // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1828
|
-
option.value === (selected === null || selected === void 0 ? void 0 : selected.value);
|
|
1829
|
-
};
|
|
1830
|
-
const removeSelectedFromGroups = (group, selected) => {
|
|
1831
|
-
if (isGroupBase(group)) {
|
|
1832
|
-
return { ...group, options: group.options.filter(option => !isSelectedOption(option, selected)) };
|
|
1833
|
-
}
|
|
1834
|
-
return group;
|
|
1835
|
-
};
|
|
1836
|
-
/**
|
|
1837
|
-
* @template IsMulti
|
|
1838
|
-
* @template Group
|
|
1839
|
-
* @param {OptionsOrGroups<Option, Group> | undefined} options An array of options to select from
|
|
1840
|
-
* @param {PropsValue<Option> | undefined} value Selected values
|
|
1841
|
-
* @returns {OptionsOrGroups<Option, Group>} An array of ordered options with selected on top
|
|
1842
|
-
*/
|
|
1843
|
-
const getOrderedOptions = (options, value) => {
|
|
1844
|
-
if (value && options) {
|
|
1845
|
-
const orderedValues = isMultiValue(value)
|
|
1846
|
-
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1847
|
-
[...value].sort((a, b) => a.label.localeCompare(b.label))
|
|
1848
|
-
: [value];
|
|
1849
|
-
const selectableOptions = options
|
|
1850
|
-
.filter(option => !isSelectedOption(option, value))
|
|
1851
|
-
.map(option => removeSelectedFromGroups(option, value));
|
|
1852
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1853
|
-
return orderedValues.concat(selectableOptions);
|
|
1854
|
-
}
|
|
1855
|
-
return options || [];
|
|
1856
|
-
};
|
|
1857
|
-
|
|
1858
1808
|
/**
|
|
1859
1809
|
* A single select menu item is a basic wrapper around Menu item designed to be used as a single value render in Select list
|
|
1860
1810
|
*
|
|
1861
1811
|
* @param {SelectMenuItemProps} props - The props for the SingleSelectMenuItem
|
|
1862
1812
|
* @returns {JSX.Element} SingleSelectMenuItem
|
|
1863
1813
|
*/
|
|
1864
|
-
const SingleSelectMenuItem = ({ label, icon, onClick, selected, dataTestId, disabled, }) => {
|
|
1865
|
-
return (jsx(MenuItem, { dataTestId: dataTestId, disabled: disabled, label: label, onClick: onClick, prefix: icon, selected: selected, suffix: selected ? jsx(Icon, { name: "Check", size: "small" }) : undefined }));
|
|
1814
|
+
const SingleSelectMenuItem = ({ label, icon, onClick, selected, dataTestId, disabled, optionLabelDescription, }) => {
|
|
1815
|
+
return (jsx(MenuItem, { dataTestId: dataTestId, disabled: disabled, label: label, onClick: onClick, optionLabelDescription: optionLabelDescription, prefix: icon, selected: selected, suffix: selected ? jsx(Icon, { name: "Check", size: "small" }) : undefined }));
|
|
1866
1816
|
};
|
|
1867
1817
|
/**
|
|
1868
1818
|
* A multi select menu item is a basic wrapper around Menu item designed to be used as a multi value render in Select list
|
|
@@ -1870,11 +1820,11 @@ const SingleSelectMenuItem = ({ label, icon, onClick, selected, dataTestId, disa
|
|
|
1870
1820
|
* @param {SelectMenuItemProps} props - The props for the MultiSelectMenuItem
|
|
1871
1821
|
* @returns {JSX.Element} multi select menu item
|
|
1872
1822
|
*/
|
|
1873
|
-
const MultiSelectMenuItem = ({ label, onClick, selected, dataTestId, disabled }) => {
|
|
1823
|
+
const MultiSelectMenuItem = ({ label, onClick, selected, dataTestId, disabled, optionLabelDescription, }) => {
|
|
1874
1824
|
return (jsx(MenuItem, { dataTestId: dataTestId, disabled: disabled, label: label, onClick: e => {
|
|
1875
1825
|
e.stopPropagation();
|
|
1876
1826
|
onClick && onClick(e);
|
|
1877
|
-
}, prefix: jsx(Checkbox, { checked: selected, disabled: disabled, onChange: () => null, onClick: e => {
|
|
1827
|
+
}, optionLabelDescription: optionLabelDescription, prefix: jsx(Checkbox, { checked: selected, disabled: disabled, onChange: () => null, onClick: e => {
|
|
1878
1828
|
e.stopPropagation();
|
|
1879
1829
|
}, readOnly: false }), selected: selected }));
|
|
1880
1830
|
};
|
|
@@ -1973,7 +1923,7 @@ const TagsContainer = ({ items, width = "100%", itemsGap = 5, postFix, disabled
|
|
|
1973
1923
|
* @param {JSX.Element} prefix a prefix element
|
|
1974
1924
|
* @returns {Partial<SelectComponents<Option, boolean, GroupBase<Option>>> | undefined} components object to override react-select default components
|
|
1975
1925
|
*/
|
|
1976
|
-
const useCustomComponents = ({ componentsProps, disabled, readOnly, refMenuIsEnabled, dataTestId, maxSelectedDisplayCount, dropdownIcon, prefix, hasError, }) => {
|
|
1926
|
+
const useCustomComponents = ({ componentsProps, disabled, readOnly, refMenuIsEnabled, dataTestId, maxSelectedDisplayCount, dropdownIcon, prefix, hasError, getOptionLabelDescription, }) => {
|
|
1977
1927
|
const [t] = useTranslation();
|
|
1978
1928
|
// perhaps it should not be wrap in memo (causing some issues with opening and closing on mobiles)
|
|
1979
1929
|
const customComponents = React.useMemo(() => {
|
|
@@ -2037,7 +1987,7 @@ const useCustomComponents = ({ componentsProps, disabled, readOnly, refMenuIsEna
|
|
|
2037
1987
|
}) }));
|
|
2038
1988
|
},
|
|
2039
1989
|
SingleValue: props => {
|
|
2040
|
-
return (jsx(components.SingleValue, { ...props, className: props.isDisabled ? "text-slate-700" : "", children:
|
|
1990
|
+
return (jsx(components.SingleValue, { ...props, className: props.isDisabled ? "text-slate-700" : "", children: jsxs("div", { "data-testid": dataTestId + "-singleValue", children: [props.children, getOptionLabelDescription ? (jsxs("span", { className: "text-secondary-400 ml-1", children: ["(", getOptionLabelDescription(props.data), ")"] })) : null] }) }));
|
|
2041
1991
|
},
|
|
2042
1992
|
Menu: props => {
|
|
2043
1993
|
return (jsx(components.Menu, { ...props, className: cvaSelectMenuList({ menuIsOpen: props.selectProps.menuIsOpen }) }));
|
|
@@ -2067,7 +2017,7 @@ const useCustomComponents = ({ componentsProps, disabled, readOnly, refMenuIsEna
|
|
|
2067
2017
|
...props.innerProps,
|
|
2068
2018
|
role: "option",
|
|
2069
2019
|
onClick: () => { },
|
|
2070
|
-
}, children: props.isMulti ? (jsx(MultiSelectMenuItem, { ...componentProps, dataTestId: typeof props.label === "string" ? props.label : undefined, disabled: disabled })) : (jsx(SingleSelectMenuItem, { ...componentProps, dataTestId: typeof props.label === "string" ? props.label : undefined, disabled: disabled || props.isDisabled })) }));
|
|
2020
|
+
}, children: props.isMulti ? (jsx(MultiSelectMenuItem, { ...componentProps, dataTestId: typeof props.label === "string" ? props.label : undefined, disabled: disabled, optionLabelDescription: getOptionLabelDescription === null || getOptionLabelDescription === void 0 ? void 0 : getOptionLabelDescription(props.data) })) : (jsx(SingleSelectMenuItem, { ...componentProps, dataTestId: typeof props.label === "string" ? props.label : undefined, disabled: disabled || props.isDisabled, optionLabelDescription: getOptionLabelDescription === null || getOptionLabelDescription === void 0 ? void 0 : getOptionLabelDescription(props.data) })) }));
|
|
2071
2021
|
},
|
|
2072
2022
|
...componentsProps,
|
|
2073
2023
|
};
|
|
@@ -2184,7 +2134,7 @@ const useCustomStyles = ({ refContainer, refPrefix, maxSelectedDisplayCount, sty
|
|
|
2184
2134
|
* @param {SelectProps} props - The props for the Select component
|
|
2185
2135
|
* @returns {UseSelectProps} Select component
|
|
2186
2136
|
*/
|
|
2187
|
-
const useSelect = ({ 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, ...props }) => {
|
|
2137
|
+
const useSelect = ({ 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, getOptionLabelDescription, ...props }) => {
|
|
2188
2138
|
var _a;
|
|
2189
2139
|
const refContainer = React__default.useRef(null);
|
|
2190
2140
|
const refPrefix = React__default.useRef(null);
|
|
@@ -2207,6 +2157,7 @@ const useSelect = ({ id, className, dataTestId = "select", prefix, async, dropdo
|
|
|
2207
2157
|
dropdownIcon,
|
|
2208
2158
|
prefix,
|
|
2209
2159
|
hasError,
|
|
2160
|
+
getOptionLabelDescription,
|
|
2210
2161
|
});
|
|
2211
2162
|
const menuPlacement = "auto";
|
|
2212
2163
|
const openMenuHandler = async () => {
|
|
@@ -2222,16 +2173,6 @@ const useSelect = ({ id, className, dataTestId = "select", prefix, async, dropdo
|
|
|
2222
2173
|
setMenuIsOpen(false);
|
|
2223
2174
|
onMenuClose && onMenuClose();
|
|
2224
2175
|
};
|
|
2225
|
-
const orderedOptions = React__default.useMemo(() => {
|
|
2226
|
-
return disabled
|
|
2227
|
-
? getOrderedOptions(options, value).map(option => {
|
|
2228
|
-
return {
|
|
2229
|
-
...option,
|
|
2230
|
-
disabled: true,
|
|
2231
|
-
};
|
|
2232
|
-
})
|
|
2233
|
-
: getOrderedOptions(options, value);
|
|
2234
|
-
}, [options, value, disabled]);
|
|
2235
2176
|
return {
|
|
2236
2177
|
refContainer,
|
|
2237
2178
|
refPrefix,
|
|
@@ -2241,7 +2182,6 @@ const useSelect = ({ id, className, dataTestId = "select", prefix, async, dropdo
|
|
|
2241
2182
|
menuPlacement,
|
|
2242
2183
|
openMenuHandler,
|
|
2243
2184
|
closeMenuHandler,
|
|
2244
|
-
orderedOptions,
|
|
2245
2185
|
};
|
|
2246
2186
|
};
|
|
2247
2187
|
|
|
@@ -2252,8 +2192,8 @@ const useSelect = ({ id, className, dataTestId = "select", prefix, async, dropdo
|
|
|
2252
2192
|
* @returns {JSX.Element} CreatableSelect component
|
|
2253
2193
|
*/
|
|
2254
2194
|
const CreatableSelect = (props) => {
|
|
2255
|
-
const { id, dataTestId = "creatableSelect", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, value, options, onChange, isLoading, classNamePrefix = "creatableSelect", onMenuScrollToBottom,
|
|
2256
|
-
const { refContainer, refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler,
|
|
2195
|
+
const { id, dataTestId = "creatableSelect", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, value, options, onChange, isLoading, classNamePrefix = "creatableSelect", onMenuScrollToBottom, onInputChange, isSearchable, isClearable = false, readOnly, openMenuOnClick = !disabled, openMenuOnFocus = !disabled, allowCreateWhileLoading, onCreateOption, } = props;
|
|
2196
|
+
const { refContainer, refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler, } = useSelect(props);
|
|
2257
2197
|
const reactCreatableSelectProps = useMemo(() => ({
|
|
2258
2198
|
value,
|
|
2259
2199
|
menuPlacement,
|
|
@@ -2310,7 +2250,7 @@ const CreatableSelect = (props) => {
|
|
|
2310
2250
|
value,
|
|
2311
2251
|
]);
|
|
2312
2252
|
const renderAsDisabled = Boolean(props.disabled) || props.readOnly;
|
|
2313
|
-
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, { ...props, ...reactCreatableSelectProps, ...async, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, placeholder: renderAsDisabled ? null : props.placeholder })) : (jsx(ReactCreatableSelect, { ...props, ...reactCreatableSelectProps, hideSelectedOptions: false, isMulti: isMulti, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, options:
|
|
2253
|
+
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, { ...props, ...reactCreatableSelectProps, ...async, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, placeholder: renderAsDisabled ? null : props.placeholder })) : (jsx(ReactCreatableSelect, { ...props, ...reactCreatableSelectProps, hideSelectedOptions: false, isMulti: isMulti, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, options: 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, { ...props.disabled }) })) : null] }));
|
|
2314
2254
|
};
|
|
2315
2255
|
CreatableSelect.displayName = "CreatableSelect";
|
|
2316
2256
|
|
|
@@ -2321,8 +2261,8 @@ CreatableSelect.displayName = "CreatableSelect";
|
|
|
2321
2261
|
* @returns {JSX.Element} Select component
|
|
2322
2262
|
*/
|
|
2323
2263
|
const Select = (props) => {
|
|
2324
|
-
const { id, dataTestId = "select", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, menuPosition = "absolute", value, options, onChange, isLoading, classNamePrefix = "select", onMenuScrollToBottom,
|
|
2325
|
-
const { refContainer, refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler,
|
|
2264
|
+
const { id, dataTestId = "select", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, menuPosition = "absolute", value, options, onChange, isLoading, classNamePrefix = "select", onMenuScrollToBottom, onInputChange, isSearchable, isClearable = false, readOnly, openMenuOnClick = !disabled, openMenuOnFocus = !disabled, hideSelectedOptions = false, } = props;
|
|
2265
|
+
const { refContainer, refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler, } = useSelect(props);
|
|
2326
2266
|
const reactSelectProps = useMemo(() => ({
|
|
2327
2267
|
value,
|
|
2328
2268
|
menuPlacement,
|
|
@@ -2380,7 +2320,7 @@ const Select = (props) => {
|
|
|
2380
2320
|
value,
|
|
2381
2321
|
]);
|
|
2382
2322
|
const renderAsDisabled = Boolean(props.disabled) || props.readOnly;
|
|
2383
|
-
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, { ...props, ...reactSelectProps, ...async, menuPosition: menuPosition, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, placeholder: renderAsDisabled ? null : props.placeholder })) : (jsx(ReactSelect, { ...props, ...reactSelectProps, isMulti: isMulti, menuPosition: menuPosition, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, options:
|
|
2323
|
+
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, { ...props, ...reactSelectProps, ...async, menuPosition: menuPosition, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, placeholder: renderAsDisabled ? null : props.placeholder })) : (jsx(ReactSelect, { ...props, ...reactSelectProps, isMulti: isMulti, menuPosition: menuPosition, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, options: 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, { ...props.disabled }) })) : null] }));
|
|
2384
2324
|
};
|
|
2385
2325
|
Select.displayName = "Select";
|
|
2386
2326
|
|
|
@@ -2879,4 +2819,4 @@ const useZodValidators = () => {
|
|
|
2879
2819
|
*/
|
|
2880
2820
|
setupLibraryTranslations();
|
|
2881
2821
|
|
|
2882
|
-
export { ActionButton, BaseInput, Checkbox, CheckboxField, ColorField, CreatableSelect, CreatableSelectField, DateField, DateInput, DropZone, DropZoneDefaultLabel, 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,
|
|
2822
|
+
export { ActionButton, BaseInput, Checkbox, CheckboxField, ColorField, CreatableSelect, CreatableSelectField, DateField, DateInput, DropZone, DropZoneDefaultLabel, 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, getPhoneNumberWithPlus, isInvalidCountryCode, isInvalidPhoneNumber, isValidHEXColor, parseSchedule, phoneErrorMessage, serializeSchedule, useCustomComponents, useGetPhoneValidationRules, usePhoneInput, useZodValidators, validateEmailAddress, validatePhoneNumber, weekDay };
|
package/package.json
CHANGED
|
@@ -19,6 +19,11 @@ interface SelectMenuItemProps extends CommonProps {
|
|
|
19
19
|
* used in disabled select options
|
|
20
20
|
*/
|
|
21
21
|
disabled?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* A value to be displayed after the label value itself
|
|
24
|
+
* Such as a description or a hint for the option
|
|
25
|
+
*/
|
|
26
|
+
optionLabelDescription?: string;
|
|
22
27
|
}
|
|
23
28
|
export interface SingleSelectMenuItemProps extends SelectMenuItemProps {
|
|
24
29
|
/**
|
|
@@ -33,12 +38,12 @@ export interface SingleSelectMenuItemProps extends SelectMenuItemProps {
|
|
|
33
38
|
* @param {SelectMenuItemProps} props - The props for the SingleSelectMenuItem
|
|
34
39
|
* @returns {JSX.Element} SingleSelectMenuItem
|
|
35
40
|
*/
|
|
36
|
-
export declare const SingleSelectMenuItem: ({ label, icon, onClick, selected, dataTestId, disabled, }: SingleSelectMenuItemProps) => import("react/jsx-runtime").JSX.Element;
|
|
41
|
+
export declare const SingleSelectMenuItem: ({ label, icon, onClick, selected, dataTestId, disabled, optionLabelDescription, }: SingleSelectMenuItemProps) => import("react/jsx-runtime").JSX.Element;
|
|
37
42
|
/**
|
|
38
43
|
* A multi select menu item is a basic wrapper around Menu item designed to be used as a multi value render in Select list
|
|
39
44
|
*
|
|
40
45
|
* @param {SelectMenuItemProps} props - The props for the MultiSelectMenuItem
|
|
41
46
|
* @returns {JSX.Element} multi select menu item
|
|
42
47
|
*/
|
|
43
|
-
export declare const MultiSelectMenuItem: ({ label, onClick, selected, dataTestId, disabled }: SelectMenuItemProps) => import("react/jsx-runtime").JSX.Element;
|
|
48
|
+
export declare const MultiSelectMenuItem: ({ label, onClick, selected, dataTestId, disabled, optionLabelDescription, }: SelectMenuItemProps) => import("react/jsx-runtime").JSX.Element;
|
|
44
49
|
export {};
|
|
@@ -18,7 +18,7 @@ import { SelectComponents } from "react-select/dist/declarations/src/components"
|
|
|
18
18
|
* @param {JSX.Element} prefix a prefix element
|
|
19
19
|
* @returns {Partial<SelectComponents<Option, boolean, GroupBase<Option>>> | undefined} components object to override react-select default components
|
|
20
20
|
*/
|
|
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, }: {
|
|
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, getOptionLabelDescription, }: {
|
|
22
22
|
componentsProps: Partial<SelectComponents<Option, IsMulti, Group>> | undefined;
|
|
23
23
|
disabled: boolean;
|
|
24
24
|
readOnly: boolean;
|
|
@@ -28,4 +28,5 @@ export declare const useCustomComponents: <Option, IsMulti extends boolean = fal
|
|
|
28
28
|
dropdownIcon?: JSX.Element;
|
|
29
29
|
prefix?: JSX.Element;
|
|
30
30
|
hasError?: boolean;
|
|
31
|
+
getOptionLabelDescription?: (option: Option) => string;
|
|
31
32
|
}) => Partial<SelectComponents<Option, IsMulti, Group>>;
|
|
@@ -122,6 +122,12 @@ export type SelectProps<Option, IsAsync extends boolean, IsMulti extends boolean
|
|
|
122
122
|
* @memberof SelectProps
|
|
123
123
|
*/
|
|
124
124
|
hideSelectedOptions?: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* This callback returns
|
|
127
|
+
*
|
|
128
|
+
* @memberof SelectProps
|
|
129
|
+
*/
|
|
130
|
+
getOptionLabelDescription?: (option: Option) => string;
|
|
125
131
|
};
|
|
126
132
|
interface UseSelectProps<Option, IsMulti extends boolean = false, Group extends GroupBase<Option> = GroupBase<Option>> {
|
|
127
133
|
customStyles: StylesConfig<Option, IsMulti, Group>;
|
|
@@ -132,7 +138,6 @@ interface UseSelectProps<Option, IsMulti extends boolean = false, Group extends
|
|
|
132
138
|
menuPlacement: MenuPlacement;
|
|
133
139
|
openMenuHandler: () => Promise<void>;
|
|
134
140
|
closeMenuHandler: () => void;
|
|
135
|
-
orderedOptions: OptionsOrGroups<Option, Group>;
|
|
136
141
|
}
|
|
137
142
|
/**
|
|
138
143
|
* A hook used by selects to share the common code
|
|
@@ -140,5 +145,5 @@ interface UseSelectProps<Option, IsMulti extends boolean = false, Group extends
|
|
|
140
145
|
* @param {SelectProps} props - The props for the Select component
|
|
141
146
|
* @returns {UseSelectProps} Select component
|
|
142
147
|
*/
|
|
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>;
|
|
148
|
+
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, getOptionLabelDescription, ...props }: SelectProps<Option, IsAsync, IsMulti, Group>) => UseSelectProps<Option, IsMulti, Group>;
|
|
144
149
|
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { GroupBase, MultiValue, OptionsOrGroups, PropsValue, SingleValue } from "react-select";
|
|
2
|
-
/**
|
|
3
|
-
* @param {MultiValue<Option> | SingleValue<Option>} arg option to check type
|
|
4
|
-
* @returns {arg is MultiValue<Option> } is Multivalue
|
|
5
|
-
*/
|
|
6
|
-
export declare function isMultiValue<TOption>(arg: MultiValue<TOption> | SingleValue<TOption>): arg is MultiValue<TOption>;
|
|
7
|
-
/**
|
|
8
|
-
* @template IsMulti
|
|
9
|
-
* @template Group
|
|
10
|
-
* @param {OptionsOrGroups<Option, Group> | undefined} options An array of options to select from
|
|
11
|
-
* @param {PropsValue<Option> | undefined} value Selected values
|
|
12
|
-
* @returns {OptionsOrGroups<Option, Group>} An array of ordered options with selected on top
|
|
13
|
-
*/
|
|
14
|
-
export declare const getOrderedOptions: <TOption, TGroup extends GroupBase<TOption>>(options: OptionsOrGroups<TOption, TGroup> | undefined, value: PropsValue<TOption> | undefined) => OptionsOrGroups<TOption, TGroup>;
|