@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
|
@@ -17,94 +17,96 @@ function isComboboxCustom(child) {
|
|
|
17
17
|
function isInteractiveComboboxCustom(child) {
|
|
18
18
|
return isComboboxCustom(child) && child.props.interactive === true;
|
|
19
19
|
}
|
|
20
|
-
function useCombobox({ children, inputValue, multiple, filter
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
function useCombobox({ children, inputValue, multiple, filter = (inputValue, option) => {
|
|
21
|
+
return option.label.toLowerCase().startsWith(inputValue.toLowerCase());
|
|
22
|
+
}, initialValue, }) {
|
|
23
|
+
const { optionsChildren, customIds, restChildren, interactiveChildren } = React.useMemo(() => {
|
|
24
|
+
const allChildren = React.Children.toArray(children);
|
|
25
|
+
const result = allChildren.reduce((acc, child) => {
|
|
24
26
|
if (isComboboxOption(child)) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
label = childrenLabel;
|
|
27
|
+
acc.optionsChildren.push(child);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
acc.restChildren.push(child);
|
|
31
|
+
if (isInteractiveComboboxCustom(child)) {
|
|
32
|
+
const childElement = child;
|
|
33
|
+
acc.interactiveChildren.push(childElement);
|
|
34
|
+
if (!childElement.props.id) {
|
|
35
|
+
throw new Error('If ComboboxCustom is interactive, it must have an id');
|
|
36
|
+
}
|
|
37
|
+
acc.customIds.push(childElement.props.id);
|
|
39
38
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
}
|
|
40
|
+
return acc;
|
|
41
|
+
}, {
|
|
42
|
+
optionsChildren: [],
|
|
43
|
+
customIds: [],
|
|
44
|
+
restChildren: [],
|
|
45
|
+
interactiveChildren: [],
|
|
46
|
+
});
|
|
47
|
+
return result;
|
|
48
|
+
}, [children]);
|
|
49
|
+
const options = React.useMemo(() => {
|
|
50
|
+
const allOptions = {};
|
|
51
|
+
optionsChildren.map((child) => {
|
|
52
|
+
const props = child.props;
|
|
53
|
+
let label = props.displayValue || '';
|
|
54
|
+
if (!props.displayValue) {
|
|
55
|
+
let childrenLabel = '';
|
|
56
|
+
// go over children and find all strings
|
|
57
|
+
React.Children.forEach(props.children, (child) => {
|
|
58
|
+
if (typeof child === 'string') {
|
|
59
|
+
childrenLabel += child;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
throw new Error('If ComboboxOption is not a string, it must have a displayValue prop');
|
|
63
|
+
}
|
|
45
64
|
});
|
|
65
|
+
label = childrenLabel;
|
|
46
66
|
}
|
|
67
|
+
allOptions[props.value] = {
|
|
68
|
+
value: props.value,
|
|
69
|
+
label,
|
|
70
|
+
displayValue: props.displayValue,
|
|
71
|
+
description: props.description,
|
|
72
|
+
};
|
|
47
73
|
});
|
|
48
74
|
return allOptions;
|
|
49
|
-
}, [
|
|
50
|
-
const preSelectedOptions = (initialValue || [])
|
|
51
|
-
|
|
52
|
-
|
|
75
|
+
}, [optionsChildren]);
|
|
76
|
+
const preSelectedOptions = React.useMemo(() => (initialValue || []).reduce((acc, value) => {
|
|
77
|
+
const option = options[value];
|
|
78
|
+
if (isOption(option)) {
|
|
79
|
+
acc[value] = option;
|
|
80
|
+
}
|
|
81
|
+
return acc;
|
|
82
|
+
}, {}), [initialValue, options]);
|
|
53
83
|
const [selectedOptions, setSelectedOptions] = React.useState(preSelectedOptions);
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
});
|
|
72
|
-
}, [options, children, multiple, inputValue, selectedOptions, filter]);
|
|
73
|
-
const customIds = React.useMemo(() => {
|
|
74
|
-
// find all custom components with `interactive=true` and generate random values for them
|
|
75
|
-
const children_ = React.Children.toArray(children).filter((child) => {
|
|
76
|
-
return isInteractiveComboboxCustom(child);
|
|
77
|
-
});
|
|
78
|
-
// return all ids
|
|
79
|
-
return children_.map((child) => {
|
|
80
|
-
if (!child.props.id)
|
|
81
|
-
throw new Error('If ComboboxCustom is interactive, it must have an id');
|
|
82
|
-
return child.props.id;
|
|
83
|
-
});
|
|
84
|
-
}, [children]);
|
|
85
|
-
const optionValues = React.useMemo(() => {
|
|
86
|
-
// create an index map of values from optionsChildren
|
|
87
|
-
const options = optionsChildren.map((child) => {
|
|
88
|
-
const { value } = child.props;
|
|
89
|
-
return value;
|
|
90
|
-
});
|
|
91
|
-
return [...customIds, ...options];
|
|
92
|
-
}, [customIds, optionsChildren]);
|
|
93
|
-
const restChildren = React.useMemo(() => {
|
|
94
|
-
return React.Children.toArray(children).filter((child) => {
|
|
95
|
-
return !isComboboxOption(child);
|
|
96
|
-
});
|
|
97
|
-
}, [children]);
|
|
84
|
+
const { filteredOptions, filteredOptionsChildren } = React.useMemo(() => {
|
|
85
|
+
const filteredOptions = [];
|
|
86
|
+
const filteredOptionsChildren = Object.keys(options)
|
|
87
|
+
.map((option, index) => {
|
|
88
|
+
if (multiple && selectedOptions[option]) {
|
|
89
|
+
filteredOptions.push(options[option].value);
|
|
90
|
+
return optionsChildren[index];
|
|
91
|
+
}
|
|
92
|
+
if (filter(inputValue, options[option])) {
|
|
93
|
+
filteredOptions.push(options[option].value);
|
|
94
|
+
return optionsChildren[index];
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
.filter((child) => child);
|
|
98
|
+
return { filteredOptions, filteredOptionsChildren };
|
|
99
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
100
|
+
}, [inputValue, multiple, options, optionsChildren, selectedOptions]);
|
|
98
101
|
return {
|
|
99
|
-
|
|
100
|
-
|
|
102
|
+
filteredOptionsChildren,
|
|
103
|
+
filteredOptions,
|
|
101
104
|
restChildren,
|
|
102
105
|
options,
|
|
103
106
|
customIds,
|
|
104
107
|
selectedOptions,
|
|
108
|
+
interactiveChildren,
|
|
105
109
|
setSelectedOptions,
|
|
106
|
-
prevSelectedHash,
|
|
107
|
-
setPrevSelectedHash,
|
|
108
110
|
};
|
|
109
111
|
}
|
|
110
112
|
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var useDebounce = require('../../../utilities/useDebounce.js');
|
|
5
|
+
var ComboboxIdContext = require('./ComboboxIdContext.js');
|
|
6
|
+
|
|
7
|
+
const useComboboxKeyboard = ({ readOnly, disabled, interactiveChildren, filteredOptions, inputValue, selectedOptions, multiple, open, options, setOpen, handleSelectOption, }) => {
|
|
8
|
+
const { activeIndex } = ComboboxIdContext.useComboboxId();
|
|
9
|
+
// handle keyboard navigation in the list
|
|
10
|
+
const handleKeyDownFunc = (event) => {
|
|
11
|
+
if (readOnly || disabled)
|
|
12
|
+
return;
|
|
13
|
+
if (!event)
|
|
14
|
+
return;
|
|
15
|
+
switch (event.key) {
|
|
16
|
+
case 'ArrowDown':
|
|
17
|
+
event.preventDefault();
|
|
18
|
+
if (open)
|
|
19
|
+
break;
|
|
20
|
+
setOpen(true);
|
|
21
|
+
break;
|
|
22
|
+
case 'ArrowUp':
|
|
23
|
+
event.preventDefault();
|
|
24
|
+
/* If we are on the first item, close */
|
|
25
|
+
if (activeIndex !== 0)
|
|
26
|
+
break;
|
|
27
|
+
setOpen(false);
|
|
28
|
+
break;
|
|
29
|
+
case 'Enter':
|
|
30
|
+
event.preventDefault();
|
|
31
|
+
// ignore if it is closed
|
|
32
|
+
if (!open)
|
|
33
|
+
break;
|
|
34
|
+
// check if we are in the custom components
|
|
35
|
+
if (activeIndex <= interactiveChildren.length - 1) {
|
|
36
|
+
const selectedComponent = interactiveChildren[activeIndex];
|
|
37
|
+
if (selectedComponent.props.onSelect) {
|
|
38
|
+
selectedComponent?.props.onSelect();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// if we are in the options, find the actual index
|
|
43
|
+
// eslint-disable-next-line no-case-declarations
|
|
44
|
+
const valueIndex = activeIndex - interactiveChildren.length;
|
|
45
|
+
// eslint-disable-next-line no-case-declarations
|
|
46
|
+
const option = filteredOptions[valueIndex];
|
|
47
|
+
handleSelectOption({ option: options[option] });
|
|
48
|
+
break;
|
|
49
|
+
case 'Backspace':
|
|
50
|
+
// if we are in single mode, we need to set selectedOptions to empty
|
|
51
|
+
if (!multiple) {
|
|
52
|
+
const lastOption = Object.keys(selectedOptions).pop();
|
|
53
|
+
lastOption &&
|
|
54
|
+
handleSelectOption({
|
|
55
|
+
option: selectedOptions[lastOption],
|
|
56
|
+
remove: true,
|
|
57
|
+
});
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
if (inputValue === '' && multiple) {
|
|
61
|
+
const lastOption = Object.keys(selectedOptions).pop();
|
|
62
|
+
/* Remove last option, and use handleSelectOption */
|
|
63
|
+
lastOption &&
|
|
64
|
+
handleSelectOption({
|
|
65
|
+
option: selectedOptions[lastOption],
|
|
66
|
+
remove: true,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const handleKeyDown = useDebounce(handleKeyDownFunc, 20);
|
|
73
|
+
return handleKeyDown;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
exports.useComboboxKeyboard = useComboboxKeyboard;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var floatingUi_react = require('../../../packages/react/node_modules/@floating-ui/react/dist/floating-ui.react.js');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var ReactDOM = require('react-dom');
|
|
7
|
+
var ComboboxIdContext = require('./ComboboxIdContext.js');
|
|
8
|
+
var floatingUi_dom = require('../../../packages/react/node_modules/@floating-ui/dom/dist/floating-ui.dom.js');
|
|
9
|
+
var floatingUi_core = require('../../../packages/react/node_modules/@floating-ui/core/dist/floating-ui.core.js');
|
|
10
|
+
|
|
11
|
+
const useFloatingCombobox = ({ listRef }) => {
|
|
12
|
+
const [open, setOpen] = React.useState(false);
|
|
13
|
+
const { activeIndex } = ComboboxIdContext.useComboboxId();
|
|
14
|
+
const dispatch = ComboboxIdContext.useComboboxIdDispatch();
|
|
15
|
+
// floating UI
|
|
16
|
+
const { refs, floatingStyles, context } = floatingUi_react.useFloating({
|
|
17
|
+
open,
|
|
18
|
+
onOpenChange: (newOpen) => {
|
|
19
|
+
if (!newOpen)
|
|
20
|
+
dispatch?.({ type: 'SET_ACTIVE_INDEX', payload: 0 });
|
|
21
|
+
ReactDOM.flushSync(() => {
|
|
22
|
+
if (refs.floating.current && !newOpen) {
|
|
23
|
+
refs.floating.current.scrollTop = 0;
|
|
24
|
+
}
|
|
25
|
+
setTimeout(() => {
|
|
26
|
+
setOpen(newOpen);
|
|
27
|
+
}, 1);
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
whileElementsMounted: (reference, floating, update) => {
|
|
31
|
+
floatingUi_dom.autoUpdate(reference, floating, update);
|
|
32
|
+
return () => {
|
|
33
|
+
floating.scrollTop = 0;
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
middleware: [
|
|
37
|
+
floatingUi_dom.flip({ padding: 10 }),
|
|
38
|
+
floatingUi_dom.size({
|
|
39
|
+
apply({ rects, elements }) {
|
|
40
|
+
requestAnimationFrame(() => {
|
|
41
|
+
Object.assign(elements.floating.style, {
|
|
42
|
+
width: `calc(${rects.reference.width}px - calc(var(--fds-spacing-2) * 2))`,
|
|
43
|
+
maxHeight: `200px`,
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
}),
|
|
48
|
+
floatingUi_core.offset(10),
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
const role = floatingUi_react.useRole(context, { role: 'listbox' });
|
|
52
|
+
const dismiss = floatingUi_react.useDismiss(context);
|
|
53
|
+
const listNav = floatingUi_react.useListNavigation(context, {
|
|
54
|
+
listRef,
|
|
55
|
+
activeIndex,
|
|
56
|
+
virtual: true,
|
|
57
|
+
scrollItemIntoView: true,
|
|
58
|
+
enabled: open,
|
|
59
|
+
focusItemOnHover: true,
|
|
60
|
+
onNavigate: (index) => {
|
|
61
|
+
dispatch?.({ type: 'SET_ACTIVE_INDEX', payload: index || 0 });
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
const { getReferenceProps, getFloatingProps, getItemProps } = floatingUi_react.useInteractions([role, dismiss, listNav]);
|
|
65
|
+
return {
|
|
66
|
+
open,
|
|
67
|
+
setOpen,
|
|
68
|
+
activeIndex,
|
|
69
|
+
refs,
|
|
70
|
+
floatingStyles,
|
|
71
|
+
context,
|
|
72
|
+
getReferenceProps,
|
|
73
|
+
getFloatingProps,
|
|
74
|
+
getItemProps,
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
exports.useFloatingCombobox = useFloatingCombobox;
|
|
@@ -5,7 +5,7 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var clsx = require('../../../node_modules/clsx/dist/clsx.js');
|
|
7
7
|
var akselIcons = require('@navikt/aksel-icons');
|
|
8
|
-
var floatingUi_react = require('../../../node_modules/@floating-ui/react/dist/floating-ui.react.js');
|
|
8
|
+
var floatingUi_react = require('../../../packages/react/node_modules/@floating-ui/react/dist/floating-ui.react.js');
|
|
9
9
|
var useSearch = require('./useSearch.js');
|
|
10
10
|
var Search_module = require('./Search.module.css.js');
|
|
11
11
|
var Button = require('../../Button/Button.js');
|
|
@@ -12,7 +12,7 @@ function getNodeName(node) {
|
|
|
12
12
|
}
|
|
13
13
|
function getWindow(node) {
|
|
14
14
|
var _node$ownerDocument;
|
|
15
|
-
return (node == null
|
|
15
|
+
return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
|
|
16
16
|
}
|
|
17
17
|
function getDocumentElement(node) {
|
|
18
18
|
var _ref;
|
|
@@ -111,18 +111,21 @@ function getNearestOverflowAncestor(node) {
|
|
|
111
111
|
}
|
|
112
112
|
return getNearestOverflowAncestor(parentNode);
|
|
113
113
|
}
|
|
114
|
-
function getOverflowAncestors(node, list) {
|
|
114
|
+
function getOverflowAncestors(node, list, traverseIframes) {
|
|
115
115
|
var _node$ownerDocument2;
|
|
116
116
|
if (list === void 0) {
|
|
117
117
|
list = [];
|
|
118
118
|
}
|
|
119
|
+
if (traverseIframes === void 0) {
|
|
120
|
+
traverseIframes = true;
|
|
121
|
+
}
|
|
119
122
|
const scrollableAncestor = getNearestOverflowAncestor(node);
|
|
120
123
|
const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
|
|
121
124
|
const win = getWindow(scrollableAncestor);
|
|
122
125
|
if (isBody) {
|
|
123
|
-
return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : []);
|
|
126
|
+
return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], win.frameElement && traverseIframes ? getOverflowAncestors(win.frameElement) : []);
|
|
124
127
|
}
|
|
125
|
-
return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor));
|
|
128
|
+
return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
|
|
126
129
|
}
|
|
127
130
|
|
|
128
131
|
exports.getComputedStyle = getComputedStyle;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
-
function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e))for(t=0;t<
|
|
6
|
+
function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
|
|
7
7
|
|
|
8
8
|
exports.clsx = clsx;
|
|
9
9
|
exports.default = clsx;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
function clsx(){for(var t,r=0,e="",n=arguments.length;r<n;r++)(t=arguments[r])&&"string"==typeof t&&(e+=(e&&" ")+t);return e}
|
|
7
|
+
|
|
8
|
+
exports.clsx = clsx;
|
|
9
|
+
exports.default = clsx;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
var floatingUi_utils = require('
|
|
4
|
+
var floatingUi_utils = require('../../../../../../node_modules/@floating-ui/utils/dist/floating-ui.utils.js');
|
|
5
5
|
|
|
6
6
|
function computeCoordsFromPlacement(_ref, placement, rtl) {
|
|
7
7
|
let {
|
|
@@ -61,7 +61,7 @@ function computeCoordsFromPlacement(_ref, placement, rtl) {
|
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* Computes the `x` and `y` coordinates that will place the floating element
|
|
64
|
-
* next to a reference element
|
|
64
|
+
* next to a given reference element.
|
|
65
65
|
*
|
|
66
66
|
* This export does not have any `platform` interface logic. You will need to
|
|
67
67
|
* write one for the platform you are using Floating UI with.
|
|
@@ -139,7 +139,6 @@ const computePosition = async (reference, floating, config) => {
|
|
|
139
139
|
} = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
|
|
140
140
|
}
|
|
141
141
|
i = -1;
|
|
142
|
-
continue;
|
|
143
142
|
}
|
|
144
143
|
}
|
|
145
144
|
return {
|
|
@@ -202,6 +201,7 @@ async function detectOverflow(state, options) {
|
|
|
202
201
|
y: 1
|
|
203
202
|
};
|
|
204
203
|
const elementClientRect = floatingUi_utils.rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
|
|
204
|
+
elements,
|
|
205
205
|
rect,
|
|
206
206
|
offsetParent,
|
|
207
207
|
strategy
|
|
@@ -229,7 +229,8 @@ const arrow = options => ({
|
|
|
229
229
|
placement,
|
|
230
230
|
rects,
|
|
231
231
|
platform,
|
|
232
|
-
elements
|
|
232
|
+
elements,
|
|
233
|
+
middlewareData
|
|
233
234
|
} = state;
|
|
234
235
|
// Since `element` is required, we don't Partial<> the type.
|
|
235
236
|
const {
|
|
@@ -277,16 +278,20 @@ const arrow = options => ({
|
|
|
277
278
|
|
|
278
279
|
// If the reference is small enough that the arrow's padding causes it to
|
|
279
280
|
// to point to nothing for an aligned placement, adjust the offset of the
|
|
280
|
-
// floating element itself.
|
|
281
|
-
//
|
|
282
|
-
const shouldAddOffset = floatingUi_utils.getAlignment(placement) != null && center
|
|
283
|
-
const alignmentOffset = shouldAddOffset ? center < min$1 ? min$1
|
|
281
|
+
// floating element itself. To ensure `shift()` continues to take action,
|
|
282
|
+
// a single reset is performed when this is true.
|
|
283
|
+
const shouldAddOffset = !middlewareData.arrow && floatingUi_utils.getAlignment(placement) != null && center !== offset && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
|
|
284
|
+
const alignmentOffset = shouldAddOffset ? center < min$1 ? center - min$1 : center - max : 0;
|
|
284
285
|
return {
|
|
285
|
-
[axis]: coords[axis]
|
|
286
|
+
[axis]: coords[axis] + alignmentOffset,
|
|
286
287
|
data: {
|
|
287
288
|
[axis]: offset,
|
|
288
|
-
centerOffset: center - offset
|
|
289
|
-
|
|
289
|
+
centerOffset: center - offset - alignmentOffset,
|
|
290
|
+
...(shouldAddOffset && {
|
|
291
|
+
alignmentOffset
|
|
292
|
+
})
|
|
293
|
+
},
|
|
294
|
+
reset: shouldAddOffset
|
|
290
295
|
};
|
|
291
296
|
}
|
|
292
297
|
});
|
|
@@ -305,7 +310,7 @@ const flip = function (options) {
|
|
|
305
310
|
name: 'flip',
|
|
306
311
|
options,
|
|
307
312
|
async fn(state) {
|
|
308
|
-
var _middlewareData$flip;
|
|
313
|
+
var _middlewareData$arrow, _middlewareData$flip;
|
|
309
314
|
const {
|
|
310
315
|
placement,
|
|
311
316
|
middlewareData,
|
|
@@ -323,6 +328,14 @@ const flip = function (options) {
|
|
|
323
328
|
flipAlignment = true,
|
|
324
329
|
...detectOverflowOptions
|
|
325
330
|
} = floatingUi_utils.evaluate(options, state);
|
|
331
|
+
|
|
332
|
+
// If a reset by the arrow was caused due to an alignment offset being
|
|
333
|
+
// added, we should skip any logic now since `flip()` has already done its
|
|
334
|
+
// work.
|
|
335
|
+
// https://github.com/floating-ui/floating-ui/issues/2549#issuecomment-1719601643
|
|
336
|
+
if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
|
|
337
|
+
return {};
|
|
338
|
+
}
|
|
326
339
|
const side = floatingUi_utils.getSide(placement);
|
|
327
340
|
const isBasePlacement = floatingUi_utils.getSide(initialPlacement) === initialPlacement;
|
|
328
341
|
const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
|
|
@@ -400,6 +413,7 @@ const flip = function (options) {
|
|
|
400
413
|
|
|
401
414
|
// For type backwards-compatibility, the `OffsetOptions` type was also
|
|
402
415
|
// Derivable.
|
|
416
|
+
|
|
403
417
|
async function convertValueToCoords(state, options) {
|
|
404
418
|
const {
|
|
405
419
|
placement,
|
|
@@ -413,8 +427,6 @@ async function convertValueToCoords(state, options) {
|
|
|
413
427
|
const mainAxisMulti = ['left', 'top'].includes(side) ? -1 : 1;
|
|
414
428
|
const crossAxisMulti = rtl && isVertical ? -1 : 1;
|
|
415
429
|
const rawValue = floatingUi_utils.evaluate(options, state);
|
|
416
|
-
|
|
417
|
-
// eslint-disable-next-line prefer-const
|
|
418
430
|
let {
|
|
419
431
|
mainAxis,
|
|
420
432
|
crossAxis,
|
|
@@ -456,15 +468,27 @@ const offset = function (options) {
|
|
|
456
468
|
name: 'offset',
|
|
457
469
|
options,
|
|
458
470
|
async fn(state) {
|
|
471
|
+
var _middlewareData$offse, _middlewareData$arrow;
|
|
459
472
|
const {
|
|
460
473
|
x,
|
|
461
|
-
y
|
|
474
|
+
y,
|
|
475
|
+
placement,
|
|
476
|
+
middlewareData
|
|
462
477
|
} = state;
|
|
463
478
|
const diffCoords = await convertValueToCoords(state, options);
|
|
479
|
+
|
|
480
|
+
// If the placement is the same and the arrow caused an alignment offset
|
|
481
|
+
// then we don't need to change the positioning coordinates.
|
|
482
|
+
if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
|
|
483
|
+
return {};
|
|
484
|
+
}
|
|
464
485
|
return {
|
|
465
486
|
x: x + diffCoords.x,
|
|
466
487
|
y: y + diffCoords.y,
|
|
467
|
-
data:
|
|
488
|
+
data: {
|
|
489
|
+
...diffCoords,
|
|
490
|
+
placement
|
|
491
|
+
}
|
|
468
492
|
};
|
|
469
493
|
}
|
|
470
494
|
};
|