@navikt/ds-react 4.6.1 → 4.7.1
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/_docs.json +1711 -169
- package/cjs/chips/Chips.js +1 -2
- package/cjs/date/hooks/useDatepicker.js +1 -2
- package/cjs/date/hooks/useMonthPicker.js +1 -2
- package/cjs/form/combobox/ClearButton.js +27 -0
- package/cjs/form/combobox/Combobox.js +78 -0
- package/cjs/form/combobox/ComboboxProvider.js +99 -0
- package/cjs/form/combobox/ComboboxWrapper.js +51 -0
- package/cjs/form/combobox/FilteredOptions/CheckIcon.js +11 -0
- package/cjs/form/combobox/FilteredOptions/FilteredOptions.js +46 -0
- package/cjs/form/combobox/FilteredOptions/filteredOptionsContext.js +208 -0
- package/cjs/form/combobox/Input/Input.js +143 -0
- package/cjs/form/combobox/Input/inputContext.js +86 -0
- package/cjs/form/combobox/SelectedOptions/SelectedOptions.js +27 -0
- package/cjs/form/combobox/SelectedOptions/selectedOptionsContext.js +107 -0
- package/cjs/form/combobox/ToggleListButton.js +36 -0
- package/cjs/form/combobox/customOptionsContext.js +56 -0
- package/cjs/form/combobox/index.js +8 -0
- package/cjs/form/combobox/package.json +6 -0
- package/cjs/form/combobox/types.js +2 -0
- package/cjs/form/index.js +3 -1
- package/cjs/timeline/AxisLabels.js +12 -12
- package/cjs/timeline/Timeline.js +2 -2
- package/cjs/util/usePrevious.js +18 -0
- package/esm/chips/Chips.js +1 -2
- package/esm/chips/Chips.js.map +1 -1
- package/esm/date/datepicker/TableHead.d.ts +1 -0
- package/esm/date/hooks/useDatepicker.js +1 -2
- package/esm/date/hooks/useDatepicker.js.map +1 -1
- package/esm/date/hooks/useMonthPicker.js +1 -2
- package/esm/date/hooks/useMonthPicker.js.map +1 -1
- package/esm/form/Fieldset/useFieldset.d.ts +1 -1
- package/esm/form/checkbox/useCheckbox.d.ts +4 -4
- package/esm/form/combobox/ClearButton.d.ts +7 -0
- package/esm/form/combobox/ClearButton.js +21 -0
- package/esm/form/combobox/ClearButton.js.map +1 -0
- package/esm/form/combobox/Combobox.d.ts +4 -0
- package/esm/form/combobox/Combobox.js +50 -0
- package/esm/form/combobox/Combobox.js.map +1 -0
- package/esm/form/combobox/ComboboxProvider.d.ts +26 -0
- package/esm/form/combobox/ComboboxProvider.js +72 -0
- package/esm/form/combobox/ComboboxProvider.js.map +1 -0
- package/esm/form/combobox/ComboboxWrapper.d.ts +14 -0
- package/esm/form/combobox/ComboboxWrapper.js +24 -0
- package/esm/form/combobox/ComboboxWrapper.js.map +1 -0
- package/esm/form/combobox/FilteredOptions/CheckIcon.d.ts +3 -0
- package/esm/form/combobox/FilteredOptions/CheckIcon.js +7 -0
- package/esm/form/combobox/FilteredOptions/CheckIcon.js.map +1 -0
- package/esm/form/combobox/FilteredOptions/FilteredOptions.d.ts +3 -0
- package/esm/form/combobox/FilteredOptions/FilteredOptions.js +42 -0
- package/esm/form/combobox/FilteredOptions/FilteredOptions.js.map +1 -0
- package/esm/form/combobox/FilteredOptions/filteredOptionsContext.d.ts +27 -0
- package/esm/form/combobox/FilteredOptions/filteredOptionsContext.js +178 -0
- package/esm/form/combobox/FilteredOptions/filteredOptionsContext.js.map +1 -0
- package/esm/form/combobox/Input/Input.d.ts +10 -0
- package/esm/form/combobox/Input/Input.js +116 -0
- package/esm/form/combobox/Input/Input.js.map +1 -0
- package/esm/form/combobox/Input/inputContext.d.ts +19 -0
- package/esm/form/combobox/Input/inputContext.js +59 -0
- package/esm/form/combobox/Input/inputContext.js.map +1 -0
- package/esm/form/combobox/SelectedOptions/SelectedOptions.d.ts +8 -0
- package/esm/form/combobox/SelectedOptions/SelectedOptions.js +23 -0
- package/esm/form/combobox/SelectedOptions/SelectedOptions.js.map +1 -0
- package/esm/form/combobox/SelectedOptions/selectedOptionsContext.d.ts +17 -0
- package/esm/form/combobox/SelectedOptions/selectedOptionsContext.js +77 -0
- package/esm/form/combobox/SelectedOptions/selectedOptionsContext.js.map +1 -0
- package/esm/form/combobox/ToggleListButton.d.ts +6 -0
- package/esm/form/combobox/ToggleListButton.js +11 -0
- package/esm/form/combobox/ToggleListButton.js.map +1 -0
- package/esm/form/combobox/customOptionsContext.d.ts +11 -0
- package/esm/form/combobox/customOptionsContext.js +29 -0
- package/esm/form/combobox/customOptionsContext.js.map +1 -0
- package/esm/form/combobox/index.d.ts +2 -0
- package/esm/form/combobox/index.js +2 -0
- package/esm/form/combobox/index.js.map +1 -0
- package/esm/form/combobox/types.d.ts +119 -0
- package/esm/form/combobox/types.js +2 -0
- package/esm/form/combobox/types.js.map +1 -0
- package/esm/form/index.d.ts +1 -0
- package/esm/form/index.js +1 -0
- package/esm/form/index.js.map +1 -1
- package/esm/form/radio/useRadio.d.ts +4 -4
- package/esm/form/useFormField.d.ts +11 -10
- package/esm/form/useFormField.js.map +1 -1
- package/esm/timeline/AxisLabels.d.ts +7 -5
- package/esm/timeline/AxisLabels.js +12 -12
- package/esm/timeline/AxisLabels.js.map +1 -1
- package/esm/timeline/Timeline.d.ts +6 -0
- package/esm/timeline/Timeline.js +2 -2
- package/esm/timeline/Timeline.js.map +1 -1
- package/esm/timeline/utils/types.external.d.ts +5 -0
- package/esm/util/usePrevious.d.ts +2 -0
- package/esm/util/usePrevious.js +17 -0
- package/esm/util/usePrevious.js.map +1 -0
- package/package.json +2 -2
- package/src/chips/Chips.tsx +1 -1
- package/src/date/hooks/useDatepicker.tsx +1 -2
- package/src/date/hooks/useMonthPicker.tsx +1 -2
- package/src/form/combobox/ClearButton.tsx +29 -0
- package/src/form/combobox/Combobox.tsx +136 -0
- package/src/form/combobox/ComboboxProvider.tsx +99 -0
- package/src/form/combobox/ComboboxWrapper.tsx +63 -0
- package/src/form/combobox/FilteredOptions/CheckIcon.tsx +23 -0
- package/src/form/combobox/FilteredOptions/FilteredOptions.tsx +106 -0
- package/src/form/combobox/FilteredOptions/filteredOptionsContext.tsx +266 -0
- package/src/form/combobox/Input/Input.tsx +170 -0
- package/src/form/combobox/Input/inputContext.tsx +127 -0
- package/src/form/combobox/SelectedOptions/SelectedOptions.tsx +45 -0
- package/src/form/combobox/SelectedOptions/selectedOptionsContext.tsx +147 -0
- package/src/form/combobox/ToggleListButton.tsx +37 -0
- package/src/form/combobox/combobox.stories.tsx +413 -0
- package/src/form/combobox/combobox.test.tsx +123 -0
- package/src/form/combobox/customOptionsContext.tsx +57 -0
- package/src/form/combobox/index.ts +2 -0
- package/src/form/combobox/types.ts +122 -0
- package/src/form/index.ts +1 -0
- package/src/form/useFormField.ts +19 -1
- package/src/timeline/AxisLabels.tsx +23 -13
- package/src/timeline/Timeline.tsx +18 -2
- package/src/timeline/utils/types.external.ts +6 -0
- package/src/util/usePrevious.ts +19 -0
package/cjs/chips/Chips.js
CHANGED
|
@@ -75,8 +75,7 @@ exports.Chips = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
75
75
|
"navds-body-short navds-body-short--small": size === "medium",
|
|
76
76
|
"navds-detail navds-detail--small": size === "small",
|
|
77
77
|
}) }), react_1.default.Children.map(children, (chip, index) => {
|
|
78
|
-
|
|
79
|
-
return react_1.default.createElement("li", { key: index + ((_a = chip === null || chip === void 0 ? void 0 : chip.toString()) !== null && _a !== void 0 ? _a : "") }, chip);
|
|
78
|
+
return react_1.default.createElement("li", { key: (chip === null || chip === void 0 ? void 0 : chip.toString()) || index }, chip);
|
|
80
79
|
})));
|
|
81
80
|
});
|
|
82
81
|
exports.Chips.Toggle = Toggle_1.default;
|
|
@@ -43,8 +43,7 @@ const useDatepicker = (opt = {}) => {
|
|
|
43
43
|
const handleOpen = (0, react_1.useCallback)((open) => {
|
|
44
44
|
var _a, _b;
|
|
45
45
|
setOpen(open);
|
|
46
|
-
|
|
47
|
-
setMonth((_b = (_a = selectedDay !== null && selectedDay !== void 0 ? selectedDay : defaultSelected) !== null && _a !== void 0 ? _a : defaultMonth) !== null && _b !== void 0 ? _b : today);
|
|
46
|
+
open && setMonth((_b = (_a = selectedDay !== null && selectedDay !== void 0 ? selectedDay : defaultSelected) !== null && _a !== void 0 ? _a : defaultMonth) !== null && _b !== void 0 ? _b : today);
|
|
48
47
|
}, [defaultMonth, defaultSelected, selectedDay, today]);
|
|
49
48
|
(0, useOutsideClickHandler_1.useOutsideClickHandler)(open, handleOpen, [
|
|
50
49
|
daypickerRef,
|
|
@@ -48,8 +48,7 @@ const useMonthpicker = (opt = {}) => {
|
|
|
48
48
|
const handleOpen = (0, react_1.useCallback)((open) => {
|
|
49
49
|
var _a, _b;
|
|
50
50
|
setOpen(open);
|
|
51
|
-
|
|
52
|
-
setYear((_b = (_a = selectedMonth !== null && selectedMonth !== void 0 ? selectedMonth : defaultSelected) !== null && _a !== void 0 ? _a : defaultYear) !== null && _b !== void 0 ? _b : today);
|
|
51
|
+
open && setYear((_b = (_a = selectedMonth !== null && selectedMonth !== void 0 ? selectedMonth : defaultSelected) !== null && _a !== void 0 ? _a : defaultYear) !== null && _b !== void 0 ? _b : today);
|
|
53
52
|
}, [defaultSelected, defaultYear, selectedMonth, today]);
|
|
54
53
|
(0, useOutsideClickHandler_1.useOutsideClickHandler)(open, handleOpen, [
|
|
55
54
|
monthpickerRef,
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.ClearButton = void 0;
|
|
18
|
+
const react_1 = __importDefault(require("react"));
|
|
19
|
+
const aksel_icons_1 = require("@navikt/aksel-icons");
|
|
20
|
+
const ClearButton = (_a) => {
|
|
21
|
+
var { handleClear, clearButtonLabel } = _a, rest = __rest(_a, ["handleClear", "clearButtonLabel"]);
|
|
22
|
+
return (react_1.default.createElement("button", Object.assign({ type: "button", onClick: handleClear, className: "navds-combobox__button-clear" }, rest),
|
|
23
|
+
react_1.default.createElement("span", { className: "navds-sr-only" }, clearButtonLabel ? clearButtonLabel : "Tøm"),
|
|
24
|
+
react_1.default.createElement(aksel_icons_1.XMarkIcon, { "aria-hidden": true })));
|
|
25
|
+
};
|
|
26
|
+
exports.ClearButton = ClearButton;
|
|
27
|
+
exports.default = exports.ClearButton;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
+
var t = {};
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
+
t[p] = s[p];
|
|
29
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
+
t[p[i]] = s[p[i]];
|
|
33
|
+
}
|
|
34
|
+
return t;
|
|
35
|
+
};
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.Combobox = void 0;
|
|
41
|
+
const clsx_1 = __importDefault(require("clsx"));
|
|
42
|
+
const react_1 = __importStar(require("react"));
|
|
43
|
+
const __1 = require("../..");
|
|
44
|
+
const ClearButton_1 = __importDefault(require("./ClearButton"));
|
|
45
|
+
const FilteredOptions_1 = __importDefault(require("./FilteredOptions/FilteredOptions"));
|
|
46
|
+
const filteredOptionsContext_1 = require("./FilteredOptions/filteredOptionsContext");
|
|
47
|
+
const SelectedOptions_1 = __importDefault(require("./SelectedOptions/SelectedOptions"));
|
|
48
|
+
const ToggleListButton_1 = __importDefault(require("./ToggleListButton"));
|
|
49
|
+
const selectedOptionsContext_1 = require("./SelectedOptions/selectedOptionsContext");
|
|
50
|
+
const ComboboxWrapper_1 = __importDefault(require("./ComboboxWrapper"));
|
|
51
|
+
const inputContext_1 = require("./Input/inputContext");
|
|
52
|
+
const Input_1 = __importDefault(require("./Input/Input"));
|
|
53
|
+
exports.Combobox = (0, react_1.forwardRef)((props, ref) => {
|
|
54
|
+
const { value: externalValue, onClear, className, hideLabel = false, description, label, clearButton = true, clearButtonLabel, toggleListButton = true, toggleListButtonLabel, inputClassName, shouldShowSelectedOptions = true } = props, rest = __rest(props, ["value", "onClear", "className", "hideLabel", "description", "label", "clearButton", "clearButtonLabel", "toggleListButton", "toggleListButtonLabel", "inputClassName", "shouldShowSelectedOptions"]);
|
|
55
|
+
const toggleListButtonRef = (0, react_1.useRef)(null);
|
|
56
|
+
const { currentOption, toggleIsListOpen } = (0, filteredOptionsContext_1.useFilteredOptionsContext)();
|
|
57
|
+
const { selectedOptions } = (0, selectedOptionsContext_1.useSelectedOptionsContext)();
|
|
58
|
+
const { clearInput, focusInput, hasError, inputDescriptionId, inputProps, inputRef, value, size = "medium", } = (0, inputContext_1.useInputContext)();
|
|
59
|
+
const mergedInputRef = (0, react_1.useMemo)(() => (0, __1.mergeRefs)([inputRef, ref]), [inputRef, ref]);
|
|
60
|
+
return (react_1.default.createElement(ComboboxWrapper_1.default, { className: className, hasError: hasError, inputProps: inputProps, inputSize: size, toggleIsListOpen: toggleIsListOpen, toggleListButtonRef: toggleListButtonRef },
|
|
61
|
+
react_1.default.createElement(__1.Label, { htmlFor: inputProps.id, size: size, className: (0, clsx_1.default)("navds-form-field__label", {
|
|
62
|
+
"navds-sr-only": hideLabel,
|
|
63
|
+
}) }, label),
|
|
64
|
+
!!description && (react_1.default.createElement(__1.BodyShort, { as: "div", className: (0, clsx_1.default)("navds-form-field__description", {
|
|
65
|
+
"navds-sr-only": hideLabel,
|
|
66
|
+
}), id: inputDescriptionId, size: size }, description)),
|
|
67
|
+
react_1.default.createElement("div", { className: "navds-combobox__wrapper" },
|
|
68
|
+
react_1.default.createElement("div", { className: (0, clsx_1.default)("navds-combobox__wrapper-inner navds-text-field__input", {
|
|
69
|
+
"navds-combobox__wrapper-inner--virtually-unfocused": currentOption !== null,
|
|
70
|
+
}), onClick: focusInput },
|
|
71
|
+
!shouldShowSelectedOptions ? (react_1.default.createElement(Input_1.default, Object.assign({ id: inputProps.id, ref: mergedInputRef, inputClassName: inputClassName }, rest))) : (react_1.default.createElement(SelectedOptions_1.default, { selectedOptions: selectedOptions, size: size },
|
|
72
|
+
react_1.default.createElement(Input_1.default, Object.assign({ id: inputProps.id, ref: mergedInputRef, inputClassName: inputClassName }, rest)))),
|
|
73
|
+
react_1.default.createElement("div", null,
|
|
74
|
+
value && clearButton && (react_1.default.createElement(ClearButton_1.default, { handleClear: clearInput, clearButtonLabel: clearButtonLabel, tabIndex: -1 })),
|
|
75
|
+
toggleListButton && (react_1.default.createElement(ToggleListButton_1.default, { toggleListButtonLabel: toggleListButtonLabel, ref: toggleListButtonRef })))),
|
|
76
|
+
react_1.default.createElement(FilteredOptions_1.default, null))));
|
|
77
|
+
});
|
|
78
|
+
exports.default = exports.Combobox;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
+
var t = {};
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
+
t[p] = s[p];
|
|
29
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
+
t[p[i]] = s[p[i]];
|
|
33
|
+
}
|
|
34
|
+
return t;
|
|
35
|
+
};
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
const react_1 = __importStar(require("react"));
|
|
41
|
+
const Combobox_1 = __importDefault(require("./Combobox"));
|
|
42
|
+
const filteredOptionsContext_1 = require("./FilteredOptions/filteredOptionsContext");
|
|
43
|
+
const customOptionsContext_1 = require("./customOptionsContext");
|
|
44
|
+
const selectedOptionsContext_1 = require("./SelectedOptions/selectedOptionsContext");
|
|
45
|
+
const inputContext_1 = require("./Input/inputContext");
|
|
46
|
+
/**
|
|
47
|
+
* A component that allows the user to search in a list of options
|
|
48
|
+
*
|
|
49
|
+
* Has options for allowing only one or multiple options to be selected,
|
|
50
|
+
* or adding new, user-submitted values.
|
|
51
|
+
*
|
|
52
|
+
* @see [📝 Documentation](https://aksel.nav.no/komponenter/core/combobox)
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```jsx
|
|
56
|
+
* const options = ["apple", "banana", "orange"];
|
|
57
|
+
*
|
|
58
|
+
* return (
|
|
59
|
+
* <Combobox
|
|
60
|
+
* label="Velg en verdi"
|
|
61
|
+
* options={options}
|
|
62
|
+
* id="my-combobox"
|
|
63
|
+
* shouldAutoComplete
|
|
64
|
+
* />
|
|
65
|
+
* )
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
const ComboboxProvider = (0, react_1.forwardRef)((props, ref) => {
|
|
69
|
+
const { allowNewValues = false, children, defaultValue, error, errorId, filteredOptions, id, isListOpen, isLoading = false, isMultiSelect, onToggleSelected, selectedOptions, options, value, onChange, onClear, shouldAutocomplete, size } = props, rest = __rest(props, ["allowNewValues", "children", "defaultValue", "error", "errorId", "filteredOptions", "id", "isListOpen", "isLoading", "isMultiSelect", "onToggleSelected", "selectedOptions", "options", "value", "onChange", "onClear", "shouldAutocomplete", "size"]);
|
|
70
|
+
return (react_1.default.createElement(inputContext_1.InputContextProvider, { value: {
|
|
71
|
+
defaultValue,
|
|
72
|
+
error,
|
|
73
|
+
errorId,
|
|
74
|
+
id,
|
|
75
|
+
value,
|
|
76
|
+
onChange,
|
|
77
|
+
onClear,
|
|
78
|
+
shouldAutocomplete,
|
|
79
|
+
size,
|
|
80
|
+
} },
|
|
81
|
+
react_1.default.createElement(customOptionsContext_1.CustomOptionsProvider, null,
|
|
82
|
+
react_1.default.createElement(selectedOptionsContext_1.SelectedOptionsProvider, { value: {
|
|
83
|
+
allowNewValues,
|
|
84
|
+
isMultiSelect,
|
|
85
|
+
selectedOptions,
|
|
86
|
+
onToggleSelected,
|
|
87
|
+
options,
|
|
88
|
+
} },
|
|
89
|
+
react_1.default.createElement(filteredOptionsContext_1.FilteredOptionsProvider, { value: {
|
|
90
|
+
allowNewValues,
|
|
91
|
+
filteredOptions,
|
|
92
|
+
isListOpen,
|
|
93
|
+
isLoading,
|
|
94
|
+
isMultiSelect,
|
|
95
|
+
options,
|
|
96
|
+
} },
|
|
97
|
+
react_1.default.createElement(Combobox_1.default, Object.assign({ ref: ref }, rest), children))))));
|
|
98
|
+
});
|
|
99
|
+
exports.default = ComboboxProvider;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const clsx_1 = __importDefault(require("clsx"));
|
|
30
|
+
const react_1 = __importStar(require("react"));
|
|
31
|
+
const ComboboxWrapper = ({ children, className, hasError, inputProps, inputSize, toggleIsListOpen, toggleListButtonRef, }) => {
|
|
32
|
+
const wrapperRef = (0, react_1.useRef)(null);
|
|
33
|
+
function onFocusInsideWrapper(e) {
|
|
34
|
+
var _a;
|
|
35
|
+
if (!((_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.relatedTarget)) &&
|
|
36
|
+
(toggleListButtonRef === null || toggleListButtonRef === void 0 ? void 0 : toggleListButtonRef.current) !== e.target) {
|
|
37
|
+
toggleIsListOpen(true);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function onBlurWrapper(e) {
|
|
41
|
+
var _a;
|
|
42
|
+
if (!((_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.relatedTarget))) {
|
|
43
|
+
toggleIsListOpen(false);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return (react_1.default.createElement("div", { ref: wrapperRef, className: (0, clsx_1.default)(className, "navds-form-field", `navds-form-field--${inputSize}`, "navds-search", {
|
|
47
|
+
"navds-search--error": hasError,
|
|
48
|
+
"navds-search--disabled": !!inputProps.disabled,
|
|
49
|
+
}), onFocus: onFocusInsideWrapper, onBlur: onBlurWrapper }, children));
|
|
50
|
+
};
|
|
51
|
+
exports.default = ComboboxWrapper;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = __importDefault(require("react"));
|
|
7
|
+
const CheckIcon = () => {
|
|
8
|
+
return (react_1.default.createElement("svg", { width: "16", height: "13", viewBox: "0 0 16 13", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" },
|
|
9
|
+
react_1.default.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", fill: "#005B82", d: "M14.2014 0L16 1.89047L4.77943 13L0 8.39552L1.79361 6.5L4.77418 9.3019L14.2014 0Z" })));
|
|
10
|
+
};
|
|
11
|
+
exports.default = CheckIcon;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = __importDefault(require("react"));
|
|
7
|
+
const clsx_1 = __importDefault(require("clsx"));
|
|
8
|
+
const __1 = require("../../..");
|
|
9
|
+
const aksel_icons_1 = require("@navikt/aksel-icons");
|
|
10
|
+
const filteredOptionsContext_1 = require("./filteredOptionsContext");
|
|
11
|
+
const selectedOptionsContext_1 = require("../SelectedOptions/selectedOptionsContext");
|
|
12
|
+
const inputContext_1 = require("../Input/inputContext");
|
|
13
|
+
const FilteredOptions = () => {
|
|
14
|
+
const { inputProps: { id }, size, value, } = (0, inputContext_1.useInputContext)();
|
|
15
|
+
const { allowNewValues, isLoading, isListOpen, filteredOptions, filteredOptionsIndex, filteredOptionsRef, isValueNew, toggleIsListOpen, } = (0, filteredOptionsContext_1.useFilteredOptionsContext)();
|
|
16
|
+
const { isMultiSelect, selectedOptions, toggleOption } = (0, selectedOptionsContext_1.useSelectedOptionsContext)();
|
|
17
|
+
return (react_1.default.createElement("ul", { ref: filteredOptionsRef, className: (0, clsx_1.default)("navds-combobox__list", {
|
|
18
|
+
"navds-combobox__list--closed": !isListOpen,
|
|
19
|
+
}), id: `${id}-filtered-options`, role: "listbox", tabIndex: -1 },
|
|
20
|
+
isLoading && (react_1.default.createElement("li", { className: "navds-combobox__list-item--loading", role: "option", "aria-selected": false, id: `${id}-is-loading` },
|
|
21
|
+
react_1.default.createElement(__1.Loader, { "aria-label": "S\u00F8ker..." }))),
|
|
22
|
+
isValueNew && allowNewValues && (react_1.default.createElement("li", { tabIndex: -1, onPointerUp: (event) => toggleOption(value, event), id: `${id}-combobox-new-option`, className: (0, clsx_1.default)("navds-combobox__list-item__new-option", {
|
|
23
|
+
"navds-combobox__list-item__new-option--focus": filteredOptionsIndex === -1,
|
|
24
|
+
}), role: "option", "aria-selected": false },
|
|
25
|
+
react_1.default.createElement(aksel_icons_1.PlusIcon, { "aria-hidden": true }),
|
|
26
|
+
react_1.default.createElement(__1.BodyShort, { size: size },
|
|
27
|
+
"Legg til",
|
|
28
|
+
" ",
|
|
29
|
+
react_1.default.createElement(__1.Label, { as: "span", size: size },
|
|
30
|
+
"\u201C",
|
|
31
|
+
value,
|
|
32
|
+
"\u201D")))),
|
|
33
|
+
!isLoading && filteredOptions.length === 0 && (react_1.default.createElement("li", { className: "navds-combobox__list-item__no-options", role: "option", "aria-selected": false, id: `${id}-no-hits` }, "Ingen s\u00F8ketreff")),
|
|
34
|
+
filteredOptions.map((option, index) => (react_1.default.createElement("li", { className: (0, clsx_1.default)("navds-combobox__list-item", {
|
|
35
|
+
"navds-combobox__list-item--focus": index === filteredOptionsIndex,
|
|
36
|
+
"navds-combobox__list-item--selected": selectedOptions.includes(option),
|
|
37
|
+
}), id: `${id}-option-${option.replace(" ", "-")}`, key: option, tabIndex: -1, onPointerUp: (event) => {
|
|
38
|
+
toggleOption(option, event);
|
|
39
|
+
if (!isMultiSelect) {
|
|
40
|
+
toggleIsListOpen(false);
|
|
41
|
+
}
|
|
42
|
+
}, role: "option", "aria-selected": selectedOptions.includes(option) },
|
|
43
|
+
react_1.default.createElement(__1.BodyShort, { size: size }, option),
|
|
44
|
+
selectedOptions.includes(option) && react_1.default.createElement(aksel_icons_1.CheckmarkIcon, null))))));
|
|
45
|
+
};
|
|
46
|
+
exports.default = FilteredOptions;
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.useFilteredOptionsContext = exports.FilteredOptionsProvider = void 0;
|
|
30
|
+
const react_1 = __importStar(require("react"));
|
|
31
|
+
const customOptionsContext_1 = require("../customOptionsContext");
|
|
32
|
+
const inputContext_1 = require("../Input/inputContext");
|
|
33
|
+
const usePrevious_1 = __importDefault(require("../../../util/usePrevious"));
|
|
34
|
+
const normalizeText = (text) => typeof text === "string" ? `${text}`.toLowerCase().trim() : "";
|
|
35
|
+
const isPartOfText = (value, text) => normalizeText(text).startsWith(normalizeText(value !== null && value !== void 0 ? value : ""));
|
|
36
|
+
const isValueInList = (value, list) => list === null || list === void 0 ? void 0 : list.find((listItem) => normalizeText(value) === normalizeText(listItem));
|
|
37
|
+
const getMatchingValuesFromList = (value, list) => list === null || list === void 0 ? void 0 : list.filter((listItem) => isPartOfText(value, listItem));
|
|
38
|
+
const FilteredOptionsContext = (0, react_1.createContext)({});
|
|
39
|
+
const FilteredOptionsProvider = ({ children, value: props }) => {
|
|
40
|
+
const { allowNewValues, filteredOptions: externalFilteredOptions, isListOpen: isExternalListOpen, isLoading, options, } = props;
|
|
41
|
+
const filteredOptionsRef = (0, react_1.useRef)(null);
|
|
42
|
+
const { inputProps: { id }, value, searchTerm, setValue, setSearchTerm, shouldAutocomplete, } = (0, inputContext_1.useInputContext)();
|
|
43
|
+
const [filteredOptionsIndex, setFilteredOptionsIndex] = (0, react_1.useState)(null);
|
|
44
|
+
const [isInternalListOpen, setInternalListOpen] = (0, react_1.useState)(false);
|
|
45
|
+
const { customOptions } = (0, customOptionsContext_1.useCustomOptionsContext)();
|
|
46
|
+
const filteredOptions = (0, react_1.useMemo)(() => {
|
|
47
|
+
if (externalFilteredOptions) {
|
|
48
|
+
return externalFilteredOptions;
|
|
49
|
+
}
|
|
50
|
+
const opts = [...customOptions, ...options];
|
|
51
|
+
setFilteredOptionsIndex(null);
|
|
52
|
+
return getMatchingValuesFromList(searchTerm, opts);
|
|
53
|
+
}, [customOptions, externalFilteredOptions, options, searchTerm]);
|
|
54
|
+
const previousSearchTerm = (0, usePrevious_1.default)(searchTerm);
|
|
55
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
56
|
+
if (shouldAutocomplete &&
|
|
57
|
+
normalizeText(searchTerm) !== "" &&
|
|
58
|
+
((previousSearchTerm === null || previousSearchTerm === void 0 ? void 0 : previousSearchTerm.length) || 0) < searchTerm.length &&
|
|
59
|
+
filteredOptions.length > 0 &&
|
|
60
|
+
!isValueInList(searchTerm, filteredOptions)) {
|
|
61
|
+
setValue(`${searchTerm}${filteredOptions[0].substring(searchTerm.length)}`);
|
|
62
|
+
setSearchTerm(searchTerm);
|
|
63
|
+
}
|
|
64
|
+
}, [
|
|
65
|
+
filteredOptions,
|
|
66
|
+
previousSearchTerm,
|
|
67
|
+
searchTerm,
|
|
68
|
+
setSearchTerm,
|
|
69
|
+
setValue,
|
|
70
|
+
shouldAutocomplete,
|
|
71
|
+
]);
|
|
72
|
+
const isListOpen = (0, react_1.useMemo)(() => {
|
|
73
|
+
return isExternalListOpen !== null && isExternalListOpen !== void 0 ? isExternalListOpen : isInternalListOpen;
|
|
74
|
+
}, [isExternalListOpen, isInternalListOpen]);
|
|
75
|
+
const toggleIsListOpen = (0, react_1.useCallback)((newState) => {
|
|
76
|
+
setFilteredOptionsIndex(null);
|
|
77
|
+
setInternalListOpen((oldState) => newState !== null && newState !== void 0 ? newState : !oldState);
|
|
78
|
+
}, []);
|
|
79
|
+
const isValueNew = (0, react_1.useMemo)(() => Boolean(value) && !isValueInList(value, filteredOptions), [value, filteredOptions]);
|
|
80
|
+
const getMinimumIndex = (0, react_1.useCallback)(() => {
|
|
81
|
+
return isValueNew && allowNewValues ? -1 : 0;
|
|
82
|
+
}, [allowNewValues, isValueNew]);
|
|
83
|
+
const ariaDescribedBy = (0, react_1.useMemo)(() => {
|
|
84
|
+
if (!isLoading && filteredOptions.length === 0) {
|
|
85
|
+
return `${id}-no-hits`;
|
|
86
|
+
}
|
|
87
|
+
else if ((value && value !== "") || isLoading) {
|
|
88
|
+
if (shouldAutocomplete && filteredOptions[0]) {
|
|
89
|
+
return `${id}-option-${filteredOptions[0].replace(" ", "-")}`;
|
|
90
|
+
}
|
|
91
|
+
else if (isLoading) {
|
|
92
|
+
return `${id}-is-loading`;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
}, [isLoading, value, shouldAutocomplete, filteredOptions, id]);
|
|
99
|
+
const currentOption = (0, react_1.useMemo)(() => {
|
|
100
|
+
if (filteredOptionsIndex == null) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
if (filteredOptionsIndex === -1) {
|
|
104
|
+
return value;
|
|
105
|
+
}
|
|
106
|
+
return filteredOptions[filteredOptionsIndex];
|
|
107
|
+
}, [filteredOptionsIndex, filteredOptions, value]);
|
|
108
|
+
const resetFilteredOptionsIndex = () => {
|
|
109
|
+
setFilteredOptionsIndex(getMinimumIndex());
|
|
110
|
+
};
|
|
111
|
+
const scrollToOption = (0, react_1.useCallback)((newIndex) => {
|
|
112
|
+
if (filteredOptionsRef.current &&
|
|
113
|
+
filteredOptionsRef.current.children[newIndex]) {
|
|
114
|
+
const child = filteredOptionsRef.current.children[newIndex];
|
|
115
|
+
const { top, bottom } = child.getBoundingClientRect();
|
|
116
|
+
const parentRect = filteredOptionsRef.current.getBoundingClientRect();
|
|
117
|
+
if (top < parentRect.top || bottom > parentRect.bottom) {
|
|
118
|
+
child.scrollIntoView({ block: "nearest" });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}, []);
|
|
122
|
+
(0, react_1.useEffect)(() => {
|
|
123
|
+
if (filteredOptionsIndex !== null && isListOpen) {
|
|
124
|
+
scrollToOption(filteredOptionsIndex);
|
|
125
|
+
}
|
|
126
|
+
}, [filteredOptionsIndex, isListOpen, scrollToOption]);
|
|
127
|
+
const moveFocusToInput = (0, react_1.useCallback)(() => {
|
|
128
|
+
setFilteredOptionsIndex(null);
|
|
129
|
+
toggleIsListOpen(false);
|
|
130
|
+
}, [toggleIsListOpen]);
|
|
131
|
+
const moveFocusToEnd = (0, react_1.useCallback)(() => {
|
|
132
|
+
const lastIndex = filteredOptions.length - 1;
|
|
133
|
+
toggleIsListOpen(true);
|
|
134
|
+
setFilteredOptionsIndex(lastIndex);
|
|
135
|
+
}, [filteredOptions.length, toggleIsListOpen]);
|
|
136
|
+
const moveFocusUp = (0, react_1.useCallback)(() => {
|
|
137
|
+
if (filteredOptionsIndex === null) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (filteredOptionsIndex === getMinimumIndex()) {
|
|
141
|
+
toggleIsListOpen(false);
|
|
142
|
+
setFilteredOptionsIndex(null);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
const newIndex = Math.max(getMinimumIndex(), filteredOptionsIndex - 1);
|
|
146
|
+
setFilteredOptionsIndex(newIndex);
|
|
147
|
+
}
|
|
148
|
+
}, [filteredOptionsIndex, getMinimumIndex, toggleIsListOpen]);
|
|
149
|
+
const moveFocusDown = (0, react_1.useCallback)(() => {
|
|
150
|
+
if (filteredOptionsIndex === null || !isListOpen) {
|
|
151
|
+
toggleIsListOpen(true);
|
|
152
|
+
if (allowNewValues || filteredOptions.length >= 1) {
|
|
153
|
+
setFilteredOptionsIndex(getMinimumIndex());
|
|
154
|
+
}
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const newIndex = Math.min(filteredOptionsIndex + 1, Math.max(getMinimumIndex(), filteredOptions.length - 1));
|
|
158
|
+
setFilteredOptionsIndex(newIndex);
|
|
159
|
+
}, [
|
|
160
|
+
allowNewValues,
|
|
161
|
+
filteredOptions.length,
|
|
162
|
+
filteredOptionsIndex,
|
|
163
|
+
getMinimumIndex,
|
|
164
|
+
isListOpen,
|
|
165
|
+
toggleIsListOpen,
|
|
166
|
+
]);
|
|
167
|
+
const activeDecendantId = (0, react_1.useMemo)(() => {
|
|
168
|
+
if (filteredOptionsIndex === null) {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
else if (filteredOptionsIndex === -1) {
|
|
172
|
+
return `${id}-combobox-new-option`;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
return `${id}-option-${currentOption === null || currentOption === void 0 ? void 0 : currentOption.replace(" ", "-")}`;
|
|
176
|
+
}
|
|
177
|
+
}, [filteredOptionsIndex, currentOption, id]);
|
|
178
|
+
const filteredOptionsState = {
|
|
179
|
+
activeDecendantId,
|
|
180
|
+
allowNewValues,
|
|
181
|
+
filteredOptionsRef,
|
|
182
|
+
filteredOptionsIndex,
|
|
183
|
+
setFilteredOptionsIndex,
|
|
184
|
+
shouldAutocomplete,
|
|
185
|
+
isListOpen,
|
|
186
|
+
isLoading,
|
|
187
|
+
filteredOptions,
|
|
188
|
+
isValueNew,
|
|
189
|
+
toggleIsListOpen,
|
|
190
|
+
currentOption,
|
|
191
|
+
resetFilteredOptionsIndex,
|
|
192
|
+
moveFocusUp,
|
|
193
|
+
moveFocusDown,
|
|
194
|
+
moveFocusToInput,
|
|
195
|
+
moveFocusToEnd,
|
|
196
|
+
ariaDescribedBy,
|
|
197
|
+
};
|
|
198
|
+
return (react_1.default.createElement(FilteredOptionsContext.Provider, { value: filteredOptionsState }, children));
|
|
199
|
+
};
|
|
200
|
+
exports.FilteredOptionsProvider = FilteredOptionsProvider;
|
|
201
|
+
const useFilteredOptionsContext = () => {
|
|
202
|
+
const context = (0, react_1.useContext)(FilteredOptionsContext);
|
|
203
|
+
if (!context) {
|
|
204
|
+
throw new Error("useFilteredOptionsContext must be used within a FilteredOptionsProvider");
|
|
205
|
+
}
|
|
206
|
+
return context;
|
|
207
|
+
};
|
|
208
|
+
exports.useFilteredOptionsContext = useFilteredOptionsContext;
|