@simplybusiness/mobius 5.8.0 → 5.9.0
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/CHANGELOG.md +17 -0
- package/dist/cjs/components/Combobox/Combobox.js +35 -22
- package/dist/cjs/components/Combobox/Combobox.js.map +1 -1
- package/dist/cjs/components/Combobox/Listbox.js +2 -4
- package/dist/cjs/components/Combobox/Listbox.js.map +1 -1
- package/dist/cjs/components/Combobox/fixtures.js +195 -4
- package/dist/cjs/components/Combobox/fixtures.js.map +1 -1
- package/dist/cjs/components/Combobox/useComboboxOptions.js +69 -0
- package/dist/cjs/components/Combobox/useComboboxOptions.js.map +1 -0
- package/dist/cjs/components/VisuallyHidden/VisuallyHidden.js +2 -1
- package/dist/cjs/components/VisuallyHidden/VisuallyHidden.js.map +1 -1
- package/dist/cjs/hooks/index.js +2 -0
- package/dist/cjs/hooks/index.js.map +1 -1
- package/dist/cjs/hooks/useDebouncedValue/index.js +20 -0
- package/dist/cjs/hooks/useDebouncedValue/index.js.map +1 -0
- package/dist/cjs/hooks/useDebouncedValue/useDebouncedValue.js +36 -0
- package/dist/cjs/hooks/useDebouncedValue/useDebouncedValue.js.map +1 -0
- package/dist/cjs/hooks/useOnUnmount/index.js +20 -0
- package/dist/cjs/hooks/useOnUnmount/index.js.map +1 -0
- package/dist/cjs/hooks/useOnUnmount/useOnUnmount.js +27 -0
- package/dist/cjs/hooks/useOnUnmount/useOnUnmount.js.map +1 -0
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/components/Combobox/Combobox.js +37 -24
- package/dist/esm/components/Combobox/Combobox.js.map +1 -1
- package/dist/esm/components/Combobox/Listbox.js +2 -4
- package/dist/esm/components/Combobox/Listbox.js.map +1 -1
- package/dist/esm/components/Combobox/fixtures.js +189 -1
- package/dist/esm/components/Combobox/fixtures.js.map +1 -1
- package/dist/esm/components/Combobox/types.js.map +1 -1
- package/dist/esm/components/Combobox/useComboboxOptions.js +59 -0
- package/dist/esm/components/Combobox/useComboboxOptions.js.map +1 -0
- package/dist/esm/components/VisuallyHidden/VisuallyHidden.js +2 -1
- package/dist/esm/components/VisuallyHidden/VisuallyHidden.js.map +1 -1
- package/dist/esm/hooks/index.js +2 -0
- package/dist/esm/hooks/index.js.map +1 -1
- package/dist/esm/hooks/useDebouncedValue/index.js +3 -0
- package/dist/esm/hooks/useDebouncedValue/index.js.map +1 -0
- package/dist/esm/hooks/useDebouncedValue/useDebouncedValue.js +26 -0
- package/dist/esm/hooks/useDebouncedValue/useDebouncedValue.js.map +1 -0
- package/dist/esm/hooks/useOnUnmount/index.js +3 -0
- package/dist/esm/hooks/useOnUnmount/index.js.map +1 -0
- package/dist/esm/hooks/useOnUnmount/useOnUnmount.js +17 -0
- package/dist/esm/hooks/useOnUnmount/useOnUnmount.js.map +1 -0
- package/dist/types/components/Combobox/Combobox.stories.d.ts +1 -0
- package/dist/types/components/Combobox/Listbox.d.ts +1 -2
- package/dist/types/components/Combobox/fixtures.d.ts +8 -1
- package/dist/types/components/Combobox/types.d.ts +1 -1
- package/dist/types/components/Combobox/useComboboxOptions.d.ts +10 -0
- package/dist/types/components/Combobox/useComboboxOptions.test.d.ts +1 -0
- package/dist/types/components/VisuallyHidden/VisuallyHidden.d.ts +3 -1
- package/dist/types/hooks/index.d.ts +2 -0
- package/dist/types/hooks/useDebouncedValue/index.d.ts +1 -0
- package/dist/types/hooks/useDebouncedValue/useDebouncedValue.d.ts +1 -0
- package/dist/types/hooks/useDebouncedValue/useDebouncedValue.test.d.ts +1 -0
- package/dist/types/hooks/useOnUnmount/index.d.ts +1 -0
- package/dist/types/hooks/useOnUnmount/useOnUnmount.d.ts +1 -0
- package/dist/types/hooks/useOnUnmount/useOnUnmount.test.d.ts +1 -0
- package/package.json +2 -2
- package/src/components/Combobox/Combobox.css +1 -1
- package/src/components/Combobox/Combobox.stories.tsx +26 -2
- package/src/components/Combobox/Combobox.test.tsx +679 -732
- package/src/components/Combobox/Combobox.tsx +44 -22
- package/src/components/Combobox/Listbox.tsx +1 -5
- package/src/components/Combobox/fixtures.tsx +58 -1
- package/src/components/Combobox/loading-dots.svg +27 -0
- package/src/components/Combobox/types.tsx +1 -1
- package/src/components/Combobox/useComboboxOptions.test.ts +423 -0
- package/src/components/Combobox/useComboboxOptions.ts +67 -0
- package/src/components/VisuallyHidden/VisuallyHidden.tsx +10 -2
- package/src/hooks/index.tsx +2 -0
- package/src/hooks/useDebouncedValue/index.tsx +1 -0
- package/src/hooks/useDebouncedValue/useDebouncedValue.test.tsx +62 -0
- package/src/hooks/useDebouncedValue/useDebouncedValue.tsx +25 -0
- package/src/hooks/useOnUnmount/index.tsx +1 -0
- package/src/hooks/useOnUnmount/useOnUnmount.test.tsx +37 -0
- package/src/hooks/useOnUnmount/useOnUnmount.tsx +19 -0
|
@@ -1,36 +1,33 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import classNames from "classnames/dedupe";
|
|
3
|
-
import { forwardRef,
|
|
3
|
+
import { forwardRef, useId, useRef, useState } from "react";
|
|
4
|
+
import { useOnUnmount } from "../../hooks";
|
|
4
5
|
import { TextField } from "../TextField";
|
|
6
|
+
import { VisuallyHidden } from "../VisuallyHidden";
|
|
5
7
|
import { Listbox } from "./Listbox"; // Import Listbox component
|
|
6
8
|
import { useComboboxHighlight } from "./useComboboxHighlight";
|
|
7
|
-
import {
|
|
9
|
+
import { useComboboxOptions } from "./useComboboxOptions";
|
|
10
|
+
import { getOptionValue, isOptionGroup } from "./utils";
|
|
8
11
|
export const Combobox = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
9
|
-
const { defaultValue, options, asyncOptions, onSelected, className, placeholder, icon } = props;
|
|
12
|
+
const { defaultValue, options, asyncOptions, delay, minLength, onSelected, className, placeholder, icon, ...otherProps } = props;
|
|
10
13
|
const fallbackRef = useRef(null);
|
|
11
14
|
const [inputValue, setInputValue] = useState(defaultValue || "");
|
|
12
15
|
const [isOpen, setIsOpen] = useState(false);
|
|
13
|
-
const
|
|
16
|
+
const { filteredOptions, isLoading } = useComboboxOptions({
|
|
17
|
+
options,
|
|
18
|
+
asyncOptions,
|
|
19
|
+
inputValue,
|
|
20
|
+
delay,
|
|
21
|
+
minLength
|
|
22
|
+
});
|
|
14
23
|
const { highlightedIndex, highlightedGroupIndex, highlightNextOption, highlightPreviousOption, highlightFirstOption, highlightLastOption, clearHighlight } = useComboboxHighlight(filteredOptions);
|
|
15
24
|
const inputRef = ref || fallbackRef;
|
|
16
25
|
const listboxId = useId();
|
|
26
|
+
const statusId = useId();
|
|
17
27
|
const blurTimeoutRef = useRef(null);
|
|
18
|
-
|
|
19
|
-
const fetchOptions = async ()=>{
|
|
20
|
-
if (asyncOptions) {
|
|
21
|
-
const result = await asyncOptions(inputValue);
|
|
22
|
-
setFilteredOptions(result);
|
|
23
|
-
} else {
|
|
24
|
-
setFilteredOptions(filterOptions(options, inputValue));
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
fetchOptions();
|
|
28
|
-
}, [
|
|
29
|
-
inputValue,
|
|
30
|
-
options,
|
|
31
|
-
asyncOptions
|
|
32
|
-
]);
|
|
28
|
+
const showListbox = isOpen && filteredOptions.length > 0;
|
|
33
29
|
const handleFocus = ()=>{
|
|
30
|
+
if (filteredOptions.length === 0) return;
|
|
34
31
|
if (blurTimeoutRef.current) {
|
|
35
32
|
clearTimeout(blurTimeoutRef.current);
|
|
36
33
|
blurTimeoutRef.current = null;
|
|
@@ -42,6 +39,11 @@ export const Combobox = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
42
39
|
setIsOpen(false);
|
|
43
40
|
}, 150);
|
|
44
41
|
};
|
|
42
|
+
useOnUnmount(()=>{
|
|
43
|
+
if (blurTimeoutRef.current) {
|
|
44
|
+
clearTimeout(blurTimeoutRef.current);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
45
47
|
const handleInputChange = (e)=>{
|
|
46
48
|
const newValue = e.target.value;
|
|
47
49
|
setInputValue(newValue);
|
|
@@ -53,7 +55,7 @@ export const Combobox = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
53
55
|
if (!value) return;
|
|
54
56
|
setIsOpen(false);
|
|
55
57
|
setInputValue(value);
|
|
56
|
-
onSelected === null || onSelected === void 0 ? void 0 : onSelected(
|
|
58
|
+
onSelected === null || onSelected === void 0 ? void 0 : onSelected(option);
|
|
57
59
|
};
|
|
58
60
|
function getHighlightedOption() {
|
|
59
61
|
if (highlightedIndex === -1) return undefined;
|
|
@@ -100,12 +102,23 @@ export const Combobox = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
100
102
|
}
|
|
101
103
|
};
|
|
102
104
|
const classes = classNames("mobius mobius-combobox", {
|
|
103
|
-
expanded: isOpen
|
|
105
|
+
"mobius-combobox--is-expanded": isOpen,
|
|
106
|
+
"mobius-combobox--is-loading": isLoading
|
|
104
107
|
}, className);
|
|
105
108
|
return /*#__PURE__*/ _jsxs("div", {
|
|
109
|
+
"data-testid": "mobius-combobox__wrapper",
|
|
106
110
|
className: classes,
|
|
107
111
|
children: [
|
|
112
|
+
isLoading && /*#__PURE__*/ _jsx(VisuallyHidden, {
|
|
113
|
+
role: "status",
|
|
114
|
+
"aria-live": "polite",
|
|
115
|
+
id: statusId,
|
|
116
|
+
elementType: "div",
|
|
117
|
+
className: "mobius-combobox__status",
|
|
118
|
+
children: "Loading options"
|
|
119
|
+
}),
|
|
108
120
|
/*#__PURE__*/ _jsx(TextField, {
|
|
121
|
+
...otherProps,
|
|
109
122
|
className: "mobius-combobox__input",
|
|
110
123
|
role: "combobox",
|
|
111
124
|
value: inputValue,
|
|
@@ -115,6 +128,7 @@ export const Combobox = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
115
128
|
onKeyDown: handleKeyDown,
|
|
116
129
|
onChange: handleInputChange,
|
|
117
130
|
autoComplete: "off",
|
|
131
|
+
"aria-describedby": isLoading ? statusId : undefined,
|
|
118
132
|
"aria-autocomplete": "list",
|
|
119
133
|
"aria-haspopup": "listbox",
|
|
120
134
|
"aria-controls": listboxId,
|
|
@@ -123,13 +137,12 @@ export const Combobox = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
123
137
|
prefixInside: icon,
|
|
124
138
|
ref: inputRef
|
|
125
139
|
}),
|
|
126
|
-
|
|
140
|
+
showListbox && /*#__PURE__*/ _jsx(Listbox, {
|
|
127
141
|
id: listboxId,
|
|
128
142
|
options: filteredOptions,
|
|
129
143
|
highlightedIndex: highlightedIndex,
|
|
130
144
|
highlightedGroupIndex: highlightedGroupIndex,
|
|
131
|
-
onOptionSelect: handleOptionSelect
|
|
132
|
-
expanded: isOpen
|
|
145
|
+
onOptionSelect: handleOptionSelect
|
|
133
146
|
})
|
|
134
147
|
]
|
|
135
148
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/Combobox/Combobox.tsx"],"sourcesContent":["import classNames from \"classnames/dedupe\";\nimport { forwardRef,
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/Combobox/Combobox.tsx"],"sourcesContent":["import classNames from \"classnames/dedupe\";\nimport { forwardRef, useId, useRef, useState } from \"react\";\nimport { useOnUnmount } from \"../../hooks\";\nimport type { ForwardedRefComponent } from \"../../types\";\nimport { TextField } from \"../TextField\";\nimport { VisuallyHidden } from \"../VisuallyHidden\";\nimport { Listbox } from \"./Listbox\"; // Import Listbox component\nimport type {\n ComboboxElementType,\n ComboboxOption,\n ComboboxProps,\n ComboboxRef,\n} from \"./types\";\nimport { useComboboxHighlight } from \"./useComboboxHighlight\";\nimport { useComboboxOptions } from \"./useComboboxOptions\";\nimport { getOptionValue, isOptionGroup } from \"./utils\";\n\nexport const Combobox: ForwardedRefComponent<\n ComboboxProps,\n ComboboxElementType\n> = forwardRef((props: ComboboxProps, ref: ComboboxRef) => {\n const {\n defaultValue,\n options,\n asyncOptions,\n delay,\n minLength,\n onSelected,\n className,\n placeholder,\n icon,\n ...otherProps\n } = props;\n\n const fallbackRef = useRef<HTMLInputElement>(null);\n const [inputValue, setInputValue] = useState(defaultValue || \"\");\n const [isOpen, setIsOpen] = useState(false);\n const { filteredOptions, isLoading } = useComboboxOptions({\n options,\n asyncOptions,\n inputValue,\n delay,\n minLength,\n });\n const {\n highlightedIndex,\n highlightedGroupIndex,\n highlightNextOption,\n highlightPreviousOption,\n highlightFirstOption,\n highlightLastOption,\n clearHighlight,\n } = useComboboxHighlight(filteredOptions);\n\n const inputRef = ref || fallbackRef;\n const listboxId = useId();\n const statusId = useId();\n const blurTimeoutRef = useRef<NodeJS.Timeout | null>(null);\n const showListbox = isOpen && filteredOptions.length > 0;\n\n const handleFocus = () => {\n if (filteredOptions.length === 0) return;\n if (blurTimeoutRef.current) {\n clearTimeout(blurTimeoutRef.current);\n blurTimeoutRef.current = null;\n }\n setIsOpen(true);\n };\n\n const handleBlur = () => {\n blurTimeoutRef.current = setTimeout(() => {\n setIsOpen(false);\n }, 150);\n };\n\n useOnUnmount(() => {\n if (blurTimeoutRef.current) {\n clearTimeout(blurTimeoutRef.current);\n }\n });\n\n const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const newValue = e.target.value;\n setInputValue(newValue);\n setIsOpen(true);\n clearHighlight();\n };\n\n const handleOptionSelect = (option: ComboboxOption) => {\n const value = getOptionValue(option);\n if (!value) return;\n setIsOpen(false);\n setInputValue(value);\n onSelected?.(option);\n };\n\n function getHighlightedOption() {\n if (highlightedIndex === -1) return undefined;\n\n if (isOptionGroup(filteredOptions)) {\n const group = filteredOptions[highlightedGroupIndex];\n return group?.options[highlightedIndex];\n }\n\n return filteredOptions[highlightedIndex];\n }\n\n const handleKeyDown = (e: React.KeyboardEvent) => {\n switch (e.key) {\n case \"ArrowDown\":\n e.preventDefault();\n setIsOpen(true);\n highlightNextOption();\n break;\n case \"ArrowUp\":\n e.preventDefault();\n setIsOpen(true);\n highlightPreviousOption();\n break;\n case \"Home\":\n e.preventDefault();\n setIsOpen(true);\n highlightFirstOption();\n break;\n case \"End\":\n e.preventDefault();\n setIsOpen(true);\n highlightLastOption();\n break;\n case \"Enter\":\n e.preventDefault();\n if (isOpen) {\n handleOptionSelect(getHighlightedOption()!);\n }\n break;\n case \"Escape\":\n e.preventDefault();\n setIsOpen(false);\n clearHighlight();\n break;\n default:\n // Do nothing\n }\n };\n\n const classes = classNames(\n \"mobius mobius-combobox\",\n {\n \"mobius-combobox--is-expanded\": isOpen,\n \"mobius-combobox--is-loading\": isLoading,\n },\n className,\n );\n\n return (\n <div data-testid=\"mobius-combobox__wrapper\" className={classes}>\n {isLoading && (\n <VisuallyHidden\n role=\"status\"\n aria-live=\"polite\"\n id={statusId}\n elementType=\"div\"\n className=\"mobius-combobox__status\"\n >\n Loading options\n </VisuallyHidden>\n )}\n <TextField\n {...otherProps}\n className=\"mobius-combobox__input\"\n role=\"combobox\"\n value={inputValue}\n placeholder={placeholder}\n onFocus={handleFocus}\n onBlur={handleBlur}\n onKeyDown={handleKeyDown}\n onChange={handleInputChange}\n autoComplete=\"off\"\n aria-describedby={isLoading ? statusId : undefined}\n aria-autocomplete=\"list\"\n aria-haspopup=\"listbox\"\n aria-controls={listboxId}\n aria-expanded={isOpen}\n aria-activedescendant={\n highlightedIndex === -1\n ? undefined\n : `${listboxId}-option-${highlightedGroupIndex}-${highlightedIndex}`\n }\n prefixInside={icon}\n ref={inputRef}\n />\n {showListbox && (\n <Listbox\n id={listboxId}\n options={filteredOptions}\n highlightedIndex={highlightedIndex}\n highlightedGroupIndex={highlightedGroupIndex}\n onOptionSelect={handleOptionSelect}\n />\n )}\n </div>\n );\n});\n"],"names":["classNames","forwardRef","useId","useRef","useState","useOnUnmount","TextField","VisuallyHidden","Listbox","useComboboxHighlight","useComboboxOptions","getOptionValue","isOptionGroup","Combobox","props","ref","defaultValue","options","asyncOptions","delay","minLength","onSelected","className","placeholder","icon","otherProps","fallbackRef","inputValue","setInputValue","isOpen","setIsOpen","filteredOptions","isLoading","highlightedIndex","highlightedGroupIndex","highlightNextOption","highlightPreviousOption","highlightFirstOption","highlightLastOption","clearHighlight","inputRef","listboxId","statusId","blurTimeoutRef","showListbox","length","handleFocus","current","clearTimeout","handleBlur","setTimeout","handleInputChange","e","newValue","target","value","handleOptionSelect","option","getHighlightedOption","undefined","group","handleKeyDown","key","preventDefault","classes","div","data-testid","role","aria-live","id","elementType","onFocus","onBlur","onKeyDown","onChange","autoComplete","aria-describedby","aria-autocomplete","aria-haspopup","aria-controls","aria-expanded","aria-activedescendant","prefixInside","onOptionSelect"],"mappings":";AAAA,OAAOA,gBAAgB,oBAAoB;AAC3C,SAASC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAC5D,SAASC,YAAY,QAAQ,cAAc;AAE3C,SAASC,SAAS,QAAQ,eAAe;AACzC,SAASC,cAAc,QAAQ,oBAAoB;AACnD,SAASC,OAAO,QAAQ,YAAY,CAAC,2BAA2B;AAOhE,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,kBAAkB,QAAQ,uBAAuB;AAC1D,SAASC,cAAc,EAAEC,aAAa,QAAQ,UAAU;AAExD,OAAO,MAAMC,yBAGTZ,WAAW,CAACa,OAAsBC;IACpC,MAAM,EACJC,YAAY,EACZC,OAAO,EACPC,YAAY,EACZC,KAAK,EACLC,SAAS,EACTC,UAAU,EACVC,SAAS,EACTC,WAAW,EACXC,IAAI,EACJ,GAAGC,YACJ,GAAGX;IAEJ,MAAMY,cAAcvB,OAAyB;IAC7C,MAAM,CAACwB,YAAYC,cAAc,GAAGxB,SAASY,gBAAgB;IAC7D,MAAM,CAACa,QAAQC,UAAU,GAAG1B,SAAS;IACrC,MAAM,EAAE2B,eAAe,EAAEC,SAAS,EAAE,GAAGtB,mBAAmB;QACxDO;QACAC;QACAS;QACAR;QACAC;IACF;IACA,MAAM,EACJa,gBAAgB,EAChBC,qBAAqB,EACrBC,mBAAmB,EACnBC,uBAAuB,EACvBC,oB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AU;gBACVM;gBACA;YACF,KAAK;gBACHgB,EAAEW,cAAc;gBAChBjC,UAAU;gBACVO;gBACA;YACF,KAAK;gBACHe,EAAEW,cAAc;gBAChBjC,UAAU;gBACVQ;gBACA;YACF,KAAK;gBACHc,EAAEW,cAAc;gBAChB,IAAIlC,QAAQ;oBACV2B,mBAAmBE;gBACrB;gBACA;YACF,KAAK;gBACHN,EAAEW,cAAc;gBAChBjC,UAAU;gBACVS;gBACA;YACF;QAEF;IACF;IAEA,MAAMyB,UAAUhE,WACd,0BACA;QACE,gCAAgC6B;QAChC,+BAA+BG;IACjC,GACAV;IAGF,qBACE,MAAC2C;QAAIC,eAAY;QAA2B5C,WAAW0C;;YACpDhC,2BACC,KAACzB;gBACC4D,MAAK;gBACLC,aAAU;gBACVC,IAAI3B;gBACJ4B,aAAY;gBACZhD,WAAU;0BACX;;0BAIH,KAAChB;gBACE,GAAGmB,UAAU;gBACdH,WAAU;gBACV6C,MAAK;gBACLZ,OAAO5B;gBACPJ,aAAaA;gBACbgD,SAASzB;gBACT0B,QAAQvB;gBACRwB,WAAWZ;gBACXa,UAAUvB;gBACVwB,cAAa;gBACbC,oBAAkB5C,YAAYU,WAAWiB;gBACzCkB,qBAAkB;gBAClBC,iBAAc;gBACdC,iBAAetC;gBACfuC,iBAAenD;gBACfoD,yBACEhD,qBAAqB,CAAC,IAClB0B,YACA,GAAGlB,UAAU,QAAQ,EAAEP,sBAAsB,CAAC,EAAED,kBAAkB;gBAExEiD,cAAc1D;gBACdT,KAAKyB;;YAENI,6BACC,KAACpC;gBACC6D,IAAI5B;gBACJxB,SAASc;gBACTE,kBAAkBA;gBAClBC,uBAAuBA;gBACvBiD,gBAAgB3B;;;;AAK1B,GAAG"}
|
|
@@ -2,10 +2,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import classNames from "classnames";
|
|
3
3
|
import { Option } from "./Option";
|
|
4
4
|
import { isOptionGroup } from "./utils";
|
|
5
|
-
export const Listbox = ({ id, options, highlightedIndex, highlightedGroupIndex, onOptionSelect
|
|
6
|
-
const classes = classNames("mobius-combobox__list"
|
|
7
|
-
expanded
|
|
8
|
-
});
|
|
5
|
+
export const Listbox = ({ id, options, highlightedIndex, highlightedGroupIndex, onOptionSelect })=>{
|
|
6
|
+
const classes = classNames("mobius-combobox__list");
|
|
9
7
|
return /*#__PURE__*/ _jsx("div", {
|
|
10
8
|
role: "listbox",
|
|
11
9
|
id: id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/Combobox/Listbox.tsx"],"sourcesContent":["import classNames from \"classnames\";\nimport { Option } from \"./Option\";\nimport type { ComboboxOption, ComboboxOptions } from \"./types\";\nimport { isOptionGroup } from \"./utils\";\n\nexport type ListboxProps = {\n id: string;\n options: ComboboxOptions;\n highlightedIndex: number;\n highlightedGroupIndex: number;\n onOptionSelect: (option: ComboboxOption) => void;\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/Combobox/Listbox.tsx"],"sourcesContent":["import classNames from \"classnames\";\nimport { Option } from \"./Option\";\nimport type { ComboboxOption, ComboboxOptions } from \"./types\";\nimport { isOptionGroup } from \"./utils\";\n\nexport type ListboxProps = {\n id: string;\n options: ComboboxOptions;\n highlightedIndex: number;\n highlightedGroupIndex: number;\n onOptionSelect: (option: ComboboxOption) => void;\n};\n\nexport const Listbox = ({\n id,\n options,\n highlightedIndex,\n highlightedGroupIndex,\n onOptionSelect,\n}: ListboxProps) => {\n const classes = classNames(\"mobius-combobox__list\");\n\n return (\n <div role=\"listbox\" id={id} className={classes}>\n {isOptionGroup(options)\n ? options.map((option, groupIndex) => (\n <ul\n role=\"group\"\n key={option.heading}\n aria-labelledby={`${id}-group-${groupIndex}`}\n className=\"mobius-combobox__group\"\n >\n <li\n role=\"presentation\"\n id={`${id}-group-${groupIndex}`}\n className=\"mobius-combobox__group-label\"\n >\n {option.heading}\n </li>\n {option.options.map((groupOption, index) => (\n <Option\n // eslint-disable-next-line react/no-array-index-key\n key={`${id}-option-${groupIndex}-${index}`}\n option={groupOption}\n index={index}\n groupIndex={groupIndex}\n isHighlighted={\n highlightedIndex === index &&\n highlightedGroupIndex === groupIndex\n }\n onOptionSelect={onOptionSelect}\n id={id}\n />\n ))}\n </ul>\n ))\n : options.map((option, index) => (\n <Option\n // eslint-disable-next-line react/no-array-index-key\n key={index}\n option={option}\n index={index}\n isHighlighted={highlightedIndex === index}\n onOptionSelect={onOptionSelect}\n id={id}\n />\n ))}\n </div>\n );\n};\n"],"names":["classNames","Option","isOptionGroup","Listbox","id","options","highlightedIndex","highlightedGroupIndex","onOptionSelect","classes","div","role","className","map","option","groupIndex","ul","aria-labelledby","li","heading","groupOption","index","isHighlighted"],"mappings":";AAAA,OAAOA,gBAAgB,aAAa;AACpC,SAASC,MAAM,QAAQ,WAAW;AAElC,SAASC,aAAa,QAAQ,UAAU;AAUxC,OAAO,MAAMC,UAAU,CAAC,EACtBC,EAAE,EACFC,OAAO,EACPC,gBAAgB,EAChBC,qBAAqB,EACrBC,cAAc,EACD;IACb,MAAMC,UAAUT,WAAW;IAE3B,qBACE,KAACU;QAAIC,MAAK;QAAUP,IAAIA;QAAIQ,WAAWH;kBACpCP,cAAcG,WACXA,QAAQQ,GAAG,CAAC,CAACC,QAAQC,2BACnB,MAACC;gBACCL,MAAK;gBAELM,mBAAiB,GAAGb,GAAG,OAAO,EAAEW,YAAY;gBAC5CH,WAAU;;kCAEV,KAACM;wBACCP,MAAK;wBACLP,IAAI,GAAGA,GAAG,OAAO,EAAEW,YAAY;wBAC/BH,WAAU;kCAETE,OAAOK,OAAO;;oBAEhBL,OAAOT,OAAO,CAACQ,GAAG,CAAC,CAACO,aAAaC,sBAChC,KAACpB;4BAGCa,QAAQM;4BACRC,OAAOA;4BACPN,YAAYA;4BACZO,eACEhB,qBAAqBe,SACrBd,0BAA0BQ;4BAE5BP,gBAAgBA;4BAChBJ,IAAIA;2BATC,GAAGA,GAAG,QAAQ,EAAEW,WAAW,CAAC,EAAEM,OAAO;;eAdzCP,OAAOK,OAAO,KA4BvBd,QAAQQ,GAAG,CAAC,CAACC,QAAQO,sBACnB,KAACpB;gBAGCa,QAAQA;gBACRO,OAAOA;gBACPC,eAAehB,qBAAqBe;gBACpCb,gBAAgBA;gBAChBJ,IAAIA;eALCiB;;AAUnB,EAAE"}
|
|
@@ -222,7 +222,7 @@ export const FRUITS_OBJECTS = [
|
|
|
222
222
|
value: "watermelon"
|
|
223
223
|
}
|
|
224
224
|
];
|
|
225
|
-
export const
|
|
225
|
+
export const FRUITS_STRING_GROUPS = [
|
|
226
226
|
{
|
|
227
227
|
heading: "A-L",
|
|
228
228
|
options: [
|
|
@@ -278,6 +278,194 @@ export const FRUITS_GROUPS = [
|
|
|
278
278
|
]
|
|
279
279
|
}
|
|
280
280
|
];
|
|
281
|
+
export const FRUITS_OBJECT_GROUPS = [
|
|
282
|
+
{
|
|
283
|
+
heading: "A-L",
|
|
284
|
+
options: [
|
|
285
|
+
{
|
|
286
|
+
label: "Apple",
|
|
287
|
+
value: "apple"
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
label: "Apricot",
|
|
291
|
+
value: "apricot"
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
label: "Avocado",
|
|
295
|
+
value: "avocado"
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
label: "Banana",
|
|
299
|
+
value: "banana"
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
label: "Blackberry",
|
|
303
|
+
value: "blackberry"
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
label: "Blueberry",
|
|
307
|
+
value: "blueberry"
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
label: "Cantaloupe",
|
|
311
|
+
value: "cantaloupe"
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
label: "Cherry",
|
|
315
|
+
value: "cherry"
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
label: "Clementine",
|
|
319
|
+
value: "clementine"
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
label: "Coconut",
|
|
323
|
+
value: "coconut"
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
label: "Cranberry",
|
|
327
|
+
value: "cranberry"
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
label: "Date",
|
|
331
|
+
value: "date"
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
label: "Dragonfruit",
|
|
335
|
+
value: "dragonfruit"
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
label: "Durian",
|
|
339
|
+
value: "durian"
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
label: "Elderberry",
|
|
343
|
+
value: "elderberry"
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
label: "Fig",
|
|
347
|
+
value: "fig"
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
label: "Grape",
|
|
351
|
+
value: "grape"
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
label: "Grapefruit",
|
|
355
|
+
value: "grapefruit"
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
label: "Guava",
|
|
359
|
+
value: "guava"
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
label: "Honeydew",
|
|
363
|
+
value: "honeydew"
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
label: "Jackfruit",
|
|
367
|
+
value: "jackfruit"
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
label: "Kiwi",
|
|
371
|
+
value: "kiwi"
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
label: "Kumquat",
|
|
375
|
+
value: "kumquat"
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
label: "Lemon",
|
|
379
|
+
value: "lemon"
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
label: "Lime",
|
|
383
|
+
value: "lime"
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
label: "Lychee",
|
|
387
|
+
value: "lychee"
|
|
388
|
+
}
|
|
389
|
+
]
|
|
390
|
+
},
|
|
391
|
+
{
|
|
392
|
+
heading: "M-Z",
|
|
393
|
+
options: [
|
|
394
|
+
{
|
|
395
|
+
label: "Mango",
|
|
396
|
+
value: "mango"
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
label: "Mulberry",
|
|
400
|
+
value: "mulberry"
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
label: "Nectarine",
|
|
404
|
+
value: "nectarine"
|
|
405
|
+
},
|
|
406
|
+
{
|
|
407
|
+
label: "Orange",
|
|
408
|
+
value: "orange"
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
label: "Papaya",
|
|
412
|
+
value: "papaya"
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
label: "Passionfruit",
|
|
416
|
+
value: "passionfruit"
|
|
417
|
+
},
|
|
418
|
+
{
|
|
419
|
+
label: "Peach",
|
|
420
|
+
value: "peach"
|
|
421
|
+
},
|
|
422
|
+
{
|
|
423
|
+
label: "Pear",
|
|
424
|
+
value: "pear"
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
label: "Persimmon",
|
|
428
|
+
value: "persimmon"
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
label: "Pineapple",
|
|
432
|
+
value: "pineapple"
|
|
433
|
+
},
|
|
434
|
+
{
|
|
435
|
+
label: "Plum",
|
|
436
|
+
value: "plum"
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
label: "Pomegranate",
|
|
440
|
+
value: "pomegranate"
|
|
441
|
+
},
|
|
442
|
+
{
|
|
443
|
+
label: "Raspberry",
|
|
444
|
+
value: "raspberry"
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
label: "Redcurrant",
|
|
448
|
+
value: "redcurrant"
|
|
449
|
+
},
|
|
450
|
+
{
|
|
451
|
+
label: "Starfruit",
|
|
452
|
+
value: "starfruit"
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
label: "Strawberry",
|
|
456
|
+
value: "strawberry"
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
label: "Tangerine",
|
|
460
|
+
value: "tangerine"
|
|
461
|
+
},
|
|
462
|
+
{
|
|
463
|
+
label: "Watermelon",
|
|
464
|
+
value: "watermelon"
|
|
465
|
+
}
|
|
466
|
+
]
|
|
467
|
+
}
|
|
468
|
+
];
|
|
281
469
|
export const US_STATES = [
|
|
282
470
|
"Alabama",
|
|
283
471
|
"Alaska",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/Combobox/fixtures.tsx"],"sourcesContent":["export const FRUITS = [\n \"Apple\",\n \"Apricot\",\n \"Avocado\",\n \"Banana\",\n \"Blackberry\",\n \"Blueberry\",\n \"Cantaloupe\",\n \"Cherry\",\n \"Clementine\",\n \"Coconut\",\n \"Cranberry\",\n \"Date\",\n \"Dragonfruit\",\n \"Durian\",\n \"Elderberry\",\n \"Fig\",\n \"Grape\",\n \"Grapefruit\",\n \"Guava\",\n \"Honeydew\",\n \"Jackfruit\",\n \"Kiwi\",\n \"Kumquat\",\n \"Lemon\",\n \"Lime\",\n \"Lychee\",\n \"Mango\",\n \"Mulberry\",\n \"Nectarine\",\n \"Orange\",\n \"Papaya\",\n \"Passionfruit\",\n \"Peach\",\n \"Pear\",\n \"Persimmon\",\n \"Pineapple\",\n \"Plum\",\n \"Pomegranate\",\n \"Raspberry\",\n \"Redcurrant\",\n \"Starfruit\",\n \"Strawberry\",\n \"Tangerine\",\n \"Watermelon\",\n];\n\nexport const FRUITS_OBJECTS = [\n { label: \"Apple\", value: \"apple\" },\n { label: \"Apricot\", value: \"apricot\" },\n { label: \"Avocado\", value: \"avocado\" },\n { label: \"Banana\", value: \"banana\" },\n { label: \"Blackberry\", value: \"blackberry\" },\n { label: \"Blueberry\", value: \"blueberry\" },\n { label: \"Cantaloupe\", value: \"cantaloupe\" },\n { label: \"Cherry\", value: \"cherry\" },\n { label: \"Clementine\", value: \"clementine\" },\n { label: \"Coconut\", value: \"coconut\" },\n { label: \"Cranberry\", value: \"cranberry\" },\n { label: \"Date\", value: \"date\" },\n { label: \"Dragonfruit\", value: \"dragonfruit\" },\n { label: \"Durian\", value: \"durian\" },\n { label: \"Elderberry\", value: \"elderberry\" },\n { label: \"Fig\", value: \"fig\" },\n { label: \"Grape\", value: \"grape\" },\n { label: \"Grapefruit\", value: \"grapefruit\" },\n { label: \"Guava\", value: \"guava\" },\n { label: \"Honeydew\", value: \"honeydew\" },\n { label: \"Jackfruit\", value: \"jackfruit\" },\n { label: \"Kiwi\", value: \"kiwi\" },\n { label: \"Kumquat\", value: \"kumquat\" },\n { label: \"Lemon\", value: \"lemon\" },\n { label: \"Lime\", value: \"lime\" },\n { label: \"Lychee\", value: \"lychee\" },\n { label: \"Mango\", value: \"mango\" },\n { label: \"Mulberry\", value: \"mulberry\" },\n { label: \"Nectarine\", value: \"nectarine\" },\n { label: \"Orange\", value: \"orange\" },\n { label: \"Papaya\", value: \"papaya\" },\n { label: \"Passionfruit\", value: \"passionfruit\" },\n { label: \"Peach\", value: \"peach\" },\n { label: \"Pear\", value: \"pear\" },\n { label: \"Persimmon\", value: \"persimmon\" },\n { label: \"Pineapple\", value: \"pineapple\" },\n { label: \"Plum\", value: \"plum\" },\n { label: \"Pomegranate\", value: \"pomegranate\" },\n { label: \"Raspberry\", value: \"raspberry\" },\n { label: \"Redcurrant\", value: \"redcurrant\" },\n { label: \"Starfruit\", value: \"starfruit\" },\n { label: \"Strawberry\", value: \"strawberry\" },\n { label: \"Tangerine\", value: \"tangerine\" },\n { label: \"Watermelon\", value: \"watermelon\" },\n];\n\nexport const FRUITS_GROUPS = [\n {\n heading: \"A-L\",\n options: [\n \"Apple\",\n \"Apricot\",\n \"Avocado\",\n \"Banana\",\n \"Blackberry\",\n \"Blueberry\",\n \"Cantaloupe\",\n \"Cherry\",\n \"Clementine\",\n \"Coconut\",\n \"Cranberry\",\n \"Date\",\n \"Dragonfruit\",\n \"Durian\",\n \"Elderberry\",\n \"Fig\",\n \"Grape\",\n \"Grapefruit\",\n \"Guava\",\n \"Honeydew\",\n \"Jackfruit\",\n \"Kiwi\",\n \"Kumquat\",\n \"Lemon\",\n \"Lime\",\n \"Lychee\",\n ],\n },\n {\n heading: \"M-Z\",\n options: [\n \"Mango\",\n \"Mulberry\",\n \"Nectarine\",\n \"Orange\",\n \"Papaya\",\n \"Passionfruit\",\n \"Peach\",\n \"Pear\",\n \"Persimmon\",\n \"Pineapple\",\n \"Plum\",\n \"Pomegranate\",\n \"Raspberry\",\n \"Redcurrant\",\n \"Starfruit\",\n \"Strawberry\",\n \"Tangerine\",\n \"Watermelon\",\n ],\n },\n];\n\nexport const US_STATES = [\n \"Alabama\",\n \"Alaska\",\n \"Arizona\",\n \"Arkansas\",\n \"California\",\n \"Colorado\",\n \"Connecticut\",\n \"Delaware\",\n \"District Of Columbia\",\n \"Florida\",\n \"Georgia\",\n \"Hawaii\",\n \"Idaho\",\n \"Illinois\",\n \"Indiana\",\n \"Iowa\",\n \"Kansas\",\n \"Kentucky\",\n \"Louisiana\",\n \"Maine\",\n \"Maryland\",\n \"Massachusetts\",\n \"Michigan\",\n \"Minnesota\",\n \"Mississippi\",\n \"Missouri\",\n \"Montana\",\n \"Nebraska\",\n \"Nevada\",\n \"New Hampshire\",\n \"New Jersey\",\n \"New Mexico\",\n \"New York\",\n \"North Carolina\",\n \"North Dakota\",\n \"Ohio\",\n \"Oklahoma\",\n \"Oregon\",\n \"Pennsylvania\",\n \"Rhode Island\",\n \"South Carolina\",\n \"South Dakota\",\n \"Tennessee\",\n \"Texas\",\n \"Utah\",\n \"Vermont\",\n \"Virginia\",\n \"Washington\",\n \"West Virginia\",\n \"Wisconsin\",\n \"Wyoming\",\n];\n"],"names":["FRUITS","FRUITS_OBJECTS","label","value","FRUITS_GROUPS","heading","options","US_STATES"],"mappings":"A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ED,OAAO;QAAUC,OAAO;IAAS;IACnC;QAAED,OAAO;QAASC,OAAO;IAAQ;IACjC;QAAED,OAAO;QAAYC,OAAO;IAAW;IACvC;QAAED,OAAO;QAAaC,OAAO;IAAY;IACzC;QAAED,OAAO;QAAUC,OAAO;IAAS;IACnC;QAAED,OAAO;QAAUC,OAAO;IAAS;IACnC;QAAED,OAAO;QAAgBC,OAAO;IAAe;IAC/C;QAAED,OAAO;QAASC,OAAO;IAAQ;IACjC;QAAED,OAAO;QAAQC,OAAO;IAAO;IAC/B;QAAED,OAAO;QAAaC,OAAO;IAAY;IACzC;QAAED,OAAO;QAAaC,OAAO;IAAY;IACzC;QAAED,OAAO;QAAQC,OAAO;IAAO;IAC/B;QAAED,OAAO;QAAeC,OAAO;IAAc;IAC7C;QAAED,OAAO;QAAaC,OAAO;IAAY;IACzC;QAAED,OAAO;QAAcC,OAAO;IAAa;IAC3C;QAAED,OAAO;QAAaC,OAAO;IAAY;IACzC;QAAED,OAAO;QAAcC,OAAO;IAAa;IAC3C;QAAED,OAAO;QAAaC,OAAO;IAAY;IACzC;QAAED,OAAO;QAAcC,OAAO;IAAa;CAC5C,CAAC;AAEF,OAAO,MAAMC,gBAAgB;IAC3B;QACEC,SAAS;QACTC,SAAS;YACP;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;SACD;IACH;IACA;QACED,SAAS;QACTC,SAAS;YACP;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;SACD;IACH;CACD,CAAC;AAEF,OAAO,MAAMC,YAAY;IACvB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/Combobox/fixtures.tsx"],"sourcesContent":["export const FRUITS = [\n \"Apple\",\n \"Apricot\",\n \"Avocado\",\n \"Banana\",\n \"Blackberry\",\n \"Blueberry\",\n \"Cantaloupe\",\n \"Cherry\",\n \"Clementine\",\n \"Coconut\",\n \"Cranberry\",\n \"Date\",\n \"Dragonfruit\",\n \"Durian\",\n \"Elderberry\",\n \"Fig\",\n \"Grape\",\n \"Grapefruit\",\n \"Guava\",\n \"Honeydew\",\n \"Jackfruit\",\n \"Kiwi\",\n \"Kumquat\",\n \"Lemon\",\n \"Lime\",\n \"Lychee\",\n \"Mango\",\n \"Mulberry\",\n \"Nectarine\",\n \"Orange\",\n \"Papaya\",\n \"Passionfruit\",\n \"Peach\",\n \"Pear\",\n \"Persimmon\",\n \"Pineapple\",\n \"Plum\",\n \"Pomegranate\",\n \"Raspberry\",\n \"Redcurrant\",\n \"Starfruit\",\n \"Strawberry\",\n \"Tangerine\",\n \"Watermelon\",\n];\n\nexport const FRUITS_OBJECTS = [\n { label: \"Apple\", value: \"apple\" },\n { label: \"Apricot\", value: \"apricot\" },\n { label: \"Avocado\", value: \"avocado\" },\n { label: \"Banana\", value: \"banana\" },\n { label: \"Blackberry\", value: \"blackberry\" },\n { label: \"Blueberry\", value: \"blueberry\" },\n { label: \"Cantaloupe\", value: \"cantaloupe\" },\n { label: \"Cherry\", value: \"cherry\" },\n { label: \"Clementine\", value: \"clementine\" },\n { label: \"Coconut\", value: \"coconut\" },\n { label: \"Cranberry\", value: \"cranberry\" },\n { label: \"Date\", value: \"date\" },\n { label: \"Dragonfruit\", value: \"dragonfruit\" },\n { label: \"Durian\", value: \"durian\" },\n { label: \"Elderberry\", value: \"elderberry\" },\n { label: \"Fig\", value: \"fig\" },\n { label: \"Grape\", value: \"grape\" },\n { label: \"Grapefruit\", value: \"grapefruit\" },\n { label: \"Guava\", value: \"guava\" },\n { label: \"Honeydew\", value: \"honeydew\" },\n { label: \"Jackfruit\", value: \"jackfruit\" },\n { label: \"Kiwi\", value: \"kiwi\" },\n { label: \"Kumquat\", value: \"kumquat\" },\n { label: \"Lemon\", value: \"lemon\" },\n { label: \"Lime\", value: \"lime\" },\n { label: \"Lychee\", value: \"lychee\" },\n { label: \"Mango\", value: \"mango\" },\n { label: \"Mulberry\", value: \"mulberry\" },\n { label: \"Nectarine\", value: \"nectarine\" },\n { label: \"Orange\", value: \"orange\" },\n { label: \"Papaya\", value: \"papaya\" },\n { label: \"Passionfruit\", value: \"passionfruit\" },\n { label: \"Peach\", value: \"peach\" },\n { label: \"Pear\", value: \"pear\" },\n { label: \"Persimmon\", value: \"persimmon\" },\n { label: \"Pineapple\", value: \"pineapple\" },\n { label: \"Plum\", value: \"plum\" },\n { label: \"Pomegranate\", value: \"pomegranate\" },\n { label: \"Raspberry\", value: \"raspberry\" },\n { label: \"Redcurrant\", value: \"redcurrant\" },\n { label: \"Starfruit\", value: \"starfruit\" },\n { label: \"Strawberry\", value: \"strawberry\" },\n { label: \"Tangerine\", value: \"tangerine\" },\n { label: \"Watermelon\", value: \"watermelon\" },\n];\n\nexport const FRUITS_STRING_GROUPS = [\n {\n heading: \"A-L\",\n options: [\n \"Apple\",\n \"Apricot\",\n \"Avocado\",\n \"Banana\",\n \"Blackberry\",\n \"Blueberry\",\n \"Cantaloupe\",\n \"Cherry\",\n \"Clementine\",\n \"Coconut\",\n \"Cranberry\",\n \"Date\",\n \"Dragonfruit\",\n \"Durian\",\n \"Elderberry\",\n \"Fig\",\n \"Grape\",\n \"Grapefruit\",\n \"Guava\",\n \"Honeydew\",\n \"Jackfruit\",\n \"Kiwi\",\n \"Kumquat\",\n \"Lemon\",\n \"Lime\",\n \"Lychee\",\n ],\n },\n {\n heading: \"M-Z\",\n options: [\n \"Mango\",\n \"Mulberry\",\n \"Nectarine\",\n \"Orange\",\n \"Papaya\",\n \"Passionfruit\",\n \"Peach\",\n \"Pear\",\n \"Persimmon\",\n \"Pineapple\",\n \"Plum\",\n \"Pomegranate\",\n \"Raspberry\",\n \"Redcurrant\",\n \"Starfruit\",\n \"Strawberry\",\n \"Tangerine\",\n \"Watermelon\",\n ],\n },\n];\n\nexport const FRUITS_OBJECT_GROUPS = [\n {\n heading: \"A-L\",\n options: [\n { label: \"Apple\", value: \"apple\" },\n { label: \"Apricot\", value: \"apricot\" },\n { label: \"Avocado\", value: \"avocado\" },\n { label: \"Banana\", value: \"banana\" },\n { label: \"Blackberry\", value: \"blackberry\" },\n { label: \"Blueberry\", value: \"blueberry\" },\n { label: \"Cantaloupe\", value: \"cantaloupe\" },\n { label: \"Cherry\", value: \"cherry\" },\n { label: \"Clementine\", value: \"clementine\" },\n { label: \"Coconut\", value: \"coconut\" },\n { label: \"Cranberry\", value: \"cranberry\" },\n { label: \"Date\", value: \"date\" },\n { label: \"Dragonfruit\", value: \"dragonfruit\" },\n { label: \"Durian\", value: \"durian\" },\n { label: \"Elderberry\", value: \"elderberry\" },\n { label: \"Fig\", value: \"fig\" },\n { label: \"Grape\", value: \"grape\" },\n { label: \"Grapefruit\", value: \"grapefruit\" },\n { label: \"Guava\", value: \"guava\" },\n { label: \"Honeydew\", value: \"honeydew\" },\n { label: \"Jackfruit\", value: \"jackfruit\" },\n { label: \"Kiwi\", value: \"kiwi\" },\n { label: \"Kumquat\", value: \"kumquat\" },\n { label: \"Lemon\", value: \"lemon\" },\n { label: \"Lime\", value: \"lime\" },\n { label: \"Lychee\", value: \"lychee\" },\n ],\n },\n {\n heading: \"M-Z\",\n options: [\n { label: \"Mango\", value: \"mango\" },\n { label: \"Mulberry\", value: \"mulberry\" },\n { label: \"Nectarine\", value: \"nectarine\" },\n { label: \"Orange\", value: \"orange\" },\n { label: \"Papaya\", value: \"papaya\" },\n { label: \"Passionfruit\", value: \"passionfruit\" },\n { label: \"Peach\", value: \"peach\" },\n { label: \"Pear\", value: \"pear\" },\n { label: \"Persimmon\", value: \"persimmon\" },\n { label: \"Pineapple\", value: \"pineapple\" },\n { label: \"Plum\", value: \"plum\" },\n { label: \"Pomegranate\", value: \"pomegranate\" },\n { label: \"Raspberry\", value: \"raspberry\" },\n { label: \"Redcurrant\", value: \"redcurrant\" },\n { label: \"Starfruit\", value: \"starfruit\" },\n { label: \"Strawberry\", value: \"strawberry\" },\n { label: \"Tangerine\", value: \"tangerine\" },\n { label: \"Watermelon\", value: \"watermelon\" },\n ],\n },\n];\n\nexport const US_STATES = [\n \"Alabama\",\n \"Alaska\",\n \"Arizona\",\n \"Arkansas\",\n \"California\",\n \"Colorado\",\n \"Connecticut\",\n \"Delaware\",\n \"District Of Columbia\",\n \"Florida\",\n \"Georgia\",\n \"Hawaii\",\n \"Idaho\",\n \"Illinois\",\n \"Indiana\",\n \"Iowa\",\n \"Kansas\",\n \"Kentucky\",\n \"Louisiana\",\n \"Maine\",\n \"Maryland\",\n \"Massachusetts\",\n \"Michigan\",\n \"Minnesota\",\n \"Mississippi\",\n \"Missouri\",\n \"Montana\",\n \"Nebraska\",\n \"Nevada\",\n \"New Hampshire\",\n \"New Jersey\",\n \"New Mexico\",\n \"New York\",\n \"North Carolina\",\n \"North Dakota\",\n \"Ohio\",\n \"Oklahoma\",\n \"Oregon\",\n \"Pennsylvania\",\n \"Rhode Island\",\n \"South Carolina\",\n \"South Dakota\",\n \"Tennessee\",\n \"Texas\",\n \"Utah\",\n \"Vermont\",\n \"Virginia\",\n \"Washington\",\n \"West Virginia\",\n \"Wisconsin\",\n \"Wyoming\",\n];\n"],"names":["FRUITS","FRUITS_OBJECTS","label","value","FRUITS_STRING_GROUPS","heading","options","FRUITS_OBJECT_GROUPS","US_STATES"],"mappings":"AAAA,OAAO,MAAMA,SAAS;IACpB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAC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;gBAAED,OAAO;gBAAQC,OAAO;YAAO;YAC/B;gBAAED,OAAO;gBAAeC,OAAO;YAAc;YAC7C;gBAAED,OAAO;gBAAaC,OAAO;YAAY;YACzC;gBAAED,OAAO;gBAAcC,OAAO;YAAa;YAC3C;gBAAED,OAAO;gBAAaC,OAAO;YAAY;YACzC;gBAAED,OAAO;gBAAcC,OAAO;YAAa;YAC3C;gBAAED,OAAO;gBAAaC,OAAO;YAAY;YACzC;gBAAED,OAAO;gBAAcC,OAAO;YAAa;SAC5C;IACH;CACD,CAAC;AAEF,OAAO,MAAMK,YAAY;IACvB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/Combobox/types.tsx"],"sourcesContent":["import type { ReactElement, Ref } from \"react\";\nimport type { TextFieldElementType, TextFieldProps } from \"../TextField\";\n\nexport type ComboboxBaseProps = TextFieldProps & {\n /** An icon to display in TextField (left side) */\n icon?: ReactElement;\n /** The default value of the selected option */\n defaultValue?: string | undefined;\n /** Callback when the selected option changes */\n onSelected?: ((value:
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/Combobox/types.tsx"],"sourcesContent":["import type { ReactElement, Ref } from \"react\";\nimport type { TextFieldElementType, TextFieldProps } from \"../TextField\";\n\nexport type ComboboxBaseProps = TextFieldProps & {\n /** An icon to display in TextField (left side) */\n icon?: ReactElement;\n /** The default value of the selected option */\n defaultValue?: string | undefined;\n /** Callback when the selected option changes */\n onSelected?: ((value: ComboboxOption) => void) | undefined;\n};\n\nexport type ComboboxSyncProps = ComboboxBaseProps & {\n /** The list of options to display in the dropdown */\n options: ComboboxOptions;\n asyncOptions?: never;\n delay?: never;\n minLength?: never;\n};\n\nexport type ComboboxAsyncProps = ComboboxBaseProps & {\n options?: never;\n delay?: number;\n minLength?: number;\n /** A function that returns a list of options to display in the dropdown */\n asyncOptions:\n | ((inputValue: string) => ComboboxOptions)\n | ((\n inputValue: string,\n options?: { signal?: AbortSignal },\n ) => Promise<ComboboxOptions>);\n};\n\nexport type ComboboxProps = ComboboxAsyncProps | ComboboxSyncProps;\n\nexport type ComboboxOption = string | { label: string; value: string };\n\nexport type ComboboxOptionGroup = {\n heading: string;\n options: ComboboxOption[];\n};\n\nexport type ComboboxOptions = ComboboxOption[] | ComboboxOptionGroup[];\n\nexport type ComboboxElementType = TextFieldElementType;\n\nexport type ComboboxRef = Ref<ComboboxElementType>;\n\nexport type ComboboxOptionProps = {\n option: ComboboxOption;\n index: number;\n groupIndex?: number;\n isHighlighted: boolean;\n onOptionSelect: (option: ComboboxOption) => void;\n id: string;\n};\n"],"names":[],"mappings":"AAgDA,WAOE"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { filterOptions } from "./utils";
|
|
3
|
+
import { useDebouncedValue } from "../../hooks";
|
|
4
|
+
export function useComboboxOptions({ options, asyncOptions, delay = 300, minLength = 3, inputValue = "" }) {
|
|
5
|
+
const [filteredOptions, setFilteredOptions] = useState([]);
|
|
6
|
+
const debouncedInputValue = useDebouncedValue(inputValue, // Don't debounce synchronous options
|
|
7
|
+
options ? 0 : delay);
|
|
8
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
9
|
+
const [error, setError] = useState(null);
|
|
10
|
+
useEffect(()=>{
|
|
11
|
+
const controller = new AbortController();
|
|
12
|
+
const { signal } = controller;
|
|
13
|
+
const fetchOptions = async ()=>{
|
|
14
|
+
setIsLoading(true);
|
|
15
|
+
setError(null);
|
|
16
|
+
try {
|
|
17
|
+
if (asyncOptions) {
|
|
18
|
+
if (debouncedInputValue.length < minLength) {
|
|
19
|
+
setFilteredOptions([]);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const result = await asyncOptions(debouncedInputValue, {
|
|
23
|
+
signal
|
|
24
|
+
});
|
|
25
|
+
setFilteredOptions(result);
|
|
26
|
+
} else {
|
|
27
|
+
// @ts-expect-error options will always be set here, fix the types
|
|
28
|
+
setFilteredOptions(filterOptions(options, debouncedInputValue));
|
|
29
|
+
}
|
|
30
|
+
} catch (e) {
|
|
31
|
+
if (e instanceof DOMException && e.name === "AbortError") {
|
|
32
|
+
// Ignore abort errors
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
setError(e);
|
|
36
|
+
} finally{
|
|
37
|
+
setIsLoading(false);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
fetchOptions();
|
|
41
|
+
return ()=>{
|
|
42
|
+
controller.abort();
|
|
43
|
+
};
|
|
44
|
+
}, [
|
|
45
|
+
debouncedInputValue,
|
|
46
|
+
options,
|
|
47
|
+
asyncOptions,
|
|
48
|
+
delay,
|
|
49
|
+
minLength
|
|
50
|
+
]);
|
|
51
|
+
return {
|
|
52
|
+
filteredOptions,
|
|
53
|
+
isLoading,
|
|
54
|
+
error,
|
|
55
|
+
isError: error != null
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=useComboboxOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/Combobox/useComboboxOptions.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\nimport type { ComboboxOptions, ComboboxProps } from \"./types\";\nimport { filterOptions } from \"./utils\";\nimport { useDebouncedValue } from \"../../hooks\";\n\nexport type UseComboboxOptionsProps = Pick<\n ComboboxProps,\n \"options\" | \"asyncOptions\" | \"delay\" | \"minLength\"\n> & {\n inputValue?: string;\n};\n\nexport function useComboboxOptions({\n options,\n asyncOptions,\n delay = 300,\n minLength = 3,\n inputValue = \"\",\n}: UseComboboxOptionsProps) {\n const [filteredOptions, setFilteredOptions] = useState<ComboboxOptions>([]);\n const debouncedInputValue = useDebouncedValue(\n inputValue,\n // Don't debounce synchronous options\n options ? 0 : delay,\n );\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n useEffect(() => {\n const controller = new AbortController();\n const { signal } = controller;\n\n const fetchOptions = async () => {\n setIsLoading(true);\n setError(null);\n try {\n if (asyncOptions) {\n if (debouncedInputValue.length < minLength) {\n setFilteredOptions([]);\n return;\n }\n const result = await asyncOptions(debouncedInputValue, { signal });\n setFilteredOptions(result);\n } else {\n // @ts-expect-error options will always be set here, fix the types\n setFilteredOptions(filterOptions(options, debouncedInputValue));\n }\n } catch (e: unknown) {\n if (e instanceof DOMException && e.name === \"AbortError\") {\n // Ignore abort errors\n return;\n }\n setError(e as Error);\n } finally {\n setIsLoading(false);\n }\n };\n\n fetchOptions();\n\n return () => {\n controller.abort();\n };\n }, [debouncedInputValue, options, asyncOptions, delay, minLength]);\n\n return { filteredOptions, isLoading, error, isError: error != null };\n}\n"],"names":["useEffect","useState","filterOptions","useDebouncedValue","useComboboxOptions","options","asyncOptions","delay","minLength","inputValue","filteredOptions","setFilteredOptions","debouncedInputValue","isLoading","setIsLoading","error","setError","controller","AbortController","signal","fetchOptions","length","result","e","DOMException","name","abort","isError"],"mappings":"AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AAE5C,SAASC,aAAa,QAAQ,UAAU;AACxC,SAASC,iBAAiB,QAAQ,cAAc;AAShD,OAAO,SAASC,mBAAmB,EACjCC,OAAO,EACPC,YAAY,EACZC,QAAQ,GAAG,EACXC,YAAY,CAAC,EACbC,aAAa,EAAE,EACS;IACxB,MAAM,CAACC,iBAAiBC,mBAAmB,GAAGV,SAA0B,EAAE;IAC1E,MAAMW,sBAAsBT,kBAC1BM,YACA,qCAAqC;IACrCJ,UAAU,IAAIE;IAEhB,MAAM,CAACM,WAAWC,aAAa,GAAGb,SAAS;IAC3C,MAAM,CAACc,OAAOC,SAAS,GAAGf,SAAuB;IAEjDD,UAAU;QACR,MAAMiB,aAAa,IAAIC;QACvB,MAAM,EAAEC,MAAM,EAAE,GAAGF;QAEnB,MAAMG,eAAe;YACnBN,aAAa;YACbE,SAAS;YACT,IAAI;gBACF,IAAIV,cAAc;oBAChB,IAAIM,oBAAoBS,MAAM,GAAGb,WAAW;wBAC1CG,mBAAmB,EAAE;wBACrB;oBACF;oBACA,MAAMW,SAAS,MAAMhB,aAAaM,qBAAqB;wBAAEO;oBAAO;oBAChER,mBAAmBW;gBACrB,OAAO;oBACL,kEAAkE;oBAClEX,mBAAmBT,cAAcG,SAASO;gBAC5C;YACF,EAAE,OAAOW,GAAY;gBACnB,IAAIA,aAAaC,gBAAgBD,EAAEE,IAAI,KAAK,cAAc;oBACxD,sBAAsB;oBACtB;gBACF;gBACAT,SAASO;YACX,SAAU;gBACRT,aAAa;YACf;QACF;QAEAM;QAEA,OAAO;YACLH,WAAWS,KAAK;QAClB;IACF,GAAG;QAACd;QAAqBP;QAASC;QAAcC;QAAOC;KAAU;IAEjE,OAAO;QAAEE;QAAiBG;QAAWE;QAAOY,SAASZ,SAAS;IAAK;AACrE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
export function VisuallyHidden(props) {
|
|
3
|
-
const { className, children, elementType: Component = "div" } = props;
|
|
3
|
+
const { className, children, elementType: Component = "div", ...otherProps } = props;
|
|
4
4
|
return /*#__PURE__*/ _jsx(Component, {
|
|
5
5
|
className: className,
|
|
6
6
|
style: {
|
|
@@ -15,6 +15,7 @@ export function VisuallyHidden(props) {
|
|
|
15
15
|
width: "1px",
|
|
16
16
|
whiteSpace: "nowrap"
|
|
17
17
|
},
|
|
18
|
+
...otherProps,
|
|
18
19
|
children: children
|
|
19
20
|
});
|
|
20
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/VisuallyHidden/VisuallyHidden.tsx"],"sourcesContent":["import type { JSXElementConstructor, ReactNode } from \"react\";\n\nexport interface VisuallyHiddenProps {\n /** The content to visually hide. */\n children?: ReactNode;\n\n className?: string;\n\n /**\n * The element type for the container. Defaults to 'div'\n */\n elementType?: string | JSXElementConstructor<any>;\n}\n\nexport function VisuallyHidden(props: VisuallyHiddenProps) {\n const {
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/VisuallyHidden/VisuallyHidden.tsx"],"sourcesContent":["import type { AriaRole, JSXElementConstructor, ReactNode } from \"react\";\n\nexport interface VisuallyHiddenProps {\n /** The content to visually hide. */\n children?: ReactNode;\n id?: string;\n role?: AriaRole;\n\n className?: string;\n\n /**\n * The element type for the container. Defaults to 'div'\n */\n elementType?: string | JSXElementConstructor<any>;\n}\n\nexport function VisuallyHidden(props: VisuallyHiddenProps) {\n const {\n className,\n children,\n elementType: Component = \"div\",\n ...otherProps\n } = props;\n\n return (\n <Component\n className={className}\n style={{\n border: 0,\n clip: \"rect(0 0 0 0)\",\n clipPath: \"inset(50%)\",\n height: \"1px\",\n margin: \"-1px\",\n overflow: \"hidden\",\n padding: 0,\n position: \"absolute\",\n width: \"1px\",\n whiteSpace: \"nowrap\",\n }}\n {...otherProps}\n >\n {children}\n </Component>\n );\n}\n"],"names":["VisuallyHidden","props","className","children","elementType","Component","otherProps","style","border","clip","clipPath","height","margin","overflow","padding","position","width","whiteSpace"],"mappings":";AAgBA,OAAO,SAASA,eAAeC,KAA0B;IACvD,MAAM,EACJC,SAAS,EACTC,QAAQ,EACRC,aAAaC,YAAY,KAAK,EAC9B,GAAGC,YACJ,GAAGL;IAEJ,qBACE,KAACI;QACCH,WAAWA;QACXK,OAAO;YACLC,QAAQ;YACRC,MAAM;YACNC,UAAU;YACVC,QAAQ;YACRC,QAAQ;YACRC,UAAU;YACVC,SAAS;YACTC,UAAU;YACVC,OAAO;YACPC,YAAY;QACd;QACC,GAAGX,UAAU;kBAEbH;;AAGP"}
|
package/dist/esm/hooks/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
export * from "./useBodyScrollLock";
|
|
2
2
|
export * from "./useBreakpoint";
|
|
3
3
|
export * from "./useButton";
|
|
4
|
+
export * from "./useDebouncedValue";
|
|
4
5
|
export * from "./useDeprecationWarning";
|
|
5
6
|
export * from "./useDialog";
|
|
6
7
|
export * from "./useDialogPolyfill";
|
|
7
8
|
export * from "./useLabel";
|
|
8
9
|
export * from "./useOnClickOutside";
|
|
10
|
+
export * from "./useOnUnmount";
|
|
9
11
|
export * from "./usePrefersReducedMotion";
|
|
10
12
|
export * from "./useRenderCount";
|
|
11
13
|
export * from "./useTextField";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/index.tsx"],"sourcesContent":["export * from \"./useBodyScrollLock\";\nexport * from \"./useBreakpoint\";\nexport * from \"./useButton\";\nexport * from \"./useDeprecationWarning\";\nexport * from \"./useDialog\";\nexport * from \"./useDialogPolyfill\";\nexport * from \"./useLabel\";\nexport * from \"./useOnClickOutside\";\nexport * from \"./usePrefersReducedMotion\";\nexport * from \"./useRenderCount\";\nexport * from \"./useTextField\";\nexport * from \"./useValidationClasses\";\nexport * from \"./useWindowEvent\";\n"],"names":[],"mappings":"AAAA,cAAc,sBAAsB;AACpC,cAAc,kBAAkB;AAChC,cAAc,cAAc;AAC5B,cAAc,0BAA0B;AACxC,cAAc,cAAc;AAC5B,cAAc,sBAAsB;AACpC,cAAc,aAAa;AAC3B,cAAc,sBAAsB;AACpC,cAAc,4BAA4B;AAC1C,cAAc,mBAAmB;AACjC,cAAc,iBAAiB;AAC/B,cAAc,yBAAyB;AACvC,cAAc,mBAAmB"}
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/index.tsx"],"sourcesContent":["export * from \"./useBodyScrollLock\";\nexport * from \"./useBreakpoint\";\nexport * from \"./useButton\";\nexport * from \"./useDebouncedValue\";\nexport * from \"./useDeprecationWarning\";\nexport * from \"./useDialog\";\nexport * from \"./useDialogPolyfill\";\nexport * from \"./useLabel\";\nexport * from \"./useOnClickOutside\";\nexport * from \"./useOnUnmount\";\nexport * from \"./usePrefersReducedMotion\";\nexport * from \"./useRenderCount\";\nexport * from \"./useTextField\";\nexport * from \"./useValidationClasses\";\nexport * from \"./useWindowEvent\";\n"],"names":[],"mappings":"AAAA,cAAc,sBAAsB;AACpC,cAAc,kBAAkB;AAChC,cAAc,cAAc;AAC5B,cAAc,sBAAsB;AACpC,cAAc,0BAA0B;AACxC,cAAc,cAAc;AAC5B,cAAc,sBAAsB;AACpC,cAAc,aAAa;AAC3B,cAAc,sBAAsB;AACpC,cAAc,iBAAiB;AAC/B,cAAc,4BAA4B;AAC1C,cAAc,mBAAmB;AACjC,cAAc,iBAAiB;AAC/B,cAAc,yBAAyB;AACvC,cAAc,mBAAmB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/hooks/useDebouncedValue/index.tsx"],"sourcesContent":["export * from \"./useDebouncedValue\";\n"],"names":[],"mappings":"AAAA,cAAc,sBAAsB"}
|