@digdir/designsystemet-react 1.0.0-next.43 → 1.0.0-next.45
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/Combobox/Combobox.js +1 -1
- package/dist/cjs/{utilities/hooks → components/Combobox}/useFormField/useFormField.js +1 -1
- package/dist/cjs/components/Field/Field.js +2 -2
- package/dist/cjs/components/Pagination/usePagination.js +8 -8
- package/dist/cjs/components/Popover/PopoverTrigger.js +7 -3
- package/dist/cjs/components/Table/TableHeaderCell.js +1 -1
- package/dist/cjs/components/Tag/Tag.js +3 -3
- package/dist/cjs/components/Tooltip/Tooltip.js +65 -50
- package/dist/cjs/index.js +24 -14
- package/dist/cjs/utilities/hooks/useCheckboxGroup/useCheckboxGroup.js +121 -0
- package/dist/cjs/utilities/hooks/useMediaQuery/useMediaQuery.js +49 -0
- package/dist/cjs/utilities/hooks/usePrevious/usePrevious.js +14 -0
- package/dist/cjs/utilities/hooks/useRadioGroup/useRadioGroup.js +99 -0
- package/dist/esm/components/Combobox/Combobox.js +1 -1
- package/dist/esm/{utilities/hooks → components/Combobox}/useFormField/useFormField.js +1 -1
- package/dist/esm/components/Field/Field.js +2 -2
- package/dist/esm/components/Pagination/usePagination.js +8 -8
- package/dist/esm/components/Popover/PopoverTrigger.js +7 -3
- package/dist/esm/components/Table/TableHeaderCell.js +1 -1
- package/dist/esm/components/Tag/Tag.js +3 -3
- package/dist/esm/components/Tooltip/Tooltip.js +66 -51
- package/dist/esm/index.js +11 -6
- package/dist/esm/utilities/hooks/useCheckboxGroup/useCheckboxGroup.js +119 -0
- package/dist/esm/utilities/hooks/useMediaQuery/useMediaQuery.js +47 -0
- package/dist/esm/utilities/hooks/usePrevious/usePrevious.js +12 -0
- package/dist/esm/utilities/hooks/useRadioGroup/useRadioGroup.js +97 -0
- package/dist/types/components/Alert/Alert.d.ts +6 -269
- package/dist/types/components/Alert/Alert.d.ts.map +1 -1
- package/dist/types/components/Avatar/Avatar.d.ts +23 -275
- package/dist/types/components/Avatar/Avatar.d.ts.map +1 -1
- package/dist/types/components/Badge/Badge.d.ts +10 -276
- package/dist/types/components/Badge/Badge.d.ts.map +1 -1
- package/dist/types/components/Badge/BadgePosition.d.ts +13 -271
- package/dist/types/components/Badge/BadgePosition.d.ts.map +1 -1
- package/dist/types/components/Badge/index.d.ts +7 -542
- package/dist/types/components/Badge/index.d.ts.map +1 -1
- package/dist/types/components/Breadcrumbs/Breadcrumbs.d.ts +6 -269
- package/dist/types/components/Breadcrumbs/Breadcrumbs.d.ts.map +1 -1
- package/dist/types/components/Breadcrumbs/BreadcrumbsLink.d.ts +4 -277
- package/dist/types/components/Breadcrumbs/BreadcrumbsLink.d.ts.map +1 -1
- package/dist/types/components/Breadcrumbs/index.d.ts +6 -546
- package/dist/types/components/Breadcrumbs/index.d.ts.map +1 -1
- package/dist/types/components/Button/Button.d.ts +23 -287
- package/dist/types/components/Button/Button.d.ts.map +1 -1
- package/dist/types/components/Card/Card.d.ts +9 -271
- package/dist/types/components/Card/Card.d.ts.map +1 -1
- package/dist/types/components/Card/index.d.ts +3 -269
- package/dist/types/components/Card/index.d.ts.map +1 -1
- package/dist/types/components/Checkbox/Checkbox.d.ts +0 -5
- package/dist/types/components/Checkbox/Checkbox.d.ts.map +1 -1
- package/dist/types/components/Chip/Chips.d.ts +4 -1166
- package/dist/types/components/Chip/Chips.d.ts.map +1 -1
- package/dist/types/components/Chip/index.d.ts +8 -1158
- package/dist/types/components/Chip/index.d.ts.map +1 -1
- package/dist/types/components/Combobox/Combobox.d.ts +24 -7
- package/dist/types/components/Combobox/Combobox.d.ts.map +1 -1
- package/dist/types/components/Combobox/ComboboxContext.d.ts +1 -1
- package/dist/types/components/Combobox/ComboboxContext.d.ts.map +1 -1
- package/dist/types/components/Combobox/internal/ComboboxError.d.ts +1 -1
- package/dist/types/components/Combobox/internal/ComboboxError.d.ts.map +1 -1
- package/dist/types/components/Combobox/internal/ComboboxLabel.d.ts +1 -1
- package/dist/types/components/Combobox/internal/ComboboxLabel.d.ts.map +1 -1
- package/dist/types/components/{Fieldset → Combobox/useFormField}/FieldsetContext.d.ts +1 -1
- package/dist/types/components/Combobox/useFormField/FieldsetContext.d.ts.map +1 -0
- package/dist/types/components/Combobox/useFormField/useFormField.d.ts.map +1 -0
- package/dist/types/components/Details/Details.d.ts +10 -2
- package/dist/types/components/Details/Details.d.ts.map +1 -1
- package/dist/types/components/Dropdown/Dropdown.d.ts +5 -279
- package/dist/types/components/Dropdown/Dropdown.d.ts.map +1 -1
- package/dist/types/components/Dropdown/DropdownHeading.d.ts +1 -1
- package/dist/types/components/Dropdown/DropdownTrigger.d.ts +1 -284
- package/dist/types/components/Dropdown/DropdownTrigger.d.ts.map +1 -1
- package/dist/types/components/Dropdown/index.d.ts +4 -560
- package/dist/types/components/Dropdown/index.d.ts.map +1 -1
- package/dist/types/components/ErrorSummary/ErrorSummaryHeading.d.ts +1 -1
- package/dist/types/components/ErrorSummary/index.d.ts +1 -1
- package/dist/types/components/Field/Field.d.ts.map +1 -1
- package/dist/types/components/Field/FieldCounter.d.ts +3 -270
- package/dist/types/components/Field/FieldCounter.d.ts.map +1 -1
- package/dist/types/components/Field/index.d.ts +3 -270
- package/dist/types/components/Field/index.d.ts.map +1 -1
- package/dist/types/components/Fieldset/FieldsetDescription.d.ts +1 -1
- package/dist/types/components/Fieldset/index.d.ts +1 -1
- package/dist/types/components/Heading/Heading.d.ts +2 -2
- package/dist/types/components/Heading/Heading.d.ts.map +1 -1
- package/dist/types/components/HelpText/HelpText.d.ts +9 -278
- package/dist/types/components/HelpText/HelpText.d.ts.map +1 -1
- package/dist/types/components/Input/Input.d.ts +12 -303
- package/dist/types/components/Input/Input.d.ts.map +1 -1
- package/dist/types/components/Link/Link.d.ts +11 -283
- package/dist/types/components/Link/Link.d.ts.map +1 -1
- package/dist/types/components/Modal/Modal.d.ts +16 -275
- package/dist/types/components/Modal/Modal.d.ts.map +1 -1
- package/dist/types/components/Modal/ModalTrigger.d.ts +5 -282
- package/dist/types/components/Modal/ModalTrigger.d.ts.map +1 -1
- package/dist/types/components/Modal/index.d.ts +10 -557
- package/dist/types/components/Modal/index.d.ts.map +1 -1
- package/dist/types/components/Pagination/Pagination.d.ts +10 -274
- package/dist/types/components/Pagination/Pagination.d.ts.map +1 -1
- package/dist/types/components/Pagination/PaginationButton.d.ts +1 -284
- package/dist/types/components/Pagination/PaginationButton.d.ts.map +1 -1
- package/dist/types/components/Pagination/index.d.ts +4 -554
- package/dist/types/components/Pagination/index.d.ts.map +1 -1
- package/dist/types/components/Pagination/usePagination.d.ts +1 -1
- package/dist/types/components/Pagination/usePagination.d.ts.map +1 -1
- package/dist/types/components/Paragraph/Paragraph.d.ts +2 -2
- package/dist/types/components/Paragraph/Paragraph.d.ts.map +1 -1
- package/dist/types/components/Popover/Popover.d.ts +28 -279
- package/dist/types/components/Popover/Popover.d.ts.map +1 -1
- package/dist/types/components/Popover/PopoverTrigger.d.ts +9 -285
- package/dist/types/components/Popover/PopoverTrigger.d.ts.map +1 -1
- package/dist/types/components/Radio/Radio.d.ts +0 -5
- package/dist/types/components/Radio/Radio.d.ts.map +1 -1
- package/dist/types/components/Search/SearchButton.d.ts +5 -282
- package/dist/types/components/Search/SearchButton.d.ts.map +1 -1
- package/dist/types/components/Search/SearchClear.d.ts +1 -284
- package/dist/types/components/Search/SearchClear.d.ts.map +1 -1
- package/dist/types/components/Search/index.d.ts +6 -566
- package/dist/types/components/Search/index.d.ts.map +1 -1
- package/dist/types/components/Select/Select.d.ts +9 -277
- package/dist/types/components/Select/Select.d.ts.map +1 -1
- package/dist/types/components/Select/index.d.ts +3 -277
- package/dist/types/components/Select/index.d.ts.map +1 -1
- package/dist/types/components/SkipLink/SkipLink.d.ts +3 -275
- package/dist/types/components/SkipLink/SkipLink.d.ts.map +1 -1
- package/dist/types/components/Spinner/Spinner.d.ts +1 -6
- package/dist/types/components/Spinner/Spinner.d.ts.map +1 -1
- package/dist/types/components/Switch/Switch.d.ts +0 -10
- package/dist/types/components/Switch/Switch.d.ts.map +1 -1
- package/dist/types/components/Table/TableHeaderCell.d.ts.map +1 -1
- package/dist/types/components/Tabs/Tabs.d.ts +7 -274
- package/dist/types/components/Tabs/Tabs.d.ts.map +1 -1
- package/dist/types/components/Tabs/index.d.ts +4 -270
- package/dist/types/components/Tabs/index.d.ts.map +1 -1
- package/dist/types/components/Tag/Tag.d.ts +3 -280
- package/dist/types/components/Tag/Tag.d.ts.map +1 -1
- package/dist/types/components/ToggleGroup/ToggleGroup.d.ts +9 -275
- package/dist/types/components/ToggleGroup/ToggleGroup.d.ts.map +1 -1
- package/dist/types/components/ToggleGroup/ToggleGroupItem.d.ts +1 -284
- package/dist/types/components/ToggleGroup/ToggleGroupItem.d.ts.map +1 -1
- package/dist/types/components/Tooltip/Tooltip.d.ts +20 -284
- package/dist/types/components/Tooltip/Tooltip.d.ts.map +1 -1
- package/dist/types/components/ValidationMessage/ValidationMessage.d.ts +11 -270
- package/dist/types/components/ValidationMessage/ValidationMessage.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +6 -11
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utilities/hooks/index.d.ts +2 -2
- package/dist/types/utilities/hooks/index.d.ts.map +1 -1
- package/dist/types/utilities/hooks/useCheckboxGroup/useCheckboxGroup.d.ts +3 -3
- package/dist/types/utilities/hooks/useRadioGroup/useRadioGroup.d.ts +3 -3
- package/dist/types/utilities/types.d.ts +1 -5
- package/dist/types/utilities/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/types/components/Fieldset/FieldsetContext.d.ts.map +0 -1
- package/dist/types/components/Textarea/useTextarea.d.ts +0 -10
- package/dist/types/components/Textarea/useTextarea.d.ts.map +0 -1
- package/dist/types/utilities/hooks/useFormField/useFormField.d.ts.map +0 -1
- /package/dist/cjs/components/{Fieldset → Combobox/useFormField}/FieldsetContext.js +0 -0
- /package/dist/esm/components/{Fieldset → Combobox/useFormField}/FieldsetContext.js +0 -0
- /package/dist/types/{utilities/hooks → components/Combobox}/useFormField/useFormField.d.ts +0 -0
|
@@ -6,7 +6,7 @@ var react$1 = require('@floating-ui/react');
|
|
|
6
6
|
var reactVirtual = require('@tanstack/react-virtual');
|
|
7
7
|
var cl = require('clsx/lite');
|
|
8
8
|
var react = require('react');
|
|
9
|
-
var useFormField = require('
|
|
9
|
+
var useFormField = require('./useFormField/useFormField.js');
|
|
10
10
|
var ComboboxContext = require('./ComboboxContext.js');
|
|
11
11
|
var ComboboxIdContext = require('./ComboboxIdContext.js');
|
|
12
12
|
var Custom = require('./Custom.js');
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
var cl = require('clsx/lite');
|
|
5
5
|
var react = require('react');
|
|
6
|
-
var FieldsetContext = require('
|
|
6
|
+
var FieldsetContext = require('./FieldsetContext.js');
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Handles props and their state for various form-fields in context with Fieldset
|
|
@@ -7,11 +7,11 @@ var cl = require('clsx/lite');
|
|
|
7
7
|
var react = require('react');
|
|
8
8
|
var fieldObserver = require('./fieldObserver.js');
|
|
9
9
|
|
|
10
|
-
const Field = react.forwardRef(function Field({ className, ...rest }, ref) {
|
|
10
|
+
const Field = react.forwardRef(function Field({ className, position, ...rest }, ref) {
|
|
11
11
|
const fieldRef = react.useRef(null);
|
|
12
12
|
const mergedRefs = react$1.useMergeRefs([fieldRef, ref]);
|
|
13
13
|
react.useEffect(() => fieldObserver.fieldObserver(fieldRef.current), []);
|
|
14
|
-
return (jsxRuntime.jsx("div", { className: cl('ds-field', className), ref: mergedRefs, ...rest }));
|
|
14
|
+
return (jsxRuntime.jsx("div", { className: cl('ds-field', className), "data-position": position, ref: mergedRefs, ...rest }));
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
exports.Field = Field;
|
|
@@ -28,15 +28,15 @@ const usePagination = ({ currentPage = 1, setCurrentPage, onChange, totalPages,
|
|
|
28
28
|
return {
|
|
29
29
|
/** Number of steps */
|
|
30
30
|
pages: getSteps(currentPage, totalPages, showPages).map((page, index) => ({
|
|
31
|
-
page: page || '',
|
|
31
|
+
page: page || 'ellipsis',
|
|
32
32
|
itemKey: page ? `page-${page}` : `ellipsis-${index}`, // React key utility
|
|
33
|
-
buttonProps:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
buttonProps: (page
|
|
34
|
+
? {
|
|
35
|
+
'aria-current': page === currentPage ? 'page' : undefined,
|
|
36
|
+
onClick: handleClick(page),
|
|
37
|
+
variant: page === currentPage ? 'primary' : 'tertiary',
|
|
38
|
+
}
|
|
39
|
+
: null),
|
|
40
40
|
})),
|
|
41
41
|
/** Properties to spread on Pagination.Button used for previous naviagation */
|
|
42
42
|
prevButtonProps: {
|
|
@@ -7,10 +7,14 @@ var react = require('react');
|
|
|
7
7
|
var Button = require('../Button/Button.js');
|
|
8
8
|
var PopoverTriggerContext = require('./PopoverTriggerContext.js');
|
|
9
9
|
|
|
10
|
-
const PopoverTrigger = react.forwardRef(function PopoverTrigger({ id, asChild, ...rest }, ref) {
|
|
10
|
+
const PopoverTrigger = react.forwardRef(function PopoverTrigger({ id, inline, asChild, ...rest }, ref) {
|
|
11
11
|
const { popoverId } = react.useContext(PopoverTriggerContext.Context);
|
|
12
|
-
const Component = asChild ? reactSlot.Slot : Button.Button;
|
|
13
|
-
return jsxRuntime.jsx(Component, { ref: ref, popovertarget: popoverId, ...
|
|
12
|
+
const Component = asChild ? reactSlot.Slot : inline ? 'button' : Button.Button;
|
|
13
|
+
return (jsxRuntime.jsx(Component, { ref: ref, popovertarget: popoverId, ...(inline
|
|
14
|
+
? {
|
|
15
|
+
'data-popover': 'inline',
|
|
16
|
+
}
|
|
17
|
+
: {}), ...rest }));
|
|
14
18
|
});
|
|
15
19
|
|
|
16
20
|
exports.PopoverTrigger = PopoverTrigger;
|
|
@@ -5,7 +5,7 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
5
5
|
var react = require('react');
|
|
6
6
|
|
|
7
7
|
const TableHeaderCell = react.forwardRef(function TableHeaderCell({ sort, children, ...rest }, ref) {
|
|
8
|
-
return (jsxRuntime.jsx("th", { "aria-sort": sort, ref: ref, ...rest, children: sort ?
|
|
8
|
+
return (jsxRuntime.jsx("th", { "aria-sort": sort, ref: ref, ...rest, children: sort ? jsxRuntime.jsx("button", { type: 'button', children: children }) : children }));
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
exports.TableHeaderCell = TableHeaderCell;
|
|
@@ -8,10 +8,10 @@ var react = require('react');
|
|
|
8
8
|
/**
|
|
9
9
|
* Use `Tag` to display a small piece of information.
|
|
10
10
|
* @example
|
|
11
|
-
* <Tag
|
|
11
|
+
* <Tag>Success</Tag>
|
|
12
12
|
*/
|
|
13
|
-
const Tag = react.forwardRef(function Tag({
|
|
14
|
-
return
|
|
13
|
+
const Tag = react.forwardRef(function Tag({ className, ...rest }, ref) {
|
|
14
|
+
return jsxRuntime.jsx("span", { className: cl('ds-tag', className), ref: ref, ...rest });
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
exports.Tag = Tag;
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
-
var
|
|
5
|
+
var dom = require('@floating-ui/dom');
|
|
6
6
|
var reactSlot = require('@radix-ui/react-slot');
|
|
7
7
|
var cl = require('clsx/lite');
|
|
8
8
|
var react = require('react');
|
|
9
|
+
var react$1 = require('@floating-ui/react');
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Tooltip component that displays a small piece of information when hovering or focusing on an element.
|
|
@@ -19,46 +20,61 @@ var react = require('react');
|
|
|
19
20
|
* Hover me
|
|
20
21
|
* </Tooltip>
|
|
21
22
|
*/
|
|
22
|
-
const Tooltip = react.forwardRef(function Tooltip({ children, content, placement = 'top',
|
|
23
|
-
const
|
|
24
|
-
const internalOpen =
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
23
|
+
const Tooltip = react.forwardRef(function Tooltip({ id, children, content, placement = 'top', open, className, ...rest }, ref) {
|
|
24
|
+
const randomTooltipId = react.useId();
|
|
25
|
+
const [internalOpen, setInternalOpen] = react.useState(false);
|
|
26
|
+
const triggerRef = react.useRef(null);
|
|
27
|
+
const tooltipRef = react.useRef(null);
|
|
28
|
+
const mergedRefs = react$1.useMergeRefs([tooltipRef, ref]);
|
|
29
|
+
const controlledOpen = open ?? internalOpen;
|
|
30
|
+
const setOpen = () => {
|
|
31
|
+
setInternalOpen(true);
|
|
32
|
+
};
|
|
33
|
+
const setClose = () => {
|
|
34
|
+
setInternalOpen(false);
|
|
35
|
+
};
|
|
36
|
+
// Position with floating-ui
|
|
37
|
+
react.useEffect(() => {
|
|
38
|
+
const tooltip = tooltipRef.current;
|
|
39
|
+
const trigger = triggerRef.current;
|
|
40
|
+
tooltip?.togglePopover?.(controlledOpen);
|
|
41
|
+
if (tooltip)
|
|
42
|
+
tooltip.style.opacity = controlledOpen ? '1' : '0';
|
|
43
|
+
if (tooltip && trigger && controlledOpen) {
|
|
44
|
+
return dom.autoUpdate(trigger, tooltip, () => {
|
|
45
|
+
dom.computePosition(trigger, tooltip, {
|
|
46
|
+
placement,
|
|
47
|
+
strategy: 'fixed',
|
|
48
|
+
middleware: [
|
|
49
|
+
dom.offset((data) => {
|
|
50
|
+
// get pseudo element arrow size
|
|
51
|
+
const styles = getComputedStyle(data.elements.floating, '::before');
|
|
52
|
+
return parseFloat(styles.height);
|
|
53
|
+
}),
|
|
54
|
+
dom.flip({
|
|
55
|
+
fallbackAxisSideDirection: 'start',
|
|
56
|
+
}),
|
|
57
|
+
dom.shift(),
|
|
58
|
+
arrowPseudoElement,
|
|
59
|
+
],
|
|
60
|
+
}).then(({ x, y }) => {
|
|
61
|
+
tooltip.style.translate = `${x}px ${y}px`;
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}, [controlledOpen, placement]);
|
|
66
|
+
/* Add listener for ESC to dismiss */
|
|
67
|
+
react.useEffect(() => {
|
|
68
|
+
const handleKeyDown = (event) => {
|
|
69
|
+
if (event.key === 'Escape') {
|
|
70
|
+
setInternalOpen(false);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
74
|
+
return () => {
|
|
75
|
+
window.removeEventListener('keydown', handleKeyDown);
|
|
76
|
+
};
|
|
77
|
+
}, []);
|
|
62
78
|
/* If children is only a string, make a span */
|
|
63
79
|
const ChildContainer = typeof children === 'string' ? 'span' : reactSlot.Slot;
|
|
64
80
|
/* Make sure it is valid */
|
|
@@ -66,13 +82,12 @@ const Tooltip = react.forwardRef(function Tooltip({ children, content, placement
|
|
|
66
82
|
console.error('<Tooltip> children needs to be a single ReactElement that can receive a ref and not: <Fragment/> | <></>');
|
|
67
83
|
return null;
|
|
68
84
|
}
|
|
69
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(ChildContainer, {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}), children: content }) }))] }));
|
|
85
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(ChildContainer, { ref: triggerRef, popovertarget: id ?? randomTooltipId,
|
|
86
|
+
// We set this to not close on click, since it should always show on hover
|
|
87
|
+
// @ts-ignore @types/react-dom does not understand popovertargetaction yet
|
|
88
|
+
popovertargetaction: 'show', onMouseEnter: setOpen, onMouseLeave: setClose, onFocus: setOpen, onBlur: setClose, children: children }), jsxRuntime.jsx("div", { ref: mergedRefs, role: 'tooltip', className: cl('ds-tooltip', className), id: id ?? randomTooltipId,
|
|
89
|
+
// @ts-ignore @types/react-dom does not understand popover yet
|
|
90
|
+
popover: 'manual', ...rest, children: content })] }));
|
|
76
91
|
});
|
|
77
92
|
const arrowPseudoElement = {
|
|
78
93
|
name: 'ArrowPseudoElement',
|
|
@@ -94,8 +109,8 @@ const arrowPseudoElement = {
|
|
|
94
109
|
arrowX = '100%';
|
|
95
110
|
break;
|
|
96
111
|
}
|
|
97
|
-
elements.floating.style.setProperty('--
|
|
98
|
-
elements.floating.style.setProperty('--
|
|
112
|
+
elements.floating.style.setProperty('--dsc-tooltip-arrow-x', arrowX);
|
|
113
|
+
elements.floating.style.setProperty('--dsc-tooltip-arrow-y', arrowY);
|
|
99
114
|
return data;
|
|
100
115
|
},
|
|
101
116
|
};
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
var useSynchronizedAnimation = require('./utilities/hooks/useSynchronizedAnimation/useSynchronizedAnimation.js');
|
|
5
|
-
var useIsomorphicLayoutEffect = require('./utilities/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js');
|
|
6
|
-
var RovingFocusRoot = require('./utilities/RovingFocus/RovingFocusRoot.js');
|
|
7
|
-
var useRovingFocus = require('./utilities/RovingFocus/useRovingFocus.js');
|
|
8
|
-
var RovingFocusItem = require('./utilities/RovingFocus/RovingFocusItem.js');
|
|
9
|
-
var omit = require('./utilities/omit/omit.js');
|
|
10
4
|
var Avatar = require('./components/Avatar/Avatar.js');
|
|
11
5
|
var Button = require('./components/Button/Button.js');
|
|
12
6
|
var index = require('./components/Badge/index.js');
|
|
@@ -97,17 +91,20 @@ var index$i = require('./components/ErrorSummary/index.js');
|
|
|
97
91
|
var ErrorSummaryItem = require('./components/ErrorSummary/ErrorSummaryItem.js');
|
|
98
92
|
var ErrorSummaryHeading = require('./components/ErrorSummary/ErrorSummaryHeading.js');
|
|
99
93
|
var ErrorSummaryList = require('./components/ErrorSummary/ErrorSummaryList.js');
|
|
94
|
+
var omit = require('./utilities/omit/omit.js');
|
|
95
|
+
var useCheckboxGroup = require('./utilities/hooks/useCheckboxGroup/useCheckboxGroup.js');
|
|
96
|
+
var useDebounceCallback = require('./utilities/hooks/useDebounceCallback/useDebounceCallback.js');
|
|
97
|
+
var useIsomorphicLayoutEffect = require('./utilities/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js');
|
|
98
|
+
var useMediaQuery = require('./utilities/hooks/useMediaQuery/useMediaQuery.js');
|
|
99
|
+
var usePrevious = require('./utilities/hooks/usePrevious/usePrevious.js');
|
|
100
|
+
var useRadioGroup = require('./utilities/hooks/useRadioGroup/useRadioGroup.js');
|
|
101
|
+
var useSynchronizedAnimation = require('./utilities/hooks/useSynchronizedAnimation/useSynchronizedAnimation.js');
|
|
102
|
+
var RovingFocusRoot = require('./utilities/RovingFocus/RovingFocusRoot.js');
|
|
103
|
+
var useRovingFocus = require('./utilities/RovingFocus/useRovingFocus.js');
|
|
104
|
+
var RovingFocusItem = require('./utilities/RovingFocus/RovingFocusItem.js');
|
|
100
105
|
|
|
101
106
|
|
|
102
107
|
|
|
103
|
-
exports.useSynchronizedAnimation = useSynchronizedAnimation.useSynchronizedAnimation;
|
|
104
|
-
exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect.useIsomorphicLayoutEffect;
|
|
105
|
-
exports.RovingFocusRoot = RovingFocusRoot.RovingFocusRoot;
|
|
106
|
-
exports.useRovingFocus = useRovingFocus.useRovingFocus;
|
|
107
|
-
exports.RovingFocusItem = RovingFocusItem.RovingFocusItem;
|
|
108
|
-
exports.getNextFocusableValue = RovingFocusItem.getNextFocusableValue;
|
|
109
|
-
exports.getPrevFocusableValue = RovingFocusItem.getPrevFocusableValue;
|
|
110
|
-
exports.omit = omit.omit;
|
|
111
108
|
exports.Avatar = Avatar.Avatar;
|
|
112
109
|
exports.Button = Button.Button;
|
|
113
110
|
exports.Badge = index.Badge;
|
|
@@ -203,3 +200,16 @@ exports.ErrorSummary = index$i.ErrorSummary;
|
|
|
203
200
|
exports.ErrorSummaryItem = ErrorSummaryItem.ErrorSummaryItem;
|
|
204
201
|
exports.ErrorSummaryHeading = ErrorSummaryHeading.ErrorSummaryHeading;
|
|
205
202
|
exports.ErrorSummaryList = ErrorSummaryList.ErrorSummaryList;
|
|
203
|
+
exports.omit = omit.omit;
|
|
204
|
+
exports.useCheckboxGroup = useCheckboxGroup.useCheckboxGroup;
|
|
205
|
+
exports.useDebounceCallback = useDebounceCallback.useDebounceCallback;
|
|
206
|
+
exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect.useIsomorphicLayoutEffect;
|
|
207
|
+
exports.useMediaQuery = useMediaQuery.useMediaQuery;
|
|
208
|
+
exports.usePrevious = usePrevious.usePrevious;
|
|
209
|
+
exports.useRadioGroup = useRadioGroup.useRadioGroup;
|
|
210
|
+
exports.useSynchronizedAnimation = useSynchronizedAnimation.useSynchronizedAnimation;
|
|
211
|
+
exports.RovingFocusRoot = RovingFocusRoot.RovingFocusRoot;
|
|
212
|
+
exports.useRovingFocus = useRovingFocus.useRovingFocus;
|
|
213
|
+
exports.RovingFocusItem = RovingFocusItem.RovingFocusItem;
|
|
214
|
+
exports.getNextFocusableValue = RovingFocusItem.getNextFocusableValue;
|
|
215
|
+
exports.getPrevFocusableValue = RovingFocusItem.getPrevFocusableValue;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var react$1 = require('@floating-ui/react');
|
|
5
|
+
var react = require('react');
|
|
6
|
+
|
|
7
|
+
const toggleIndeterminate = (getIndeterminateInputs, getInputs) => {
|
|
8
|
+
const inputs = getIndeterminateInputs();
|
|
9
|
+
const checked = !!getInputs(true).length;
|
|
10
|
+
const unchecked = !!getInputs(false).length;
|
|
11
|
+
for (const input of inputs) {
|
|
12
|
+
input.indeterminate = unchecked && checked;
|
|
13
|
+
input.checked = !unchecked && checked;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
function useCheckboxGroup(props) {
|
|
17
|
+
const { error, name: groupName, onChange, value = [], disabled, readOnly, required, } = props || {};
|
|
18
|
+
const [groupValue, setGroupValue] = react.useState(value);
|
|
19
|
+
const namedId = react.useId();
|
|
20
|
+
const errorId = react.useId();
|
|
21
|
+
const checkboxRefs = react.useRef(new Set());
|
|
22
|
+
const indeterminateRefs = react.useRef(new Set());
|
|
23
|
+
const getInputs = (checked) => Array.from(checkboxRefs.current.values()).filter((input) => input.checked === checked);
|
|
24
|
+
const getIndeterminateInputs = () => Array.from(indeterminateRefs.current.values());
|
|
25
|
+
return {
|
|
26
|
+
/**
|
|
27
|
+
* Current value of the group.
|
|
28
|
+
*/
|
|
29
|
+
value: groupValue,
|
|
30
|
+
/**
|
|
31
|
+
* Set the value of the group.
|
|
32
|
+
*
|
|
33
|
+
* @param value string[]
|
|
34
|
+
* @returns void
|
|
35
|
+
*/
|
|
36
|
+
setValue: setGroupValue,
|
|
37
|
+
/**
|
|
38
|
+
* Props to send to the `Checkbox` component.
|
|
39
|
+
* Accepts value or object
|
|
40
|
+
* @example
|
|
41
|
+
* <Checkbox {...getCheckboxProps('value')} />
|
|
42
|
+
*
|
|
43
|
+
* @example allow indeterminate
|
|
44
|
+
* <Checkbox {...getCheckboxProps({ value: 'all', allowIndeterminate: true })} />
|
|
45
|
+
*/
|
|
46
|
+
getCheckboxProps: (propsOrValue) => {
|
|
47
|
+
const props = typeof propsOrValue === 'string'
|
|
48
|
+
? { value: propsOrValue }
|
|
49
|
+
: propsOrValue || {};
|
|
50
|
+
const { allowIndeterminate = false, ref = undefined, value = '', ...rest } = props;
|
|
51
|
+
const inputRef = react.useRef(null);
|
|
52
|
+
const mergedRefs = react$1.useMergeRefs([ref, inputRef]);
|
|
53
|
+
const handleChange = () => {
|
|
54
|
+
const nextGroupValue = Array.from(getInputs(true), ({ value }) => value);
|
|
55
|
+
setGroupValue(nextGroupValue);
|
|
56
|
+
onChange?.(nextGroupValue, groupValue);
|
|
57
|
+
};
|
|
58
|
+
const indeterminateChange = () => {
|
|
59
|
+
if (!inputRef.current)
|
|
60
|
+
return;
|
|
61
|
+
const checked = !!inputRef.current.checked;
|
|
62
|
+
for (const input of getInputs(!checked)) {
|
|
63
|
+
/* We use click to send both event and change checked state */
|
|
64
|
+
input.click();
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
react.useEffect(() => {
|
|
68
|
+
if (!allowIndeterminate)
|
|
69
|
+
return;
|
|
70
|
+
toggleIndeterminate(getIndeterminateInputs, getInputs);
|
|
71
|
+
}, [groupValue]);
|
|
72
|
+
react.useEffect(() => {
|
|
73
|
+
if (!inputRef.current)
|
|
74
|
+
return;
|
|
75
|
+
const input = inputRef.current;
|
|
76
|
+
const refs = allowIndeterminate ? indeterminateRefs : checkboxRefs;
|
|
77
|
+
refs.current.add(input);
|
|
78
|
+
if (getIndeterminateInputs().length)
|
|
79
|
+
toggleIndeterminate(getIndeterminateInputs, getInputs);
|
|
80
|
+
return () => {
|
|
81
|
+
refs.current.delete(input);
|
|
82
|
+
};
|
|
83
|
+
}, [value]);
|
|
84
|
+
return {
|
|
85
|
+
/* Spread anything the user has set first */
|
|
86
|
+
...rest,
|
|
87
|
+
/* Concat ours with the user prop */
|
|
88
|
+
'aria-describedby': `${error ? errorId : ''} ${rest['aria-describedby'] || ''}`.trim() ||
|
|
89
|
+
undefined,
|
|
90
|
+
'aria-invalid': !!error || rest['aria-invalid'],
|
|
91
|
+
checked: allowIndeterminate ? undefined : groupValue.includes(value),
|
|
92
|
+
name: rest.name || groupName || namedId,
|
|
93
|
+
onChange: (e) => {
|
|
94
|
+
rest.onChange?.(e);
|
|
95
|
+
if (e.defaultPrevented)
|
|
96
|
+
return;
|
|
97
|
+
allowIndeterminate && indeterminateChange();
|
|
98
|
+
handleChange();
|
|
99
|
+
},
|
|
100
|
+
ref: mergedRefs,
|
|
101
|
+
value,
|
|
102
|
+
disabled: disabled || rest.disabled,
|
|
103
|
+
readOnly: readOnly || rest.readOnly,
|
|
104
|
+
required: required || rest.required,
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
/**
|
|
108
|
+
* Props to send to the `ValidationMessage` component.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* <ValidationMessage {...validationMessageProps} />
|
|
112
|
+
*/
|
|
113
|
+
validationMessageProps: {
|
|
114
|
+
children: error,
|
|
115
|
+
hidden: !error,
|
|
116
|
+
id: errorId,
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
exports.useCheckboxGroup = useCheckboxGroup;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var useIsomorphicLayoutEffect = require('../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js');
|
|
6
|
+
|
|
7
|
+
// from https://usehooks-ts.com/react-hook/use-media-query
|
|
8
|
+
const IS_SERVER = typeof window === 'undefined';
|
|
9
|
+
function useMediaQuery(query, { defaultValue = false, initializeWithValue = true, } = {}) {
|
|
10
|
+
const getMatches = (query) => {
|
|
11
|
+
if (IS_SERVER) {
|
|
12
|
+
return defaultValue;
|
|
13
|
+
}
|
|
14
|
+
return window.matchMedia(query).matches;
|
|
15
|
+
};
|
|
16
|
+
const [matches, setMatches] = react.useState(() => {
|
|
17
|
+
if (initializeWithValue) {
|
|
18
|
+
return getMatches(query);
|
|
19
|
+
}
|
|
20
|
+
return defaultValue;
|
|
21
|
+
});
|
|
22
|
+
// Handles the change event of the media query.
|
|
23
|
+
function handleChange() {
|
|
24
|
+
setMatches(getMatches(query));
|
|
25
|
+
}
|
|
26
|
+
useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(() => {
|
|
27
|
+
const matchMedia = window.matchMedia(query);
|
|
28
|
+
// Triggered at the first client-side load and if query changes
|
|
29
|
+
handleChange();
|
|
30
|
+
// Use deprecated `addListener` and `removeListener` to support Safari < 14 (#135)
|
|
31
|
+
if (matchMedia.addListener) {
|
|
32
|
+
matchMedia.addListener(handleChange);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
matchMedia.addEventListener('change', handleChange);
|
|
36
|
+
}
|
|
37
|
+
return () => {
|
|
38
|
+
if (matchMedia.removeListener) {
|
|
39
|
+
matchMedia.removeListener(handleChange);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
matchMedia.removeEventListener('change', handleChange);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}, [query]);
|
|
46
|
+
return matches;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
exports.useMediaQuery = useMediaQuery;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var react = require('react');
|
|
5
|
+
|
|
6
|
+
function usePrevious(value) {
|
|
7
|
+
const ref = react.useRef();
|
|
8
|
+
react.useEffect(() => {
|
|
9
|
+
ref.current = value;
|
|
10
|
+
}, [value]);
|
|
11
|
+
return ref.current;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.usePrevious = usePrevious;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var react$1 = require('@floating-ui/react');
|
|
5
|
+
var react = require('react');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* useRadioGroup is used to group multiple <Radio> components
|
|
9
|
+
* @example
|
|
10
|
+
* const { getRadioProps, validationMessageProps, value, setValue } = useRadioGroup({
|
|
11
|
+
* disabled: false,
|
|
12
|
+
* error: 'Validation message text',
|
|
13
|
+
* name: 'group-name',
|
|
14
|
+
* onChange: (nextValue, prevValue) => {},
|
|
15
|
+
* readOnly: false,
|
|
16
|
+
* required: true,
|
|
17
|
+
* value: '',
|
|
18
|
+
* });
|
|
19
|
+
*/
|
|
20
|
+
function useRadioGroup({ error, readOnly, required, disabled, name, onChange, value: initalValue = '', } = {}) {
|
|
21
|
+
const [groupValue, setGroupValue] = react.useState(initalValue);
|
|
22
|
+
const errorId = react.useId();
|
|
23
|
+
const namedId = react.useId();
|
|
24
|
+
const radioGroupName = name || namedId;
|
|
25
|
+
return {
|
|
26
|
+
/**
|
|
27
|
+
* Current value of the group.
|
|
28
|
+
*/
|
|
29
|
+
value: groupValue,
|
|
30
|
+
/**
|
|
31
|
+
* Set the value of the group.
|
|
32
|
+
*
|
|
33
|
+
* @param value string[]
|
|
34
|
+
* @returns void
|
|
35
|
+
*/
|
|
36
|
+
setValue: setGroupValue,
|
|
37
|
+
/**
|
|
38
|
+
* Props to send to the `Radio` component.
|
|
39
|
+
* @example
|
|
40
|
+
* <Radio label="Option 1" {...getRadioProps('option-1')} />
|
|
41
|
+
*/
|
|
42
|
+
getRadioProps: (propsOrValue) => {
|
|
43
|
+
const props = typeof propsOrValue === 'string'
|
|
44
|
+
? { value: propsOrValue }
|
|
45
|
+
: propsOrValue;
|
|
46
|
+
const { ref = undefined, value = '', ...rest } = props;
|
|
47
|
+
const localRef = react.useRef(null);
|
|
48
|
+
const mergedRefs = react$1.useMergeRefs([ref, localRef]);
|
|
49
|
+
const handleChange = () => {
|
|
50
|
+
const input = localRef.current;
|
|
51
|
+
const isInput = input instanceof HTMLInputElement;
|
|
52
|
+
if (isInput && input.name === radioGroupName) {
|
|
53
|
+
setGroupValue((prevValue) => {
|
|
54
|
+
onChange?.(input.value, prevValue);
|
|
55
|
+
return input.value;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
react.useEffect(() => {
|
|
60
|
+
if (!localRef.current)
|
|
61
|
+
return;
|
|
62
|
+
localRef.current.checked = value === groupValue;
|
|
63
|
+
}, [groupValue, value]);
|
|
64
|
+
return {
|
|
65
|
+
/* Spread anything the user has set first */
|
|
66
|
+
...rest,
|
|
67
|
+
/* Concat ours with the user prop */
|
|
68
|
+
name: radioGroupName,
|
|
69
|
+
'aria-describedby': `${error ? errorId : ''} ${rest['aria-describedby'] || ''}`.trim() ||
|
|
70
|
+
undefined,
|
|
71
|
+
'aria-invalid': !!error || rest['aria-invalid'],
|
|
72
|
+
value,
|
|
73
|
+
ref: mergedRefs,
|
|
74
|
+
required: required || rest.required,
|
|
75
|
+
readOnly: readOnly || rest.readOnly,
|
|
76
|
+
disabled: disabled || rest.disabled,
|
|
77
|
+
onChange: (e) => {
|
|
78
|
+
rest.onChange?.(e);
|
|
79
|
+
if (e.defaultPrevented)
|
|
80
|
+
return;
|
|
81
|
+
handleChange();
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
/**
|
|
86
|
+
* Props to send to the `ValidationMessage` component.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* <ValidationMessage {...validationMessageProps} />
|
|
90
|
+
*/
|
|
91
|
+
validationMessageProps: {
|
|
92
|
+
children: error,
|
|
93
|
+
hidden: !error,
|
|
94
|
+
id: errorId,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
exports.useRadioGroup = useRadioGroup;
|
|
@@ -4,7 +4,7 @@ import { FloatingPortal, FloatingFocusManager } from '@floating-ui/react';
|
|
|
4
4
|
import { useVirtualizer } from '@tanstack/react-virtual';
|
|
5
5
|
import cl from 'clsx/lite';
|
|
6
6
|
import { forwardRef, useRef, useState, useEffect } from 'react';
|
|
7
|
-
import { useFormField } from '
|
|
7
|
+
import { useFormField } from './useFormField/useFormField.js';
|
|
8
8
|
import { ComboboxContext } from './ComboboxContext.js';
|
|
9
9
|
import { ComboboxIdProvider } from './ComboboxIdContext.js';
|
|
10
10
|
import { ComboboxCustom } from './Custom.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import cl from 'clsx/lite';
|
|
3
3
|
import { useContext, useId } from 'react';
|
|
4
|
-
import { FieldsetContext } from '
|
|
4
|
+
import { FieldsetContext } from './FieldsetContext.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Handles props and their state for various form-fields in context with Fieldset
|
|
@@ -5,11 +5,11 @@ import cl from 'clsx/lite';
|
|
|
5
5
|
import { forwardRef, useRef, useEffect } from 'react';
|
|
6
6
|
import { fieldObserver } from './fieldObserver.js';
|
|
7
7
|
|
|
8
|
-
const Field = forwardRef(function Field({ className, ...rest }, ref) {
|
|
8
|
+
const Field = forwardRef(function Field({ className, position, ...rest }, ref) {
|
|
9
9
|
const fieldRef = useRef(null);
|
|
10
10
|
const mergedRefs = useMergeRefs([fieldRef, ref]);
|
|
11
11
|
useEffect(() => fieldObserver(fieldRef.current), []);
|
|
12
|
-
return (jsx("div", { className: cl('ds-field', className), ref: mergedRefs, ...rest }));
|
|
12
|
+
return (jsx("div", { className: cl('ds-field', className), "data-position": position, ref: mergedRefs, ...rest }));
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
export { Field };
|