@digdir/designsystemet-react 0.59.0 → 0.59.1-alpha.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/dist/cjs/components/Accordion/Accordion.js +1 -4
- package/dist/cjs/components/Accordion/AccordionContent/AccordionContent.js +1 -2
- package/dist/cjs/components/Accordion/AccordionHeader/AccordionHeader.js +1 -2
- package/dist/cjs/components/Accordion/AccordionItem/AccordionItem.js +1 -4
- package/dist/cjs/components/Button/Button.js +2 -2
- package/dist/cjs/components/DropdownMenu/DropdownMenuContent.js +4 -4
- package/dist/cjs/components/DropdownMenu/DropdownMenuTrigger.js +1 -1
- package/dist/cjs/components/Modal/ModalDialog.js +1 -1
- package/dist/cjs/components/Modal/ModalHeader/ModalHeader.js +1 -1
- package/dist/cjs/components/Modal/ModalHeader/ModalHeader.module.css.js +1 -1
- package/dist/cjs/components/Popover/PopoverContent.js +6 -6
- package/dist/cjs/components/Popover/PopoverTrigger.js +1 -1
- package/dist/cjs/components/Tooltip/Tooltip.js +6 -6
- package/dist/cjs/components/form/Checkbox/Checkbox.js +1 -1
- package/dist/cjs/components/form/Combobox/Combobox.js +72 -199
- package/dist/cjs/components/form/Combobox/Combobox.module.css.js +1 -1
- package/dist/cjs/components/form/Combobox/ComboboxContext.js +8 -0
- package/dist/cjs/components/form/Combobox/ComboboxIdContext.js +42 -0
- package/dist/cjs/components/form/Combobox/Custom/Custom.js +14 -9
- package/dist/cjs/components/form/Combobox/Empty/Empty.js +4 -4
- package/dist/cjs/components/form/Combobox/Option/Option.js +15 -33
- package/dist/cjs/components/form/Combobox/Option/useComboboxOption.js +47 -0
- package/dist/cjs/components/form/Combobox/internal/ComboboxChips.js +13 -10
- package/dist/cjs/components/form/Combobox/internal/ComboboxClearButton.js +5 -8
- package/dist/cjs/components/form/Combobox/internal/ComboboxInput.js +40 -69
- package/dist/cjs/components/form/Combobox/internal/ComboboxNative.js +2 -2
- package/dist/cjs/components/form/Combobox/useCombobox.js +77 -75
- package/dist/cjs/components/form/Combobox/useComboboxKeyboard.js +76 -0
- package/dist/cjs/components/form/Combobox/useFloatingCombobox.js +78 -0
- package/dist/cjs/components/form/Search/Search.js +1 -1
- package/dist/cjs/node_modules/@floating-ui/utils/{dom/dist → dist}/floating-ui.utils.dom.js +7 -4
- package/dist/cjs/node_modules/@floating-ui/utils/dist/floating-ui.utils.js +5 -0
- package/dist/cjs/node_modules/clsx/dist/clsx.js +1 -1
- package/dist/cjs/node_modules/clsx/dist/lite.js +9 -0
- package/dist/cjs/{node_modules → packages/react/node_modules}/@floating-ui/core/dist/floating-ui.core.js +40 -16
- package/dist/cjs/{node_modules → packages/react/node_modules}/@floating-ui/dom/dist/floating-ui.dom.js +83 -31
- package/dist/cjs/{node_modules → packages/react/node_modules}/@floating-ui/react/dist/floating-ui.react.js +307 -157
- package/dist/cjs/{node_modules/@floating-ui/react/utils → packages/react/node_modules/@floating-ui/react}/dist/floating-ui.react.utils.js +9 -4
- package/dist/cjs/{node_modules → packages/react/node_modules}/@floating-ui/react-dom/dist/floating-ui.react-dom.js +22 -18
- package/dist/{esm → cjs/packages/react}/node_modules/tabbable/dist/index.esm.js +59 -13
- package/dist/cjs/react-css-modules.css +2 -136
- package/dist/cjs/utilities/RovingTabIndex/RovingTabindexItem.js +1 -1
- package/dist/cjs/utilities/RovingTabIndex/RovingTabindexRoot.js +1 -1
- package/dist/esm/components/Accordion/Accordion.js +1 -4
- package/dist/esm/components/Accordion/AccordionContent/AccordionContent.js +1 -2
- package/dist/esm/components/Accordion/AccordionHeader/AccordionHeader.js +1 -2
- package/dist/esm/components/Accordion/AccordionItem/AccordionItem.js +1 -4
- package/dist/esm/components/Button/Button.js +2 -2
- package/dist/esm/components/DropdownMenu/DropdownMenuContent.js +3 -3
- package/dist/esm/components/DropdownMenu/DropdownMenuTrigger.js +1 -1
- package/dist/esm/components/Modal/ModalDialog.js +1 -1
- package/dist/esm/components/Modal/ModalHeader/ModalHeader.js +1 -1
- package/dist/esm/components/Modal/ModalHeader/ModalHeader.module.css.js +1 -1
- package/dist/esm/components/Popover/PopoverContent.js +4 -4
- package/dist/esm/components/Popover/PopoverTrigger.js +1 -1
- package/dist/esm/components/Tooltip/Tooltip.js +4 -4
- package/dist/esm/components/form/Checkbox/Checkbox.js +1 -1
- package/dist/esm/components/form/Combobox/Combobox.js +76 -203
- package/dist/esm/components/form/Combobox/Combobox.module.css.js +1 -1
- package/dist/esm/components/form/Combobox/ComboboxContext.js +6 -0
- package/dist/esm/components/form/Combobox/ComboboxIdContext.js +35 -0
- package/dist/esm/components/form/Combobox/Custom/Custom.js +13 -8
- package/dist/esm/components/form/Combobox/Empty/Empty.js +3 -3
- package/dist/esm/components/form/Combobox/Option/Option.js +15 -33
- package/dist/esm/components/form/Combobox/Option/useComboboxOption.js +45 -0
- package/dist/esm/components/form/Combobox/internal/ComboboxChips.js +12 -9
- package/dist/esm/components/form/Combobox/internal/ComboboxClearButton.js +4 -7
- package/dist/esm/components/form/Combobox/internal/ComboboxInput.js +40 -69
- package/dist/esm/components/form/Combobox/internal/ComboboxNative.js +2 -2
- package/dist/esm/components/form/Combobox/useCombobox.js +77 -75
- package/dist/esm/components/form/Combobox/useComboboxKeyboard.js +74 -0
- package/dist/esm/components/form/Combobox/useFloatingCombobox.js +76 -0
- package/dist/esm/components/form/Search/Search.js +1 -1
- package/dist/esm/node_modules/@floating-ui/utils/{dom/dist → dist}/floating-ui.utils.dom.js +7 -4
- package/dist/esm/node_modules/@floating-ui/utils/dist/floating-ui.utils.js +5 -0
- package/dist/esm/node_modules/clsx/dist/clsx.js +1 -1
- package/dist/esm/node_modules/clsx/dist/lite.js +4 -0
- package/dist/esm/{node_modules → packages/react/node_modules}/@floating-ui/core/dist/floating-ui.core.js +40 -16
- package/dist/esm/{node_modules → packages/react/node_modules}/@floating-ui/dom/dist/floating-ui.dom.js +82 -30
- package/dist/esm/{node_modules → packages/react/node_modules}/@floating-ui/react/dist/floating-ui.react.js +282 -135
- package/dist/esm/{node_modules/@floating-ui/react/utils → packages/react/node_modules/@floating-ui/react}/dist/floating-ui.react.utils.js +9 -5
- package/dist/esm/{node_modules → packages/react/node_modules}/@floating-ui/react-dom/dist/floating-ui.react-dom.js +19 -14
- package/dist/{cjs → esm/packages/react}/node_modules/tabbable/dist/index.esm.js +55 -15
- package/dist/esm/react-css-modules.css +2 -136
- package/dist/esm/utilities/RovingTabIndex/RovingTabindexItem.js +1 -1
- package/dist/esm/utilities/RovingTabIndex/RovingTabindexRoot.js +1 -1
- package/dist/types/components/Accordion/Accordion.d.ts.map +1 -1
- package/dist/types/components/Accordion/AccordionContent/AccordionContent.d.ts.map +1 -1
- package/dist/types/components/Accordion/AccordionHeader/AccordionHeader.d.ts.map +1 -1
- package/dist/types/components/Accordion/AccordionItem/AccordionItem.d.ts.map +1 -1
- package/dist/types/components/Modal/ModalHeader/ModalHeader.d.ts.map +1 -1
- package/dist/types/components/form/Combobox/Combobox.d.ts +95 -48
- package/dist/types/components/form/Combobox/Combobox.d.ts.map +1 -1
- package/dist/types/components/form/Combobox/ComboboxContext.d.ts +41 -0
- package/dist/types/components/form/Combobox/ComboboxContext.d.ts.map +1 -0
- package/dist/types/components/form/Combobox/ComboboxIdContext.d.ts +19 -0
- package/dist/types/components/form/Combobox/ComboboxIdContext.d.ts.map +1 -0
- package/dist/types/components/form/Combobox/Custom/Custom.d.ts.map +1 -1
- package/dist/types/components/form/Combobox/Option/Option.d.ts +2 -2
- package/dist/types/components/form/Combobox/Option/Option.d.ts.map +1 -1
- package/dist/types/components/form/Combobox/Option/useComboboxOption.d.ts +14 -0
- package/dist/types/components/form/Combobox/Option/useComboboxOption.d.ts.map +1 -0
- package/dist/types/components/form/Combobox/internal/ComboboxChips.d.ts.map +1 -1
- package/dist/types/components/form/Combobox/internal/ComboboxClearButton.d.ts.map +1 -1
- package/dist/types/components/form/Combobox/internal/ComboboxInput.d.ts +9 -2
- package/dist/types/components/form/Combobox/internal/ComboboxInput.d.ts.map +1 -1
- package/dist/types/components/form/Combobox/internal/ComboboxNative.d.ts +3 -1
- package/dist/types/components/form/Combobox/internal/ComboboxNative.d.ts.map +1 -1
- package/dist/types/components/form/Combobox/useCombobox.d.ts +14 -9
- package/dist/types/components/form/Combobox/useCombobox.d.ts.map +1 -1
- package/dist/types/components/form/Combobox/useComboboxKeyboard.d.ts +19 -0
- package/dist/types/components/form/Combobox/useComboboxKeyboard.d.ts.map +1 -0
- package/dist/types/components/form/Combobox/useFloatingCombobox.d.ts +41 -0
- package/dist/types/components/form/Combobox/useFloatingCombobox.d.ts.map +1 -0
- package/package.json +3 -3
- package/dist/cjs/components/Accordion/Accordion.module.css.js +0 -6
- package/dist/cjs/node_modules/@floating-ui/react/node_modules/@floating-ui/utils/dist/floating-ui.utils.js +0 -6
- package/dist/cjs/node_modules/@floating-ui/react/node_modules/@floating-ui/utils/dom/dist/floating-ui.utils.dom.js +0 -68
- package/dist/esm/components/Accordion/Accordion.module.css.js +0 -4
- package/dist/esm/node_modules/@floating-ui/react/node_modules/@floating-ui/utils/dist/floating-ui.utils.js +0 -4
- package/dist/esm/node_modules/@floating-ui/react/node_modules/@floating-ui/utils/dom/dist/floating-ui.utils.dom.js +0 -57
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
|
|
7
|
+
const ComboboxIdContext = React.createContext({
|
|
8
|
+
activeIndex: 0,
|
|
9
|
+
});
|
|
10
|
+
const ComboboxIdReducer = (state, action) => {
|
|
11
|
+
switch (action.type) {
|
|
12
|
+
case 'SET_ACTIVE_INDEX':
|
|
13
|
+
return {
|
|
14
|
+
...state,
|
|
15
|
+
activeIndex: action.payload,
|
|
16
|
+
};
|
|
17
|
+
default:
|
|
18
|
+
return state;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const ComboboxIdDispatch = React.createContext(() => {
|
|
22
|
+
throw new Error('ComboboxIdDispatch must be used within a provider');
|
|
23
|
+
});
|
|
24
|
+
const ComboboxIdProvider = ({ children, }) => {
|
|
25
|
+
const [state, dispatch] = React.useReducer(ComboboxIdReducer, {
|
|
26
|
+
activeIndex: 0,
|
|
27
|
+
});
|
|
28
|
+
return (jsxRuntime.jsx(ComboboxIdContext.Provider, { value: state, children: jsxRuntime.jsx(ComboboxIdDispatch.Provider, { value: dispatch, children: children }) }));
|
|
29
|
+
};
|
|
30
|
+
function useComboboxIdDispatch() {
|
|
31
|
+
return React.useContext(ComboboxIdDispatch);
|
|
32
|
+
}
|
|
33
|
+
function useComboboxId() {
|
|
34
|
+
return React.useContext(ComboboxIdContext);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
exports.ComboboxIdContext = ComboboxIdContext;
|
|
38
|
+
exports.ComboboxIdDispatch = ComboboxIdDispatch;
|
|
39
|
+
exports.ComboboxIdProvider = ComboboxIdProvider;
|
|
40
|
+
exports.ComboboxIdReducer = ComboboxIdReducer;
|
|
41
|
+
exports.useComboboxId = useComboboxId;
|
|
42
|
+
exports.useComboboxIdDispatch = useComboboxIdDispatch;
|
|
@@ -7,7 +7,9 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var clsx = require('../../../../node_modules/clsx/dist/clsx.js');
|
|
9
9
|
var index = require('../../../../node_modules/@radix-ui/react-slot/dist/index.js');
|
|
10
|
-
var
|
|
10
|
+
var floatingUi_react = require('../../../../packages/react/node_modules/@floating-ui/react/dist/floating-ui.react.js');
|
|
11
|
+
var ComboboxContext = require('../ComboboxContext.js');
|
|
12
|
+
var ComboboxIdContext = require('../ComboboxIdContext.js');
|
|
11
13
|
var Custom_module = require('./Custom.module.css.js');
|
|
12
14
|
var objectUtils = require('../../../../utilities/objectUtils.js');
|
|
13
15
|
|
|
@@ -17,17 +19,20 @@ const ComboboxCustom = React.forwardRef(({ asChild, interactive, id, className,
|
|
|
17
19
|
}
|
|
18
20
|
const Component = asChild ? index.Slot : 'div';
|
|
19
21
|
const randomId = React.useId();
|
|
20
|
-
const
|
|
22
|
+
const { activeIndex } = ComboboxIdContext.useComboboxId();
|
|
23
|
+
const context = React.useContext(ComboboxContext.ComboboxContext);
|
|
21
24
|
if (!context) {
|
|
22
25
|
throw new Error('ComboboxCustom must be used within a Combobox');
|
|
23
26
|
}
|
|
24
|
-
const { size,
|
|
25
|
-
const index$1 = React.useMemo(() => id &&
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
const { size, customIds, listRef, getItemProps } = context;
|
|
28
|
+
const index$1 = React.useMemo(() => (id && customIds.indexOf(id)) || 0, [id, customIds]);
|
|
29
|
+
const combinedRef = floatingUi_react.useMergeRefs([
|
|
30
|
+
(node) => {
|
|
31
|
+
listRef.current[index$1] = node;
|
|
32
|
+
},
|
|
33
|
+
ref,
|
|
34
|
+
]);
|
|
35
|
+
return (jsxRuntime.jsx(Component, { ref: combinedRef, tabIndex: -1, className: clsx.clsx(Custom_module.custom, Custom_module[size], className), id: id || randomId, role: 'option', "aria-selected": activeIndex === index$1, "data-active": activeIndex === index$1, ...objectUtils.omit(['interactive'], rest), ...objectUtils.omit(['onClick', 'onPointerLeave'], getItemProps()) }));
|
|
31
36
|
});
|
|
32
37
|
var ComboboxCustom$1 = ComboboxCustom;
|
|
33
38
|
|
|
@@ -6,16 +6,16 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var clsx = require('../../../../node_modules/clsx/dist/clsx.js');
|
|
9
|
-
var
|
|
9
|
+
var ComboboxContext = require('../ComboboxContext.js');
|
|
10
10
|
var Empty_module = require('./Empty.module.css.js');
|
|
11
11
|
|
|
12
12
|
const ComboboxEmpty = React.forwardRef(({ children, className, ...rest }, ref) => {
|
|
13
|
-
const context = React.useContext(
|
|
13
|
+
const context = React.useContext(ComboboxContext.ComboboxContext);
|
|
14
14
|
if (!context) {
|
|
15
15
|
throw new Error('ComboboxEmpty must be used within a Combobox');
|
|
16
16
|
}
|
|
17
|
-
const {
|
|
18
|
-
return (
|
|
17
|
+
const { filteredOptions, size } = context;
|
|
18
|
+
return (filteredOptions.length === 0 && (jsxRuntime.jsx("div", { ref: ref, className: clsx.clsx(Empty_module.empty, Empty_module[size], className), ...rest, children: children })));
|
|
19
19
|
});
|
|
20
20
|
ComboboxEmpty.displayName = 'ComboboxEmpty';
|
|
21
21
|
|
|
@@ -4,50 +4,32 @@
|
|
|
4
4
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var clsx = require('../../../../node_modules/clsx/dist/clsx.js');
|
|
7
|
-
var
|
|
8
|
-
var Combobox = require('../Combobox.js');
|
|
9
|
-
var useDebounce = require('../../../../utilities/useDebounce.js');
|
|
7
|
+
var ComboboxContext = require('../ComboboxContext.js');
|
|
10
8
|
var SelectedIcon = require('./Icon/SelectedIcon.js');
|
|
11
9
|
var Option_module = require('./Option.module.css.js');
|
|
12
10
|
var Description = require('./Description/Description.js');
|
|
11
|
+
var useComboboxOption = require('./useComboboxOption.js');
|
|
13
12
|
var objectUtils = require('../../../../utilities/objectUtils.js');
|
|
14
13
|
var Label = require('../../../Typography/Label/Label.js');
|
|
15
14
|
|
|
16
|
-
const ComboboxOption = React.forwardRef(({ value, description, children, className, ...rest },
|
|
15
|
+
const ComboboxOption = React.memo(React.forwardRef(({ value, description, children, className, ...rest }, forwardedRef) => {
|
|
17
16
|
const labelId = React.useId();
|
|
18
|
-
const
|
|
19
|
-
|
|
17
|
+
const { id, ref, selected, active, onOptionClick } = useComboboxOption({
|
|
18
|
+
id: rest.id,
|
|
19
|
+
ref: forwardedRef,
|
|
20
|
+
value,
|
|
21
|
+
});
|
|
22
|
+
const context = React.useContext(ComboboxContext.ComboboxContext);
|
|
20
23
|
if (!context) {
|
|
21
24
|
throw new Error('ComboboxOption must be used within a Combobox');
|
|
22
25
|
}
|
|
23
|
-
const {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
listRef.current[index] = node;
|
|
28
|
-
},
|
|
29
|
-
ref,
|
|
30
|
-
]);
|
|
31
|
-
if (index === -1) {
|
|
32
|
-
throw new Error('Internal error: ComboboxOption did not find index');
|
|
33
|
-
}
|
|
34
|
-
const selected = selectedOptions.find((option) => option.value === value);
|
|
35
|
-
React.useEffect(() => {
|
|
36
|
-
if (activeIndex === index)
|
|
37
|
-
setActiveOption(index, rest.id || generatedId);
|
|
38
|
-
}, [activeIndex, generatedId, index, rest.id, setActiveOption]);
|
|
39
|
-
const onOptionClickDebounced = useDebounce(() => onOptionClick(value), 50);
|
|
40
|
-
return (jsxRuntime.jsxs("button", { id: rest.id || generatedId, role: 'option', type: 'button', "aria-selected": !!selected, "aria-labelledby": labelId, tabIndex: -1, onClick: (e) => {
|
|
41
|
-
onOptionClickDebounced();
|
|
26
|
+
const { size, multiple, getItemProps } = context;
|
|
27
|
+
const props = getItemProps();
|
|
28
|
+
return (jsxRuntime.jsxs("button", { ref: ref, id: id, role: 'option', type: 'button', "aria-selected": !!selected, "aria-labelledby": labelId, tabIndex: -1, onClick: (e) => {
|
|
29
|
+
onOptionClick();
|
|
42
30
|
rest.onClick?.(e);
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
rest.onMouseEnter?.(e);
|
|
46
|
-
}, onFocus: (e) => {
|
|
47
|
-
setActiveOption(index, labelId);
|
|
48
|
-
rest.onFocus?.(e);
|
|
49
|
-
}, className: clsx.clsx(Option_module.option, Option_module[size], activeIndex === index && Option_module.active, multiple && Option_module.multiple, className), ref: combinedRef, ...objectUtils.omit(['displayValue'], rest), children: [jsxRuntime.jsx(Label.Label, { asChild: true, size: size, children: jsxRuntime.jsx("span", { children: jsxRuntime.jsx(SelectedIcon.SelectedIcon, { multiple: multiple, selected: !!selected }) }) }), jsxRuntime.jsxs(Label.Label, { className: Option_module.optionText, size: size, id: labelId, children: [children, description && (jsxRuntime.jsx(Description.default, { children: description }))] })] }));
|
|
50
|
-
});
|
|
31
|
+
}, className: clsx.clsx(Option_module.option, Option_module[size], active && Option_module.active, multiple && Option_module.multiple, className), ...objectUtils.omit(['displayValue'], rest), ...objectUtils.omit(['onClick', 'onPointerLeave'], props), children: [jsxRuntime.jsx(Label.Label, { asChild: true, size: size, children: jsxRuntime.jsx("span", { children: jsxRuntime.jsx(SelectedIcon.SelectedIcon, { multiple: multiple, selected: !!selected }) }) }), jsxRuntime.jsxs(Label.Label, { className: Option_module.optionText, size: size, id: labelId, children: [children, description && (jsxRuntime.jsx(Description.default, { children: description }))] })] }));
|
|
32
|
+
}));
|
|
51
33
|
ComboboxOption.displayName = 'ComboboxOption';
|
|
52
34
|
|
|
53
35
|
exports.ComboboxOption = ComboboxOption;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var floatingUi_react = require('../../../../packages/react/node_modules/@floating-ui/react/dist/floating-ui.react.js');
|
|
6
|
+
var ComboboxContext = require('../ComboboxContext.js');
|
|
7
|
+
var useDebounce = require('../../../../utilities/useDebounce.js');
|
|
8
|
+
var ComboboxIdContext = require('../ComboboxIdContext.js');
|
|
9
|
+
|
|
10
|
+
function useComboboxOption({ id, ref, value, }) {
|
|
11
|
+
const generatedId = React.useId();
|
|
12
|
+
const newId = id || generatedId;
|
|
13
|
+
const context = React.useContext(ComboboxContext.ComboboxContext);
|
|
14
|
+
const { activeIndex } = ComboboxIdContext.useComboboxId();
|
|
15
|
+
const dispatch = ComboboxIdContext.useComboboxIdDispatch();
|
|
16
|
+
if (!context) {
|
|
17
|
+
throw new Error('ComboboxOption must be used within a Combobox');
|
|
18
|
+
}
|
|
19
|
+
const { selectedOptions, onOptionClick, listRef, customIds, filteredOptions, } = context;
|
|
20
|
+
const index = React.useMemo(() => filteredOptions.indexOf(value) + customIds.length, [customIds.length, filteredOptions, value]);
|
|
21
|
+
const combinedRef = floatingUi_react.useMergeRefs([
|
|
22
|
+
(node) => {
|
|
23
|
+
listRef.current[index] = node;
|
|
24
|
+
},
|
|
25
|
+
ref,
|
|
26
|
+
]);
|
|
27
|
+
if (index === -1) {
|
|
28
|
+
throw new Error('Internal error: ComboboxOption did not find index');
|
|
29
|
+
}
|
|
30
|
+
const selected = selectedOptions[value];
|
|
31
|
+
const active = activeIndex === index;
|
|
32
|
+
React.useEffect(() => {
|
|
33
|
+
if (active) {
|
|
34
|
+
dispatch?.({ type: 'SET_ACTIVE_INDEX', payload: index });
|
|
35
|
+
}
|
|
36
|
+
}, [generatedId, id, dispatch, active, index]);
|
|
37
|
+
const onOptionClickDebounced = useDebounce(() => onOptionClick(value), 50);
|
|
38
|
+
return {
|
|
39
|
+
id: newId,
|
|
40
|
+
ref: combinedRef,
|
|
41
|
+
selected,
|
|
42
|
+
active,
|
|
43
|
+
onOptionClick: onOptionClickDebounced,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
module.exports = useComboboxOption;
|
|
@@ -6,16 +6,16 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
require('../../../Chip/index.js');
|
|
9
|
-
var
|
|
9
|
+
var ComboboxContext = require('../ComboboxContext.js');
|
|
10
10
|
var Removable = require('../../../Chip/Removable/Removable.js');
|
|
11
11
|
|
|
12
12
|
const ComboboxChips = () => {
|
|
13
|
-
const context = React.useContext(
|
|
13
|
+
const context = React.useContext(ComboboxContext.ComboboxContext);
|
|
14
14
|
if (!context) {
|
|
15
15
|
throw new Error('ComboboxContext is missing');
|
|
16
16
|
}
|
|
17
|
-
const { size, readOnly, disabled, selectedOptions,
|
|
18
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: selectedOptions.map((
|
|
17
|
+
const { size, readOnly, disabled, selectedOptions, chipSrLabel, handleSelectOption, inputRef, } = context;
|
|
18
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: Object.keys(selectedOptions).map((value) => {
|
|
19
19
|
return (jsxRuntime.jsx(Removable.RemovableChip, { size: size, disabled: disabled, onKeyDown: (e) => {
|
|
20
20
|
if (readOnly)
|
|
21
21
|
return;
|
|
@@ -23,7 +23,10 @@ const ComboboxChips = () => {
|
|
|
23
23
|
return;
|
|
24
24
|
if (e.key === 'Enter') {
|
|
25
25
|
e.stopPropagation();
|
|
26
|
-
|
|
26
|
+
handleSelectOption({
|
|
27
|
+
option: selectedOptions[value],
|
|
28
|
+
remove: true,
|
|
29
|
+
});
|
|
27
30
|
inputRef.current?.focus();
|
|
28
31
|
}
|
|
29
32
|
}, onClick: () => {
|
|
@@ -32,11 +35,11 @@ const ComboboxChips = () => {
|
|
|
32
35
|
if (disabled)
|
|
33
36
|
return;
|
|
34
37
|
/* If we click a chip, filter the active values and remove the one we clicked */
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}, "aria-label": chipSrLabel(
|
|
38
|
+
handleSelectOption({
|
|
39
|
+
option: selectedOptions[value],
|
|
40
|
+
remove: true,
|
|
41
|
+
});
|
|
42
|
+
}, "aria-label": chipSrLabel(selectedOptions[value]), children: selectedOptions[value].label }, value));
|
|
40
43
|
}) }));
|
|
41
44
|
};
|
|
42
45
|
ComboboxChips.displayName = 'ComboboxChips';
|
|
@@ -7,22 +7,21 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var akselIcons = require('@navikt/aksel-icons');
|
|
9
9
|
var clsx = require('../../../../node_modules/clsx/dist/clsx.js');
|
|
10
|
-
var
|
|
10
|
+
var ComboboxContext = require('../ComboboxContext.js');
|
|
11
11
|
var Combobox_module = require('../Combobox.module.css.js');
|
|
12
12
|
|
|
13
13
|
const ComboboxClearButton = () => {
|
|
14
|
-
const context = React.useContext(
|
|
14
|
+
const context = React.useContext(ComboboxContext.ComboboxContext);
|
|
15
15
|
if (!context) {
|
|
16
16
|
throw new Error('ComboboxContext is missing');
|
|
17
17
|
}
|
|
18
|
-
const { size, readOnly, disabled, clearButtonLabel,
|
|
18
|
+
const { size, readOnly, disabled, clearButtonLabel, handleSelectOption } = context;
|
|
19
19
|
return (jsxRuntime.jsx("button", { disabled: disabled, className: clsx.clsx(Combobox_module.clearButton, Combobox_module[size], `fds-focus`), onClick: () => {
|
|
20
20
|
if (readOnly)
|
|
21
21
|
return;
|
|
22
22
|
if (disabled)
|
|
23
23
|
return;
|
|
24
|
-
|
|
25
|
-
setInputValue('');
|
|
24
|
+
handleSelectOption({ option: null, clear: true });
|
|
26
25
|
}, onKeyDown: (e) => {
|
|
27
26
|
if (readOnly)
|
|
28
27
|
return;
|
|
@@ -30,9 +29,7 @@ const ComboboxClearButton = () => {
|
|
|
30
29
|
return;
|
|
31
30
|
if (e.key === 'Enter') {
|
|
32
31
|
e.stopPropagation();
|
|
33
|
-
|
|
34
|
-
setInputValue('');
|
|
35
|
-
inputRef.current?.focus();
|
|
32
|
+
handleSelectOption({ option: null, clear: true });
|
|
36
33
|
}
|
|
37
34
|
}, type: 'button', "aria-label": clearButtonLabel, children: jsxRuntime.jsx(akselIcons.XMarkIcon, { fontSize: '1.5em', title: 'Clear selection' }) }));
|
|
38
35
|
};
|
|
@@ -7,97 +7,68 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var clsx = require('../../../../node_modules/clsx/dist/clsx.js');
|
|
9
9
|
var akselIcons = require('@navikt/aksel-icons');
|
|
10
|
-
var floatingUi_react = require('../../../../node_modules/@floating-ui/react/dist/floating-ui.react.js');
|
|
11
|
-
var
|
|
10
|
+
var floatingUi_react = require('../../../../packages/react/node_modules/@floating-ui/react/dist/floating-ui.react.js');
|
|
11
|
+
var ComboboxContext = require('../ComboboxContext.js');
|
|
12
12
|
var Combobox_module = require('../Combobox.module.css.js');
|
|
13
13
|
var Textfield_module = require('../../Textfield/Textfield.module.css.js');
|
|
14
|
+
var ComboboxIdContext = require('../ComboboxIdContext.js');
|
|
14
15
|
var ComboboxChips = require('./ComboboxChips.js');
|
|
15
16
|
var ComboboxClearButton = require('./ComboboxClearButton.js');
|
|
16
17
|
var Box = require('../../../Box/Box.js');
|
|
17
18
|
var objectUtils = require('../../../../utilities/objectUtils.js');
|
|
18
19
|
|
|
19
|
-
const ComboboxInput = ({ ...rest }) => {
|
|
20
|
-
const context = React.useContext(
|
|
20
|
+
const ComboboxInput = ({ hideClearButton, listId, error, hideChips, handleKeyDown, ...rest }) => {
|
|
21
|
+
const context = React.useContext(ComboboxContext.ComboboxContext);
|
|
22
|
+
const idDispatch = ComboboxIdContext.useComboboxIdDispatch();
|
|
21
23
|
if (!context) {
|
|
22
24
|
throw new Error('ComboboxContext is missing');
|
|
23
25
|
}
|
|
24
|
-
const
|
|
26
|
+
const setActiveIndex = (id) => {
|
|
27
|
+
idDispatch?.({ type: 'SET_ACTIVE_INDEX', payload: id });
|
|
28
|
+
};
|
|
29
|
+
const { forwareddRef, size, readOnly, disabled, open, inputRef, refs, inputValue, multiple, selectedOptions, formFieldProps, htmlSize, options, setOpen, getReferenceProps, setInputValue, handleSelectOption, } = context;
|
|
25
30
|
const mergedRefs = floatingUi_react.useMergeRefs([forwareddRef, inputRef]);
|
|
26
|
-
// we need to check if input is in focus, to add focus styles to the wrapper
|
|
27
|
-
const [inputInFocus, setInputInFocus] = React.useState(false);
|
|
28
|
-
React.useEffect(() => {
|
|
29
|
-
const input = inputRef.current;
|
|
30
|
-
const onFocus = () => {
|
|
31
|
-
setInputInFocus(true);
|
|
32
|
-
};
|
|
33
|
-
const onBlur = () => {
|
|
34
|
-
setInputInFocus(false);
|
|
35
|
-
};
|
|
36
|
-
input?.addEventListener('focus', onFocus);
|
|
37
|
-
input?.addEventListener('blur', onBlur);
|
|
38
|
-
return () => {
|
|
39
|
-
input?.removeEventListener('focus', onFocus);
|
|
40
|
-
input?.removeEventListener('blur', onBlur);
|
|
41
|
-
};
|
|
42
|
-
}, [inputRef]);
|
|
43
31
|
// onChange function for the input
|
|
44
32
|
const onChange = (event) => {
|
|
45
33
|
const value = event.target.value;
|
|
46
34
|
setInputValue(value);
|
|
47
35
|
setActiveIndex(0);
|
|
48
|
-
if (typeof value === 'string') {
|
|
49
|
-
setOpen(true);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
setOpen(false);
|
|
53
|
-
}
|
|
54
36
|
// check if input value is the same as a label, if so, select it
|
|
55
|
-
const option = options.
|
|
37
|
+
const option = options[value.toLowerCase()];
|
|
56
38
|
if (!option)
|
|
57
39
|
return;
|
|
58
|
-
if (selectedOptions
|
|
40
|
+
if (selectedOptions[option.value])
|
|
59
41
|
return;
|
|
60
|
-
handleSelectOption(option);
|
|
61
|
-
if (multiple) {
|
|
62
|
-
inputRef.current?.focus();
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
// move cursor to the end of the input
|
|
66
|
-
setTimeout(() => {
|
|
67
|
-
inputRef.current?.setSelectionRange(option?.label?.length || 0, option?.label?.length || 0);
|
|
68
|
-
}, 0);
|
|
69
|
-
}
|
|
42
|
+
handleSelectOption({ option: option });
|
|
70
43
|
};
|
|
71
|
-
const showClearButton = multiple && !hideClearButton && selectedOptions.length > 0;
|
|
72
|
-
return (jsxRuntime.jsxs(Box.Box
|
|
44
|
+
const showClearButton = multiple && !hideClearButton && Object.keys(selectedOptions).length > 0;
|
|
73
45
|
/* Props from floating-ui */
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}), "aria-disabled": disabled, className: clsx.clsx(Textfield_module.input, Combobox_module.inputWrapper, Combobox_module[size], inputInFocus && Combobox_module.inFocus, readOnly && Combobox_module.readonly, error && Combobox_module.error), children: [jsxRuntime.jsxs("div", { className: Combobox_module.chipAndInput, children: [multiple && !hideChips && jsxRuntime.jsx(ComboboxChips.default, {}), jsxRuntime.jsx("input", { ref: mergedRefs, "aria-activedescendant": activeDescendant, readOnly: readOnly, "aria-autocomplete": 'list', role: 'combobox', "aria-expanded": open, "aria-controls": listId, autoComplete: 'off', size: htmlSize, value: inputValue, ...objectUtils.omit(['style', 'className'], rest), ...formFieldProps.inputProps, onChange: (e) => {
|
|
46
|
+
const props = getReferenceProps({
|
|
47
|
+
ref: refs?.setReference,
|
|
48
|
+
role: null,
|
|
49
|
+
'aria-controls': null,
|
|
50
|
+
'aria-expanded': null,
|
|
51
|
+
'aria-haspopup': null,
|
|
52
|
+
/* If we click the wrapper, open the list, set index to first option, and focus the input */
|
|
53
|
+
onClick() {
|
|
54
|
+
if (disabled)
|
|
55
|
+
return;
|
|
56
|
+
if (readOnly)
|
|
57
|
+
return;
|
|
58
|
+
setOpen(true);
|
|
59
|
+
setActiveIndex(0);
|
|
60
|
+
inputRef.current?.focus();
|
|
61
|
+
},
|
|
62
|
+
/* Handles list navigation */
|
|
63
|
+
onKeyDown: handleKeyDown,
|
|
64
|
+
// preventDefault on keydown to avoid sending in form
|
|
65
|
+
onKeyPress(event) {
|
|
66
|
+
if (event.key === 'Enter') {
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
return (jsxRuntime.jsxs(Box.Box, { ...props, "aria-disabled": disabled, className: clsx.clsx(Textfield_module.input, Combobox_module.inputWrapper, Combobox_module[size], readOnly && Combobox_module.readonly, error && Combobox_module.error), children: [jsxRuntime.jsxs("div", { className: Combobox_module.chipAndInput, children: [multiple && !hideChips && jsxRuntime.jsx(ComboboxChips.default, {}), jsxRuntime.jsx("input", { ref: mergedRefs, "aria-activedescendant": props['aria-activedescendant'], readOnly: readOnly, "aria-autocomplete": 'list', role: 'combobox', "aria-expanded": open, "aria-controls": listId, autoComplete: 'off', size: htmlSize, value: inputValue, ...objectUtils.omit(['style', 'className'], rest), ...formFieldProps.inputProps, onChange: (e) => {
|
|
101
72
|
onChange(e);
|
|
102
73
|
rest.onChange && rest.onChange(e);
|
|
103
74
|
} })] }), showClearButton && jsxRuntime.jsx(ComboboxClearButton.default, {}), jsxRuntime.jsx("div", { className: Combobox_module.arrow, children: open ? (jsxRuntime.jsx(akselIcons.ChevronUpIcon, { title: 'arrow up', fontSize: '1.5em' })) : (jsxRuntime.jsx(akselIcons.ChevronDownIcon, { title: 'arrow down', fontSize: '1.5em' })) })] }));
|
|
@@ -7,8 +7,8 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
7
7
|
|
|
8
8
|
const ComboboxNative = ({ selectedOptions, multiple, name, }) => {
|
|
9
9
|
return (jsxRuntime.jsx("select", { name: name, multiple: multiple, style: { display: 'none' }, value: multiple
|
|
10
|
-
?
|
|
11
|
-
: selectedOptions[0]
|
|
10
|
+
? Object.keys(selectedOptions)
|
|
11
|
+
: Object.keys(selectedOptions)[0], onChange: () => { }, children: Object.keys(selectedOptions).map((value) => (jsxRuntime.jsx("option", { value: value }, value))) }));
|
|
12
12
|
};
|
|
13
13
|
ComboboxNative.displayName = 'ComboboxNative';
|
|
14
14
|
var ComboboxNative$1 = ComboboxNative;
|