@digdir/designsystemet-react 0.61.0 → 0.63.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/Accordion/Accordion.js +2 -2
- package/dist/cjs/components/Accordion/AccordionContent/AccordionContent.js +2 -2
- package/dist/cjs/components/Accordion/AccordionHeader/AccordionHeader.js +2 -2
- package/dist/cjs/components/Accordion/AccordionItem/AccordionItem.js +2 -2
- package/dist/cjs/components/Alert/Alert.js +5 -3
- package/dist/cjs/components/Box/Box.js +4 -1
- package/dist/cjs/components/Chip/Group/Group.js +5 -1
- package/dist/cjs/components/Chip/Removable/Removable.js +3 -1
- package/dist/cjs/components/Chip/Toggle/Toggle.js +3 -1
- package/dist/cjs/components/Divider/Divider.js +2 -2
- package/dist/cjs/components/DropdownMenu/DropdownMenu.js +4 -2
- package/dist/cjs/components/DropdownMenu/DropdownMenuContent.js +3 -3
- package/dist/cjs/components/DropdownMenu/DropdownMenuItem.js +2 -2
- package/dist/cjs/components/DropdownMenu/DropdownMenuTrigger.js +1 -1
- package/dist/cjs/components/HelpText/HelpText.js +5 -3
- package/dist/cjs/components/List/ListHeading.js +3 -3
- package/dist/cjs/components/List/ListItem.js +2 -2
- package/dist/cjs/components/List/ListRoot.js +4 -2
- package/dist/cjs/components/List/Lists.js +3 -3
- package/dist/cjs/components/Modal/ModalDialog.js +1 -1
- package/dist/cjs/components/Modal/ModalHeader.js +1 -1
- package/dist/cjs/components/Pagination/Pagination.js +6 -4
- package/dist/cjs/components/Pagination/PaginationRoot.js +4 -2
- package/dist/cjs/components/Popover/Popover.js +4 -2
- package/dist/cjs/components/Popover/PopoverContent.js +6 -6
- package/dist/cjs/components/Popover/PopoverTrigger.js +1 -1
- package/dist/cjs/components/Skeleton/Circle/Circle.js +2 -2
- package/dist/cjs/components/Skeleton/Rectangle/Rectangle.js +2 -2
- package/dist/cjs/components/Skeleton/Text/Text.js +2 -2
- package/dist/cjs/components/SkipLink/SkipLink.js +2 -2
- package/dist/cjs/components/Spinner/Spinner.js +9 -7
- package/dist/cjs/components/Table/Table.js +3 -1
- package/dist/cjs/components/Tabs/Tab/Tab.js +3 -3
- package/dist/cjs/components/Tabs/Tab/useTab.js +1 -3
- package/dist/cjs/components/Tabs/TabList/TabList.js +2 -2
- package/dist/cjs/components/Tabs/Tabs.js +5 -2
- package/dist/cjs/components/Tag/Tag.js +3 -1
- package/dist/cjs/components/ToggleGroup/ToggleGroup.js +3 -1
- package/dist/cjs/components/ToggleGroup/ToggleGroupItem/ToggleGroupItem.js +3 -3
- package/dist/cjs/components/Tooltip/Tooltip.js +9 -9
- package/dist/cjs/components/Typography/ErrorMessage/ErrorMessage.js +5 -3
- package/dist/cjs/components/Typography/Heading/Heading.js +5 -3
- package/dist/cjs/components/Typography/Ingress/Ingress.js +5 -3
- package/dist/cjs/components/Typography/Label/Label.js +5 -3
- package/dist/cjs/components/Typography/Paragraph/Paragraph.js +5 -3
- package/dist/cjs/components/form/Checkbox/Checkbox.js +3 -3
- package/dist/cjs/components/form/Checkbox/Group/Group.js +1 -1
- package/dist/cjs/components/form/Combobox/Combobox.js +18 -16
- package/dist/cjs/components/form/Combobox/Custom.js +1 -1
- package/dist/cjs/components/form/Combobox/Option/useComboboxOption.js +4 -3
- package/dist/cjs/components/form/Combobox/internal/ComboboxInput.js +4 -3
- package/dist/cjs/components/form/Combobox/internal/ComboboxNative.js +3 -3
- package/dist/cjs/components/form/Combobox/useCombobox.js +22 -6
- package/dist/cjs/components/form/Combobox/useFloatingCombobox.js +2 -2
- package/dist/cjs/components/form/Fieldset/Fieldset.js +2 -2
- package/dist/cjs/components/form/NativeSelect/NativeSelect.js +3 -3
- package/dist/cjs/components/form/NativeSelect/useNativeSelect.js +3 -1
- package/dist/cjs/components/form/Radio/Group/Group.js +3 -3
- package/dist/cjs/components/form/Radio/Radio.js +3 -3
- package/dist/cjs/components/form/Search/Search.js +5 -5
- package/dist/cjs/components/form/Search/useSearch.js +3 -7
- package/dist/cjs/components/form/Switch/Switch.js +2 -2
- package/dist/cjs/components/form/Textarea/Textarea.js +4 -4
- package/dist/cjs/components/form/Textarea/useTextarea.js +3 -1
- package/dist/cjs/components/form/Textfield/Textfield.js +6 -6
- package/dist/cjs/components/form/Textfield/useTextfield.js +3 -1
- package/dist/cjs/components/form/useFormField.js +5 -7
- package/dist/cjs/{packages/react/node_modules → node_modules}/@floating-ui/dom/dist/floating-ui.dom.js +3 -3
- package/dist/cjs/{packages/react/node_modules → node_modules}/@floating-ui/react/dist/floating-ui.react.js +2 -2
- package/dist/cjs/{packages/react/node_modules → node_modules}/@floating-ui/react/dist/floating-ui.react.utils.js +1 -1
- package/dist/cjs/node_modules/@radix-ui/react-slot/dist/index.js +1 -1
- package/dist/cjs/utilities/AnimateHeight/AnimateHeight.js +2 -2
- package/dist/cjs/utilities/RovingTabIndex/RovingTabindexItem.js +1 -1
- package/dist/cjs/utilities/RovingTabIndex/RovingTabindexRoot.js +1 -1
- package/dist/cjs/utilities/getSize.js +2 -0
- package/dist/esm/components/Accordion/Accordion.js +1 -1
- package/dist/esm/components/Accordion/AccordionContent/AccordionContent.js +2 -2
- package/dist/esm/components/Accordion/AccordionHeader/AccordionHeader.js +2 -2
- package/dist/esm/components/Accordion/AccordionItem/AccordionItem.js +1 -1
- package/dist/esm/components/Alert/Alert.js +4 -2
- package/dist/esm/components/Box/Box.js +4 -1
- package/dist/esm/components/Chip/Group/Group.js +5 -1
- package/dist/esm/components/Chip/Removable/Removable.js +3 -1
- package/dist/esm/components/Chip/Toggle/Toggle.js +3 -1
- package/dist/esm/components/Divider/Divider.js +1 -1
- package/dist/esm/components/DropdownMenu/DropdownMenu.js +4 -2
- package/dist/esm/components/DropdownMenu/DropdownMenuContent.js +3 -3
- package/dist/esm/components/DropdownMenu/DropdownMenuItem.js +2 -2
- package/dist/esm/components/DropdownMenu/DropdownMenuTrigger.js +1 -1
- package/dist/esm/components/HelpText/HelpText.js +4 -2
- package/dist/esm/components/List/ListHeading.js +3 -3
- package/dist/esm/components/List/ListItem.js +1 -1
- package/dist/esm/components/List/ListRoot.js +4 -2
- package/dist/esm/components/List/Lists.js +1 -1
- package/dist/esm/components/Modal/ModalDialog.js +1 -1
- package/dist/esm/components/Modal/ModalHeader.js +1 -1
- package/dist/esm/components/Pagination/Pagination.js +6 -4
- package/dist/esm/components/Pagination/PaginationRoot.js +4 -2
- package/dist/esm/components/Popover/Popover.js +4 -2
- package/dist/esm/components/Popover/PopoverContent.js +4 -4
- package/dist/esm/components/Popover/PopoverTrigger.js +1 -1
- package/dist/esm/components/Skeleton/Circle/Circle.js +1 -1
- package/dist/esm/components/Skeleton/Rectangle/Rectangle.js +1 -1
- package/dist/esm/components/Skeleton/Text/Text.js +1 -1
- package/dist/esm/components/SkipLink/SkipLink.js +1 -1
- package/dist/esm/components/Spinner/Spinner.js +9 -7
- package/dist/esm/components/Table/Table.js +3 -1
- package/dist/esm/components/Tabs/Tab/Tab.js +3 -3
- package/dist/esm/components/Tabs/Tab/useTab.js +1 -3
- package/dist/esm/components/Tabs/TabList/TabList.js +1 -1
- package/dist/esm/components/Tabs/Tabs.js +5 -2
- package/dist/esm/components/Tag/Tag.js +3 -1
- package/dist/esm/components/ToggleGroup/ToggleGroup.js +3 -1
- package/dist/esm/components/ToggleGroup/ToggleGroupItem/ToggleGroupItem.js +2 -2
- package/dist/esm/components/Tooltip/Tooltip.js +9 -9
- package/dist/esm/components/Typography/ErrorMessage/ErrorMessage.js +4 -2
- package/dist/esm/components/Typography/Heading/Heading.js +4 -2
- package/dist/esm/components/Typography/Ingress/Ingress.js +4 -2
- package/dist/esm/components/Typography/Label/Label.js +4 -2
- package/dist/esm/components/Typography/Paragraph/Paragraph.js +4 -2
- package/dist/esm/components/form/Checkbox/Checkbox.js +3 -3
- package/dist/esm/components/form/Checkbox/Group/Group.js +1 -1
- package/dist/esm/components/form/Combobox/Combobox.js +19 -17
- package/dist/esm/components/form/Combobox/Custom.js +1 -1
- package/dist/esm/components/form/Combobox/Option/useComboboxOption.js +4 -3
- package/dist/esm/components/form/Combobox/internal/ComboboxInput.js +4 -3
- package/dist/esm/components/form/Combobox/internal/ComboboxNative.js +3 -3
- package/dist/esm/components/form/Combobox/useCombobox.js +21 -7
- package/dist/esm/components/form/Combobox/useFloatingCombobox.js +2 -2
- package/dist/esm/components/form/Fieldset/Fieldset.js +2 -2
- package/dist/esm/components/form/NativeSelect/NativeSelect.js +3 -3
- package/dist/esm/components/form/NativeSelect/useNativeSelect.js +3 -1
- package/dist/esm/components/form/Radio/Group/Group.js +2 -2
- package/dist/esm/components/form/Radio/Radio.js +3 -3
- package/dist/esm/components/form/Search/Search.js +3 -3
- package/dist/esm/components/form/Search/useSearch.js +3 -7
- package/dist/esm/components/form/Switch/Switch.js +2 -2
- package/dist/esm/components/form/Textarea/Textarea.js +3 -3
- package/dist/esm/components/form/Textarea/useTextarea.js +3 -1
- package/dist/esm/components/form/Textfield/Textfield.js +4 -4
- package/dist/esm/components/form/Textfield/useTextfield.js +3 -1
- package/dist/esm/components/form/useFormField.js +5 -7
- package/dist/esm/{packages/react/node_modules → node_modules}/@floating-ui/dom/dist/floating-ui.dom.js +4 -4
- package/dist/esm/{packages/react/node_modules → node_modules}/@floating-ui/react/dist/floating-ui.react.js +2 -2
- package/dist/esm/{packages/react/node_modules → node_modules}/@floating-ui/react/dist/floating-ui.react.utils.js +1 -1
- package/dist/esm/node_modules/@radix-ui/react-slot/dist/index.js +1 -1
- package/dist/esm/utilities/AnimateHeight/AnimateHeight.js +1 -1
- package/dist/esm/utilities/RovingTabIndex/RovingTabindexItem.js +1 -1
- package/dist/esm/utilities/RovingTabIndex/RovingTabindexRoot.js +1 -1
- package/dist/esm/utilities/getSize.js +2 -0
- package/dist/types/components/Alert/Alert.d.ts +13 -6
- package/dist/types/components/Alert/Alert.d.ts.map +1 -1
- package/dist/types/components/Box/Box.d.ts +7 -4
- package/dist/types/components/Box/Box.d.ts.map +1 -1
- package/dist/types/components/Chip/Group/Group.d.ts +9 -3
- package/dist/types/components/Chip/Group/Group.d.ts.map +1 -1
- package/dist/types/components/Chip/Removable/Removable.d.ts +9 -6
- package/dist/types/components/Chip/Removable/Removable.d.ts.map +1 -1
- package/dist/types/components/Chip/Toggle/Toggle.d.ts +9 -6
- package/dist/types/components/Chip/Toggle/Toggle.d.ts.map +1 -1
- package/dist/types/components/DropdownMenu/DropdownMenu.d.ts +7 -4
- package/dist/types/components/DropdownMenu/DropdownMenu.d.ts.map +1 -1
- package/dist/types/components/HelpText/HelpText.d.ts +4 -3
- package/dist/types/components/HelpText/HelpText.d.ts.map +1 -1
- package/dist/types/components/List/ListHeading.d.ts +1 -1
- package/dist/types/components/List/ListRoot.d.ts +15 -9
- package/dist/types/components/List/ListRoot.d.ts.map +1 -1
- package/dist/types/components/Pagination/Pagination.d.ts +12 -4
- package/dist/types/components/Pagination/Pagination.d.ts.map +1 -1
- package/dist/types/components/Pagination/PaginationNextPrev.d.ts +2 -2
- package/dist/types/components/Pagination/PaginationNextPrev.d.ts.map +1 -1
- package/dist/types/components/Pagination/PaginationRoot.d.ts +7 -4
- package/dist/types/components/Pagination/PaginationRoot.d.ts.map +1 -1
- package/dist/types/components/Popover/Popover.d.ts +8 -4
- package/dist/types/components/Popover/Popover.d.ts.map +1 -1
- package/dist/types/components/Spinner/Spinner.d.ts +10 -3
- package/dist/types/components/Spinner/Spinner.d.ts.map +1 -1
- package/dist/types/components/Table/Table.d.ts +8 -4
- package/dist/types/components/Table/Table.d.ts.map +1 -1
- package/dist/types/components/Tabs/Tab/Tab.d.ts.map +1 -1
- package/dist/types/components/Tabs/Tab/useTab.d.ts +1 -3
- package/dist/types/components/Tabs/Tab/useTab.d.ts.map +1 -1
- package/dist/types/components/Tabs/Tabs.d.ts +14 -4
- package/dist/types/components/Tabs/Tabs.d.ts.map +1 -1
- package/dist/types/components/Tag/Tag.d.ts +9 -5
- package/dist/types/components/Tag/Tag.d.ts.map +1 -1
- package/dist/types/components/ToggleGroup/ToggleGroup.d.ts +14 -5
- package/dist/types/components/ToggleGroup/ToggleGroup.d.ts.map +1 -1
- package/dist/types/components/ToggleGroup/ToggleGroupItem/useToggleGroupitem.d.ts +2 -1
- package/dist/types/components/ToggleGroup/ToggleGroupItem/useToggleGroupitem.d.ts.map +1 -1
- package/dist/types/components/Tooltip/Tooltip.d.ts +14 -3
- package/dist/types/components/Tooltip/Tooltip.d.ts.map +1 -1
- package/dist/types/components/Typography/ErrorMessage/ErrorMessage.d.ts +14 -4
- package/dist/types/components/Typography/ErrorMessage/ErrorMessage.d.ts.map +1 -1
- package/dist/types/components/Typography/Heading/Heading.d.ts +10 -4
- package/dist/types/components/Typography/Heading/Heading.d.ts.map +1 -1
- package/dist/types/components/Typography/Ingress/Ingress.d.ts +8 -4
- package/dist/types/components/Typography/Ingress/Ingress.d.ts.map +1 -1
- package/dist/types/components/Typography/Label/Label.d.ts +15 -4
- package/dist/types/components/Typography/Label/Label.d.ts.map +1 -1
- package/dist/types/components/Typography/Paragraph/Paragraph.d.ts +18 -4
- package/dist/types/components/Typography/Paragraph/Paragraph.d.ts.map +1 -1
- package/dist/types/components/form/CharacterCounter.d.ts +2 -1
- package/dist/types/components/form/CharacterCounter.d.ts.map +1 -1
- package/dist/types/components/form/Checkbox/Checkbox.d.ts.map +1 -1
- package/dist/types/components/form/Checkbox/Group/Group.d.ts.map +1 -1
- package/dist/types/components/form/Combobox/Combobox.d.ts +2 -2
- package/dist/types/components/form/Combobox/Combobox.d.ts.map +1 -1
- package/dist/types/components/form/Combobox/Option/useComboboxOption.d.ts.map +1 -1
- package/dist/types/components/form/Combobox/internal/ComboboxInput.d.ts.map +1 -1
- package/dist/types/components/form/Combobox/internal/ComboboxNative.d.ts.map +1 -1
- package/dist/types/components/form/Combobox/useCombobox.d.ts +7 -0
- package/dist/types/components/form/Combobox/useCombobox.d.ts.map +1 -1
- package/dist/types/components/form/Fieldset/useFieldset.d.ts +1 -1
- package/dist/types/components/form/NativeSelect/NativeSelect.d.ts +10 -6
- package/dist/types/components/form/NativeSelect/NativeSelect.d.ts.map +1 -1
- package/dist/types/components/form/NativeSelect/useNativeSelect.d.ts.map +1 -1
- package/dist/types/components/form/Search/Search.d.ts +12 -6
- package/dist/types/components/form/Search/Search.d.ts.map +1 -1
- package/dist/types/components/form/Search/useSearch.d.ts +1 -3
- package/dist/types/components/form/Search/useSearch.d.ts.map +1 -1
- package/dist/types/components/form/Switch/Switch.d.ts.map +1 -1
- package/dist/types/components/form/Textarea/Textarea.d.ts +10 -10
- package/dist/types/components/form/Textarea/Textarea.d.ts.map +1 -1
- package/dist/types/components/form/Textarea/useTextarea.d.ts.map +1 -1
- package/dist/types/components/form/Textfield/Textfield.d.ts +14 -4
- package/dist/types/components/form/Textfield/Textfield.d.ts.map +1 -1
- package/dist/types/components/form/Textfield/useTextfield.d.ts.map +1 -1
- package/dist/types/components/form/useFormField.d.ts +8 -2
- package/dist/types/components/form/useFormField.d.ts.map +1 -1
- package/dist/types/utilities/getSize.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/cjs/node_modules/clsx/dist/clsx.js +0 -9
- package/dist/esm/node_modules/clsx/dist/clsx.js +0 -4
- /package/dist/cjs/node_modules/{@radix-ui/react-slot/node_modules/@babel → @babel}/runtime/helpers/esm/extends.js +0 -0
- /package/dist/cjs/{packages/react/node_modules → node_modules}/@floating-ui/react-dom/dist/floating-ui.react-dom.js +0 -0
- /package/dist/cjs/{packages/react/node_modules → node_modules}/tabbable/dist/index.esm.js +0 -0
- /package/dist/esm/node_modules/{@radix-ui/react-slot/node_modules/@babel → @babel}/runtime/helpers/esm/extends.js +0 -0
- /package/dist/esm/{packages/react/node_modules → node_modules}/@floating-ui/react-dom/dist/floating-ui.react-dom.js +0 -0
- /package/dist/esm/{packages/react/node_modules → node_modules}/tabbable/dist/index.esm.js +0 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
3
|
import { forwardRef } from 'react';
|
|
4
4
|
import { clsx } from '../../../node_modules/clsx/dist/lite.js';
|
|
5
|
-
import { useMergeRefs } from '../../../
|
|
5
|
+
import { useMergeRefs } from '../../../node_modules/@floating-ui/react/dist/floating-ui.react.js';
|
|
6
6
|
import { useCheckbox } from './useCheckbox.js';
|
|
7
7
|
import { Paragraph } from '../../Typography/Paragraph/Paragraph.js';
|
|
8
8
|
import { omit } from '../../../utilities/objectUtils.js';
|
|
@@ -10,7 +10,7 @@ import { Label } from '../../Typography/Label/Label.js';
|
|
|
10
10
|
|
|
11
11
|
const Checkbox = forwardRef((props, ref) => {
|
|
12
12
|
const { children, description, className, style, ...rest } = props;
|
|
13
|
-
const { inputProps, descriptionId, hasError, size = '
|
|
13
|
+
const { inputProps, descriptionId, hasError, size = 'md', readOnly, } = useCheckbox(props);
|
|
14
14
|
const inputRef = useMergeRefs([
|
|
15
15
|
ref,
|
|
16
16
|
(el) => {
|
|
@@ -19,7 +19,7 @@ const Checkbox = forwardRef((props, ref) => {
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
]);
|
|
22
|
-
return (jsx(Paragraph, { asChild: true, size: size, children: jsxs("div", { className: clsx('fds-checkbox', `fds-checkbox--${size}`,
|
|
22
|
+
return (jsx(Paragraph, { asChild: true, size: size, children: jsxs("div", { className: clsx('fds-checkbox', `fds-checkbox--${size}`, hasError && `fds-checkbox--error`, readOnly && `fds-checkbox--readonly`, className), style: style, children: [jsx("input", { className: `fds-checkbox__input`, ref: inputRef, ...omit(['size', 'error', 'indeterminate'], rest), ...inputProps, type: 'checkbox', disabled: inputProps.disabled, "aria-checked": rest.indeterminate ? 'mixed' : inputProps.checked }), children && (jsxs(Fragment, { children: [jsx(Label, { className: `fds-checkbox__label`, htmlFor: inputProps.id, size: size, weight: 'regular', children: jsx("span", { children: children }) }), description && (jsx(Paragraph, { asChild: true, size: size, children: jsx("div", { id: descriptionId, className: `fds-checkbox__description`, children: description }) }))] }))] }) }));
|
|
23
23
|
});
|
|
24
24
|
Checkbox.displayName = 'Checkbox';
|
|
25
25
|
|
|
@@ -4,7 +4,7 @@ import { createContext, forwardRef, useState } from 'react';
|
|
|
4
4
|
import { Fieldset } from '../../Fieldset/Fieldset.js';
|
|
5
5
|
|
|
6
6
|
const CheckboxGroupContext = createContext(null);
|
|
7
|
-
const CheckboxGroup = forwardRef(({ onChange, children, value, readOnly, defaultValue, size = '
|
|
7
|
+
const CheckboxGroup = forwardRef(({ onChange, children, value, readOnly, defaultValue, size = 'md', ...rest }, ref) => {
|
|
8
8
|
const [internalValue, setInternalValue] = useState(defaultValue ?? []);
|
|
9
9
|
const toggleValue = (checkboxValue) => {
|
|
10
10
|
const currentValue = value ?? internalValue;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
3
3
|
import { forwardRef, useRef, useId, useState, useEffect } from 'react';
|
|
4
|
-
import { FloatingPortal, FloatingFocusManager } from '../../../
|
|
4
|
+
import { FloatingPortal, FloatingFocusManager } from '../../../node_modules/@floating-ui/react/dist/floating-ui.react.js';
|
|
5
5
|
import { clsx } from '../../../node_modules/clsx/dist/lite.js';
|
|
6
6
|
import { useVirtualizer } from '../../../node_modules/@tanstack/react-virtual/dist/esm/index.js';
|
|
7
7
|
import { useFormField } from '../useFormField.js';
|
|
8
8
|
import useDebounce from '../../../utilities/useDebounce.js';
|
|
9
|
-
import
|
|
9
|
+
import { getSize } from '../../../utilities/getSize.js';
|
|
10
|
+
import useCombobox, { prefix, removePrefix } from './useCombobox.js';
|
|
10
11
|
import ComboboxInput from './internal/ComboboxInput.js';
|
|
11
12
|
import ComboboxLabel from './internal/ComboboxLabel.js';
|
|
12
13
|
import ComboboxError from './internal/ComboboxError.js';
|
|
@@ -20,7 +21,8 @@ import { Box } from '../../Box/Box.js';
|
|
|
20
21
|
import { Spinner } from '../../Spinner/Spinner.js';
|
|
21
22
|
import { omit } from '../../../utilities/objectUtils.js';
|
|
22
23
|
|
|
23
|
-
const ComboboxComponent = forwardRef(({ value, initialValue = [], onValueChange, label, hideLabel = false, description, multiple = false,
|
|
24
|
+
const ComboboxComponent = forwardRef(({ value, initialValue = [], onValueChange, label, hideLabel = false, description, multiple = false, disabled = false, readOnly = false, hideChips = false, clearButtonLabel = 'Fjern alt', hideClearButton = false, error, errorId, id, name, portal = true, htmlSize = 0, virtual = false, children, style, loading, loadingLabel = 'Laster...', filter, chipSrLabel = (option) => 'Slett ' + option.label, className, ...rest }, forwareddRef) => {
|
|
25
|
+
const size = getSize(rest.size || 'md');
|
|
24
26
|
const inputRef = useRef(null);
|
|
25
27
|
const portalRef = useRef(null);
|
|
26
28
|
const listRef = useRef([]);
|
|
@@ -48,18 +50,18 @@ const ComboboxComponent = forwardRef(({ value, initialValue = [], onValueChange,
|
|
|
48
50
|
// if value is set, set input value to the label of the value
|
|
49
51
|
useEffect(() => {
|
|
50
52
|
if (value && value.length > 0 && !multiple) {
|
|
51
|
-
const option = options[value[0]];
|
|
53
|
+
const option = options[prefix(value[0])];
|
|
52
54
|
setInputValue(option?.label || '');
|
|
53
55
|
}
|
|
54
56
|
}, [multiple, value, options]);
|
|
55
57
|
useEffect(() => {
|
|
56
58
|
if (value && Object.keys(options).length >= 0) {
|
|
57
59
|
const updatedSelectedOptions = value.map((option) => {
|
|
58
|
-
const value = options[option];
|
|
60
|
+
const value = options[prefix(option)];
|
|
59
61
|
return value;
|
|
60
62
|
});
|
|
61
63
|
setSelectedOptions(updatedSelectedOptions.reduce((acc, value) => {
|
|
62
|
-
acc[value.value] = value;
|
|
64
|
+
acc[prefix(value.value)] = value;
|
|
63
65
|
return acc;
|
|
64
66
|
}, {}));
|
|
65
67
|
}
|
|
@@ -77,18 +79,18 @@ const ComboboxComponent = forwardRef(({ value, initialValue = [], onValueChange,
|
|
|
77
79
|
return;
|
|
78
80
|
if (remove) {
|
|
79
81
|
const newSelectedOptions = { ...selectedOptions };
|
|
80
|
-
delete newSelectedOptions[option.value];
|
|
82
|
+
delete newSelectedOptions[prefix(option.value)];
|
|
81
83
|
setSelectedOptions(newSelectedOptions);
|
|
82
|
-
onValueChange?.(Object.keys(newSelectedOptions));
|
|
84
|
+
onValueChange?.(Object.keys(newSelectedOptions).map((key) => removePrefix(key)));
|
|
83
85
|
return;
|
|
84
86
|
}
|
|
85
87
|
const newSelectedOptions = { ...selectedOptions };
|
|
86
88
|
if (multiple) {
|
|
87
|
-
if (newSelectedOptions[option.value]) {
|
|
88
|
-
delete newSelectedOptions[option.value];
|
|
89
|
+
if (newSelectedOptions[prefix(option.value)]) {
|
|
90
|
+
delete newSelectedOptions[prefix(option.value)];
|
|
89
91
|
}
|
|
90
92
|
else {
|
|
91
|
-
newSelectedOptions[option.value] = option;
|
|
93
|
+
newSelectedOptions[prefix(option.value)] = option;
|
|
92
94
|
}
|
|
93
95
|
setInputValue('');
|
|
94
96
|
inputRef.current?.focus();
|
|
@@ -98,7 +100,7 @@ const ComboboxComponent = forwardRef(({ value, initialValue = [], onValueChange,
|
|
|
98
100
|
Object.keys(newSelectedOptions).forEach((key) => {
|
|
99
101
|
delete newSelectedOptions[key];
|
|
100
102
|
});
|
|
101
|
-
newSelectedOptions[option.value] = option;
|
|
103
|
+
newSelectedOptions[prefix(option.value)] = option;
|
|
102
104
|
setInputValue(option?.label || '');
|
|
103
105
|
// move cursor to the end of the input
|
|
104
106
|
setTimeout(() => {
|
|
@@ -106,7 +108,7 @@ const ComboboxComponent = forwardRef(({ value, initialValue = [], onValueChange,
|
|
|
106
108
|
}, 0);
|
|
107
109
|
}
|
|
108
110
|
setSelectedOptions(newSelectedOptions);
|
|
109
|
-
onValueChange?.(Object.keys(newSelectedOptions));
|
|
111
|
+
onValueChange?.(Object.keys(newSelectedOptions).map((key) => removePrefix(key)));
|
|
110
112
|
!multiple && setOpen(false);
|
|
111
113
|
refs.domReference.current?.focus();
|
|
112
114
|
};
|
|
@@ -132,7 +134,7 @@ const ComboboxComponent = forwardRef(({ value, initialValue = [], onValueChange,
|
|
|
132
134
|
measureElement: (elem) => {
|
|
133
135
|
return elem.getBoundingClientRect().height;
|
|
134
136
|
},
|
|
135
|
-
overscan:
|
|
137
|
+
overscan: 7,
|
|
136
138
|
});
|
|
137
139
|
return (jsxs(ComboboxContext.Provider, { value: {
|
|
138
140
|
size,
|
|
@@ -160,14 +162,14 @@ const ComboboxComponent = forwardRef(({ value, initialValue = [], onValueChange,
|
|
|
160
162
|
return;
|
|
161
163
|
if (disabled)
|
|
162
164
|
return;
|
|
163
|
-
const option = options[value];
|
|
165
|
+
const option = options[prefix(value)];
|
|
164
166
|
debouncedHandleSelectOption({ option: option });
|
|
165
167
|
},
|
|
166
168
|
handleSelectOption: debouncedHandleSelectOption,
|
|
167
169
|
chipSrLabel,
|
|
168
170
|
listRef,
|
|
169
171
|
forwareddRef,
|
|
170
|
-
}, children: [jsxs(Box, { className: clsx('fds-combobox', `fds-combobox--${size}`, disabled && 'fds-combobox__disabled', className), style: style, ref: portalRef, children: [name && (jsx(ComboboxNative, { name: name, selectedOptions: selectedOptions, multiple: multiple })), jsx(ComboboxLabel, { label: label, description: description, size: size, readOnly: readOnly, hideLabel: hideLabel, formFieldProps: formFieldProps }), jsx(ComboboxInput, { ...omit(['inputValue'], rest), hideClearButton: hideClearButton, listId: listId, error: error, hideChips: hideChips, handleKeyDown: handleKeyDown, "aria-busy": loading }), jsx(ComboboxError, { size: size, error: error, formFieldProps: formFieldProps })] }), open && (jsx(FloatingPortal, { root: portal ? null : portalRef, children: jsx(FloatingFocusManager, { context: context, initialFocus: -1, visuallyHiddenDismiss: true, children: jsxs(Box, { id: listId, shadow: '
|
|
172
|
+
}, children: [jsxs(Box, { className: clsx('fds-combobox', `fds-combobox--${size}`, disabled && 'fds-combobox__disabled', className), style: style, ref: portalRef, children: [name && (jsx(ComboboxNative, { name: name, selectedOptions: selectedOptions, multiple: multiple })), jsx(ComboboxLabel, { label: label, description: description, size: size, readOnly: readOnly, hideLabel: hideLabel, formFieldProps: formFieldProps }), jsx(ComboboxInput, { ...omit(['inputValue'], rest), hideClearButton: hideClearButton, listId: listId, error: error, hideChips: hideChips, handleKeyDown: handleKeyDown, "aria-busy": loading }), jsx(ComboboxError, { size: size, error: error, formFieldProps: formFieldProps })] }), open && (jsx(FloatingPortal, { root: portal ? null : portalRef, children: jsx(FloatingFocusManager, { context: context, initialFocus: -1, visuallyHiddenDismiss: true, children: jsxs(Box, { id: listId, shadow: 'md', borderRadius: 'md', borderColor: 'default', "aria-labelledby": formFieldProps.inputProps.id, "aria-autocomplete": 'list', tabIndex: -1, ...getFloatingProps({
|
|
171
173
|
ref: refs.setFloating,
|
|
172
174
|
style: {
|
|
173
175
|
...floatingStyles,
|
|
@@ -182,7 +184,7 @@ const ComboboxComponent = forwardRef(({ value, initialValue = [], onValueChange,
|
|
|
182
184
|
left: 0,
|
|
183
185
|
width: '100%',
|
|
184
186
|
transform: `translateY(${virtualRow.start}px)`,
|
|
185
|
-
}, children: filteredOptionsChildren[virtualRow.index] }, virtualRow.index))) })), loading ? (jsxs(ComboboxCustom, { className: 'fds-combobox__loading', children: [jsx(Spinner, { title: 'Laster', size: '
|
|
187
|
+
}, children: filteredOptionsChildren[virtualRow.index] }, virtualRow.index))) })), loading ? (jsxs(ComboboxCustom, { className: 'fds-combobox__loading', children: [jsx(Spinner, { title: 'Laster', size: 'sm' }), loadingLabel] })) : (jsxs(Fragment, { children: [restChildren, !virtual && filteredOptionsChildren] }))] }) }) }))] }));
|
|
186
188
|
});
|
|
187
189
|
const Combobox = forwardRef((props, ref) => (jsx(ComboboxIdProvider, { children: jsx(ComboboxComponent, { ...props, ref: ref }) })));
|
|
188
190
|
Combobox.displayName = 'Combobox';
|
|
@@ -3,7 +3,7 @@ import { jsx } from 'react/jsx-runtime';
|
|
|
3
3
|
import { forwardRef, useId, useContext, useMemo } from 'react';
|
|
4
4
|
import { clsx } from '../../../node_modules/clsx/dist/lite.js';
|
|
5
5
|
import { Slot as $5e63c961fc1ce211$export$8c6ed5c666ac1360 } from '../../../node_modules/@radix-ui/react-slot/dist/index.js';
|
|
6
|
-
import { useMergeRefs } from '../../../
|
|
6
|
+
import { useMergeRefs } from '../../../node_modules/@floating-ui/react/dist/floating-ui.react.js';
|
|
7
7
|
import { ComboboxContext } from './ComboboxContext.js';
|
|
8
8
|
import { useComboboxId } from './ComboboxIdContext.js';
|
|
9
9
|
import { omit } from '../../../utilities/objectUtils.js';
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useId, useContext, useMemo, useEffect } from 'react';
|
|
3
|
-
import { useMergeRefs } from '../../../../
|
|
3
|
+
import { useMergeRefs } from '../../../../node_modules/@floating-ui/react/dist/floating-ui.react.js';
|
|
4
4
|
import { ComboboxContext } from '../ComboboxContext.js';
|
|
5
5
|
import useDebounce from '../../../../utilities/useDebounce.js';
|
|
6
6
|
import { useComboboxId, useComboboxIdDispatch } from '../ComboboxIdContext.js';
|
|
7
|
+
import { prefix } from '../useCombobox.js';
|
|
7
8
|
|
|
8
9
|
function useComboboxOption({ id, ref, value, }) {
|
|
9
10
|
const generatedId = useId();
|
|
@@ -15,7 +16,7 @@ function useComboboxOption({ id, ref, value, }) {
|
|
|
15
16
|
throw new Error('ComboboxOption must be used within a Combobox');
|
|
16
17
|
}
|
|
17
18
|
const { selectedOptions, onOptionClick, listRef, customIds, filteredOptions, } = context;
|
|
18
|
-
const index = useMemo(() => filteredOptions.indexOf(value) + customIds.length, [customIds.length, filteredOptions, value]);
|
|
19
|
+
const index = useMemo(() => filteredOptions.indexOf(prefix(String(value))) + customIds.length, [customIds.length, filteredOptions, value]);
|
|
19
20
|
const combinedRef = useMergeRefs([
|
|
20
21
|
(node) => {
|
|
21
22
|
listRef.current[index] = node;
|
|
@@ -25,7 +26,7 @@ function useComboboxOption({ id, ref, value, }) {
|
|
|
25
26
|
if (index === -1) {
|
|
26
27
|
throw new Error('Internal error: ComboboxOption did not find index');
|
|
27
28
|
}
|
|
28
|
-
const selected = selectedOptions[value];
|
|
29
|
+
const selected = selectedOptions[prefix(value)];
|
|
29
30
|
const active = activeIndex === index;
|
|
30
31
|
useEffect(() => {
|
|
31
32
|
if (active) {
|
|
@@ -3,9 +3,10 @@ import { jsxs, jsx } from 'react/jsx-runtime';
|
|
|
3
3
|
import { useContext } from 'react';
|
|
4
4
|
import { clsx } from '../../../../node_modules/clsx/dist/lite.js';
|
|
5
5
|
import { ChevronUpIcon, ChevronDownIcon } from '@navikt/aksel-icons';
|
|
6
|
-
import { useMergeRefs } from '../../../../
|
|
6
|
+
import { useMergeRefs } from '../../../../node_modules/@floating-ui/react/dist/floating-ui.react.js';
|
|
7
7
|
import { ComboboxContext } from '../ComboboxContext.js';
|
|
8
8
|
import { useComboboxIdDispatch } from '../ComboboxIdContext.js';
|
|
9
|
+
import { prefix } from '../useCombobox.js';
|
|
9
10
|
import ComboboxChips from './ComboboxChips.js';
|
|
10
11
|
import ComboboxClearButton from './ComboboxClearButton.js';
|
|
11
12
|
import { Box } from '../../../Box/Box.js';
|
|
@@ -28,10 +29,10 @@ const ComboboxInput = ({ hideClearButton, listId, error, hideChips, handleKeyDow
|
|
|
28
29
|
setInputValue(value);
|
|
29
30
|
setActiveIndex(0);
|
|
30
31
|
// check if input value is the same as a label, if so, select it
|
|
31
|
-
const option = options[value.toLowerCase()];
|
|
32
|
+
const option = options[prefix(value.toLowerCase())];
|
|
32
33
|
if (!option)
|
|
33
34
|
return;
|
|
34
|
-
if (selectedOptions[option.value])
|
|
35
|
+
if (selectedOptions[prefix(option.value)])
|
|
35
36
|
return;
|
|
36
37
|
handleSelectOption({ option: option });
|
|
37
38
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { removePrefix } from '../useCombobox.js';
|
|
3
4
|
|
|
4
5
|
const ComboboxNative = ({ selectedOptions, multiple, name, }) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
: Object.keys(selectedOptions)[0], onChange: () => { }, children: Object.keys(selectedOptions).map((value) => (jsx("option", { value: value }, value))) }));
|
|
6
|
+
const VALUE = Object.keys(selectedOptions).map((key) => removePrefix(key));
|
|
7
|
+
return (jsx("select", { name: name, multiple: multiple, style: { display: 'none' }, value: multiple ? VALUE : VALUE[0], onChange: () => { }, children: VALUE.map((value) => (jsx("option", { value: value }, value))) }));
|
|
8
8
|
};
|
|
9
9
|
ComboboxNative.displayName = 'ComboboxNative';
|
|
10
10
|
var ComboboxNative$1 = ComboboxNative;
|
|
@@ -13,6 +13,18 @@ function isComboboxCustom(child) {
|
|
|
13
13
|
function isInteractiveComboboxCustom(child) {
|
|
14
14
|
return isComboboxCustom(child) && child.props.interactive === true;
|
|
15
15
|
}
|
|
16
|
+
const INTERNAL_OPTION_PREFIX = 'internal-option-';
|
|
17
|
+
/**
|
|
18
|
+
* We use this function to prefix the value of the options so we can make sure numbers as strings are not parsed as numbers in objects
|
|
19
|
+
* @param value
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
const prefix = (value) => {
|
|
23
|
+
return INTERNAL_OPTION_PREFIX + value;
|
|
24
|
+
};
|
|
25
|
+
const removePrefix = (value) => {
|
|
26
|
+
return value.slice(INTERNAL_OPTION_PREFIX.length);
|
|
27
|
+
};
|
|
16
28
|
function useCombobox({ children, inputValue, multiple, filter = (inputValue, option) => {
|
|
17
29
|
return option.label.toLowerCase().startsWith(inputValue.toLowerCase());
|
|
18
30
|
}, initialValue, }) {
|
|
@@ -60,8 +72,8 @@ function useCombobox({ children, inputValue, multiple, filter = (inputValue, opt
|
|
|
60
72
|
});
|
|
61
73
|
label = childrenLabel;
|
|
62
74
|
}
|
|
63
|
-
allOptions[props.value] = {
|
|
64
|
-
value: props.value,
|
|
75
|
+
allOptions[prefix(String(props.value))] = {
|
|
76
|
+
value: String(props.value),
|
|
65
77
|
label,
|
|
66
78
|
displayValue: props.displayValue,
|
|
67
79
|
description: props.description,
|
|
@@ -69,7 +81,9 @@ function useCombobox({ children, inputValue, multiple, filter = (inputValue, opt
|
|
|
69
81
|
});
|
|
70
82
|
return allOptions;
|
|
71
83
|
}, [optionsChildren]);
|
|
72
|
-
const preSelectedOptions = useMemo(() => (initialValue
|
|
84
|
+
const preSelectedOptions = useMemo(() => (initialValue?.map((key) => {
|
|
85
|
+
return prefix(key);
|
|
86
|
+
}) || []).reduce((acc, value) => {
|
|
73
87
|
const option = options[value];
|
|
74
88
|
if (isOption(option)) {
|
|
75
89
|
acc[value] = option;
|
|
@@ -82,15 +96,15 @@ function useCombobox({ children, inputValue, multiple, filter = (inputValue, opt
|
|
|
82
96
|
const filteredOptionsChildren = Object.keys(options).map((option, index) => {
|
|
83
97
|
/* If we have a selected value in single mode and the input matches an option, return all children */
|
|
84
98
|
if (!multiple && Object.keys(selectedOptions).length === 1) {
|
|
85
|
-
filteredOptions.push(
|
|
99
|
+
filteredOptions.push(option);
|
|
86
100
|
return optionsChildren[index];
|
|
87
101
|
}
|
|
88
102
|
if (multiple && selectedOptions[option]) {
|
|
89
|
-
filteredOptions.push(
|
|
103
|
+
filteredOptions.push(option);
|
|
90
104
|
return optionsChildren[index];
|
|
91
105
|
}
|
|
92
106
|
if (filter(inputValue, options[option])) {
|
|
93
|
-
filteredOptions.push(
|
|
107
|
+
filteredOptions.push(option);
|
|
94
108
|
return optionsChildren[index];
|
|
95
109
|
}
|
|
96
110
|
});
|
|
@@ -109,4 +123,4 @@ function useCombobox({ children, inputValue, multiple, filter = (inputValue, opt
|
|
|
109
123
|
};
|
|
110
124
|
}
|
|
111
125
|
|
|
112
|
-
export { useCombobox as default, isComboboxCustom, isComboboxOption, isInteractiveComboboxCustom };
|
|
126
|
+
export { useCombobox as default, isComboboxCustom, isComboboxOption, isInteractiveComboboxCustom, prefix, removePrefix };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { useFloating, useRole, useDismiss, useListNavigation, useInteractions } from '../../../
|
|
2
|
+
import { useFloating, useRole, useDismiss, useListNavigation, useInteractions } from '../../../node_modules/@floating-ui/react/dist/floating-ui.react.js';
|
|
3
3
|
import { useState } from 'react';
|
|
4
4
|
import { flushSync } from 'react-dom';
|
|
5
5
|
import { useComboboxId, useComboboxIdDispatch } from './ComboboxIdContext.js';
|
|
6
|
-
import { autoUpdate, flip, size } from '../../../
|
|
6
|
+
import { autoUpdate, flip, size } from '../../../node_modules/@floating-ui/dom/dist/floating-ui.dom.js';
|
|
7
7
|
import { offset } from '../../../node_modules/@floating-ui/core/dist/floating-ui.core.js';
|
|
8
8
|
|
|
9
9
|
const useFloatingCombobox = ({ listRef }) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
3
|
import { forwardRef, useContext } from 'react';
|
|
4
|
-
import { clsx } from '../../../node_modules/clsx/dist/
|
|
4
|
+
import { clsx } from '../../../node_modules/clsx/dist/lite.js';
|
|
5
5
|
import { PadlockLockedFillIcon } from '@navikt/aksel-icons';
|
|
6
6
|
import { useFieldset } from './useFieldset.js';
|
|
7
7
|
import { FieldsetContext } from './FieldsetContext.js';
|
|
@@ -19,7 +19,7 @@ const Fieldset = forwardRef((props, ref) => {
|
|
|
19
19
|
size,
|
|
20
20
|
disabled: props?.disabled,
|
|
21
21
|
readOnly,
|
|
22
|
-
}, children: jsxs("fieldset", { ...fieldsetProps, className: clsx('fds-fieldset', !hideLegend && 'fds-fieldset--spacing', readOnly && 'fds-fieldset--readonly', props?.disabled
|
|
22
|
+
}, children: jsxs("fieldset", { ...fieldsetProps, className: clsx('fds-fieldset', !hideLegend && 'fds-fieldset--spacing', readOnly && 'fds-fieldset--readonly', className), disabled: props?.disabled, ref: ref, ...rest, children: [jsx(Label, { asChild: true, size: size, children: jsx("legend", { className: 'fds-fieldset__legend', children: jsxs("span", { className: clsx('fds-fieldset__legend__content', hideLegend && `fds-sr-only`), children: [readOnly && (jsx(PadlockLockedFillIcon, { className: 'fds-fieldset__readonly__icon', "aria-hidden": true })), legend] }) }) }), description && (jsx(Paragraph, { size: size, variant: 'short', asChild: true, children: jsx("div", { id: descriptionId, className: clsx('fds-fieldset__description', hideLegend && `fds-sr-only`), children: description }) })), children, jsx("div", { id: errorId, "aria-live": 'polite', "aria-relevant": 'additions removals', className: 'fds-fieldset__error-message', children: hasError && jsx(ErrorMessage, { size: size, children: error }) })] }) }));
|
|
23
23
|
});
|
|
24
24
|
Fieldset.displayName = 'Fieldset';
|
|
25
25
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
3
|
import { forwardRef } from 'react';
|
|
4
|
-
import { clsx } from '../../../node_modules/clsx/dist/
|
|
4
|
+
import { clsx } from '../../../node_modules/clsx/dist/lite.js';
|
|
5
5
|
import { PadlockLockedFillIcon } from '@navikt/aksel-icons';
|
|
6
6
|
import { useNativeSelect } from './useNativeSelect.js';
|
|
7
7
|
import { Label } from '../../Typography/Label/Label.js';
|
|
@@ -11,8 +11,8 @@ import { Paragraph } from '../../Typography/Paragraph/Paragraph.js';
|
|
|
11
11
|
|
|
12
12
|
const NativeSelect = forwardRef((props, ref) => {
|
|
13
13
|
const { children, disabled = false, label, description, hideLabel = false, error, className, htmlSize = 0, ...rest } = props;
|
|
14
|
-
const { selectProps, descriptionId, errorId, readOnly = false, size = '
|
|
15
|
-
return (jsx(Paragraph, { asChild: true, size: size, children: jsxs("div", { className: clsx('fds-native-select--container',
|
|
14
|
+
const { selectProps, descriptionId, errorId, readOnly = false, size = 'md', } = useNativeSelect(props);
|
|
15
|
+
return (jsx(Paragraph, { asChild: true, size: size, children: jsxs("div", { className: clsx('fds-native-select--container', readOnly && 'fds-native-select--readonly', error && 'fds-native-select--error'), children: [label && (jsxs(Label, { weight: 'medium', size: size, htmlFor: selectProps.id, className: clsx('fds-native-select__label', hideLabel && 'fds-sr-only'), children: [readOnly && (jsx(PadlockLockedFillIcon, { "aria-hidden": true, className: 'fds-native-select__readonly__icon' })), label] })), description && (jsx(Paragraph, { asChild: true, size: size, children: jsx("div", { id: descriptionId, className: clsx(`fds-native-select__description`, hideLabel && `fds-sr-only`), children: description }) })), jsx("select", { disabled: disabled || readOnly, ref: ref, size: htmlSize, className: clsx('fds-native-select', `fds-native-select--${size}`, `fds-focus`, props.multiple && 'fds-native-select--multiple', className), ...omit(['size', 'error', 'errorId'], rest), ...omit(['readOnly', 'disabled'], selectProps), children: children }), error && (jsx("div", { id: errorId, className: 'fds-native-select__error-message', "aria-live": 'polite', "aria-relevant": 'additions removals', children: jsx(ErrorMessage, { size: size, children: error }) }))] }) }));
|
|
16
16
|
});
|
|
17
17
|
NativeSelect.displayName = 'NativeSelect';
|
|
18
18
|
|
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
import { useContext } from 'react';
|
|
3
3
|
import { useFormField } from '../useFormField.js';
|
|
4
4
|
import { FieldsetContext } from '../Fieldset/FieldsetContext.js';
|
|
5
|
+
import { getSize } from '../../../utilities/getSize.js';
|
|
5
6
|
|
|
6
7
|
/** Handles props for `NativeSelect` in context with `Fieldset` */
|
|
7
8
|
const useNativeSelect = (props) => {
|
|
8
9
|
const fieldset = useContext(FieldsetContext);
|
|
9
10
|
const { inputProps: selectProps, readOnly, ...rest } = useFormField(props, 'select');
|
|
11
|
+
const size = getSize(fieldset?.size ?? props.size ?? 'md');
|
|
10
12
|
return {
|
|
11
13
|
...rest,
|
|
12
14
|
readOnly,
|
|
13
|
-
size
|
|
15
|
+
size,
|
|
14
16
|
selectProps: {
|
|
15
17
|
...selectProps,
|
|
16
18
|
readOnly,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
3
|
import { createContext, forwardRef, useId } from 'react';
|
|
4
|
-
import { clsx } from '../../../../node_modules/clsx/dist/
|
|
4
|
+
import { clsx } from '../../../../node_modules/clsx/dist/lite.js';
|
|
5
5
|
import { Fieldset } from '../../Fieldset/Fieldset.js';
|
|
6
6
|
|
|
7
7
|
const RadioGroupContext = createContext(null);
|
|
8
|
-
const RadioGroup = forwardRef(({ onChange, children, value, readOnly, defaultValue, name, size = '
|
|
8
|
+
const RadioGroup = forwardRef(({ onChange, children, value, readOnly, defaultValue, name, size = 'md', required, inline, className, ...rest }, ref) => {
|
|
9
9
|
const nameId = useId();
|
|
10
10
|
return (jsx(Fieldset, { readOnly: readOnly, size: size, className: className, ref: ref, ...rest, children: jsx(RadioGroupContext.Provider, { value: {
|
|
11
11
|
value,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
3
|
import { forwardRef } from 'react';
|
|
4
|
-
import { clsx } from '../../../node_modules/clsx/dist/
|
|
4
|
+
import { clsx } from '../../../node_modules/clsx/dist/lite.js';
|
|
5
5
|
import { useRadio } from './useRadio.js';
|
|
6
6
|
import { Paragraph } from '../../Typography/Paragraph/Paragraph.js';
|
|
7
7
|
import { omit } from '../../../utilities/objectUtils.js';
|
|
@@ -9,8 +9,8 @@ import { Label } from '../../Typography/Label/Label.js';
|
|
|
9
9
|
|
|
10
10
|
const Radio = forwardRef((props, ref) => {
|
|
11
11
|
const { children, description, className, style, ...rest } = props;
|
|
12
|
-
const { inputProps, descriptionId, hasError, size = '
|
|
13
|
-
return (jsx(Paragraph, { asChild: true, size: size, children: jsxs("div", { className: clsx('fds-radio', `fds-radio--${size}`,
|
|
12
|
+
const { inputProps, descriptionId, hasError, size = 'md', readOnly, } = useRadio(props);
|
|
13
|
+
return (jsx(Paragraph, { asChild: true, size: size, children: jsxs("div", { className: clsx('fds-radio', `fds-radio--${size}`, hasError && `fds-radio--error`, readOnly && `fds-radio--readonly`, className), style: style, children: [jsx("input", { className: 'fds-radio__input', disabled: inputProps.disabled, ref: ref, ...omit(['size', 'error'], rest), ...inputProps }), children && (jsxs(Fragment, { children: [jsx(Label, { className: 'fds-radio__label', htmlFor: inputProps.id, size: size, weight: 'regular', children: jsx("span", { children: children }) }), description && (jsx(Paragraph, { asChild: true, size: size, children: jsx("div", { id: descriptionId, className: 'fds-radio__description', children: description }) }))] }))] }) }));
|
|
14
14
|
});
|
|
15
15
|
Radio.displayName = 'Radio';
|
|
16
16
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
3
|
import { forwardRef, useRef, useState, useCallback } from 'react';
|
|
4
|
-
import { clsx } from '../../../node_modules/clsx/dist/
|
|
4
|
+
import { clsx } from '../../../node_modules/clsx/dist/lite.js';
|
|
5
5
|
import { MagnifyingGlassIcon, XMarkIcon } from '@navikt/aksel-icons';
|
|
6
|
-
import { useMergeRefs } from '../../../
|
|
6
|
+
import { useMergeRefs } from '../../../node_modules/@floating-ui/react/dist/floating-ui.react.js';
|
|
7
7
|
import { useSearch } from './useSearch.js';
|
|
8
8
|
import { Button } from '../../Button/Button.js';
|
|
9
9
|
import { Paragraph } from '../../Typography/Paragraph/Paragraph.js';
|
|
@@ -20,7 +20,7 @@ import { ErrorMessage } from '../../Typography/ErrorMessage/ErrorMessage.js';
|
|
|
20
20
|
*/
|
|
21
21
|
const Search = forwardRef((props, ref) => {
|
|
22
22
|
const { label, style, hideLabel = true, variant = 'simple', searchButtonLabel = 'Søk', clearButtonLabel = 'Tøm', defaultValue, value, onChange, onClear, disabled, onSearchClick, htmlSize = 27, className, ...rest } = props;
|
|
23
|
-
const { inputProps, hasError, errorId, size = '
|
|
23
|
+
const { inputProps, hasError, errorId, size = 'md' } = useSearch(props);
|
|
24
24
|
const inputRef = useRef();
|
|
25
25
|
const mergedRef = useMergeRefs([ref, inputRef]);
|
|
26
26
|
const [internalValue, setInternalValue] = useState(defaultValue ?? '');
|
|
@@ -2,21 +2,17 @@
|
|
|
2
2
|
import { useContext } from 'react';
|
|
3
3
|
import { useFormField } from '../useFormField.js';
|
|
4
4
|
import { FieldsetContext } from '../Fieldset/FieldsetContext.js';
|
|
5
|
+
import { getSize } from '../../../utilities/getSize.js';
|
|
5
6
|
|
|
6
|
-
const sizeMap = {
|
|
7
|
-
small: 'small',
|
|
8
|
-
medium: 'medium',
|
|
9
|
-
large: 'large',
|
|
10
|
-
};
|
|
11
7
|
/** Handles props for `Search` in context with `Fieldset` */
|
|
12
8
|
const useSearch = (props) => {
|
|
13
9
|
const fieldset = useContext(FieldsetContext);
|
|
14
10
|
const { inputProps, readOnly, ...rest } = useFormField(props, 'search');
|
|
15
|
-
const
|
|
11
|
+
const size = fieldset?.size ?? getSize(props.size || 'md');
|
|
16
12
|
return {
|
|
17
13
|
...rest,
|
|
18
14
|
readOnly,
|
|
19
|
-
size
|
|
15
|
+
size,
|
|
20
16
|
inputProps: {
|
|
21
17
|
...inputProps,
|
|
22
18
|
type: 'search',
|
|
@@ -10,8 +10,8 @@ import { Label } from '../../Typography/Label/Label.js';
|
|
|
10
10
|
|
|
11
11
|
const Switch = forwardRef((props, ref) => {
|
|
12
12
|
const { children, description, position = 'left', className, ...rest } = props;
|
|
13
|
-
const { inputProps, descriptionId, size = '
|
|
14
|
-
return (jsx(Paragraph, { asChild: true, size: size, children: jsxs("div", { className: clsx(`fds-switch`, `fds-switch--${size}`, inputProps.disabled && `fds-switch--disabled`, readOnly && `fds-switch--readonly`, className), children: [jsx("input", { className: `fds-switch__input`, ref: ref, ...omit(['size', 'error'], rest), ...inputProps }), jsxs(Label, { className: clsx(`fds-switch__label`, position === 'right' && `fds-switch__label--right`), htmlFor: inputProps.id, size: size, weight: 'regular', children: [jsx("span", { className: `fds-switch__track`, children: jsx("span", { className: `fds-switch__thumb` }) }), readOnly && (jsx(PadlockLockedFillIcon, { "aria-hidden": true, className: `fds-switch__readonly__icon` })), children && jsx("span", { children: children })] }), description && (jsx(Paragraph, { asChild: true, size: size, children: jsx("div", { id: descriptionId, className: `fds-switch__description`, children: description }) }))] }) }));
|
|
13
|
+
const { inputProps, descriptionId, size = 'md', readOnly, } = useSwitch(props);
|
|
14
|
+
return (jsx(Paragraph, { asChild: true, size: size, children: jsxs("div", { className: clsx(`fds-switch`, `fds-switch--${size}`, inputProps.disabled && `fds-switch--disabled`, readOnly && `fds-switch--readonly`, className), children: [jsx("input", { className: `fds-switch__input`, disabled: inputProps.disabled, ref: ref, ...omit(['size', 'error'], rest), ...inputProps }), jsxs(Label, { className: clsx(`fds-switch__label`, position === 'right' && `fds-switch__label--right`), htmlFor: inputProps.id, size: size, weight: 'regular', children: [jsx("span", { className: `fds-switch__track`, children: jsx("span", { className: `fds-switch__thumb` }) }), readOnly && (jsx(PadlockLockedFillIcon, { "aria-hidden": true, className: `fds-switch__readonly__icon` })), children && jsx("span", { children: children })] }), description && (jsx(Paragraph, { asChild: true, size: size, children: jsx("div", { id: descriptionId, className: `fds-switch__description`, children: description }) }))] }) }));
|
|
15
15
|
});
|
|
16
16
|
Switch.displayName = 'Switch';
|
|
17
17
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
3
|
import { forwardRef, useState } from 'react';
|
|
4
|
-
import { clsx } from '../../../node_modules/clsx/dist/
|
|
4
|
+
import { clsx } from '../../../node_modules/clsx/dist/lite.js';
|
|
5
5
|
import { PadlockLockedFillIcon } from '@navikt/aksel-icons';
|
|
6
6
|
import { CharacterCounter } from '../CharacterCounter.js';
|
|
7
7
|
import { useTextarea } from './useTextarea.js';
|
|
@@ -19,12 +19,12 @@ import { ErrorMessage } from '../../Typography/ErrorMessage/ErrorMessage.js';
|
|
|
19
19
|
*/
|
|
20
20
|
const Textarea = forwardRef((props, ref) => {
|
|
21
21
|
const { label, description, style, characterLimit, hideLabel, className, ...rest } = props;
|
|
22
|
-
const { textareaProps, descriptionId, hasError, errorId, size = '
|
|
22
|
+
const { textareaProps, descriptionId, hasError, errorId, size = 'md', readOnly, } = useTextarea(props);
|
|
23
23
|
const [value, setValue] = useState(props.defaultValue);
|
|
24
24
|
const characterLimitId = `${textareaProps.id}-charactercount}`;
|
|
25
25
|
const hasCharacterLimit = characterLimit != null;
|
|
26
26
|
const describedBy = clsx(textareaProps['aria-describedby'], hasCharacterLimit && characterLimitId) || undefined;
|
|
27
|
-
return (jsx(Paragraph, { asChild: true, size: size, children: jsxs("div", { style: style, className: clsx('fds-textarea', `fds-textarea--${size}`,
|
|
27
|
+
return (jsx(Paragraph, { asChild: true, size: size, children: jsxs("div", { style: style, className: clsx('fds-textarea', `fds-textarea--${size}`, hasError && `fds-textarea--error`, className), children: [label && (jsxs(Label, { size: size, weight: 'medium', htmlFor: textareaProps.id, className: clsx('fds-textarea__label', hideLabel && `fds-sr-only`), children: [readOnly && (jsx(PadlockLockedFillIcon, { "aria-hidden": true, className: 'fds-textarea__readonly-icon' })), jsx("span", { children: label })] })), description && (jsx(Paragraph, { asChild: true, size: size, children: jsx("div", { id: descriptionId, className: clsx('fds-textarea__description', hideLabel && `fds-sr-only`), children: description }) })), jsx("textarea", { className: clsx('fds-textarea__input', `fds-focus`), ref: ref, "aria-describedby": describedBy, disabled: textareaProps.disabled, readOnly: readOnly, ...omit(['size', 'error', 'errorId'], rest), ...textareaProps, onChange: (e) => {
|
|
28
28
|
textareaProps?.onChange?.(e);
|
|
29
29
|
setValue(e.target.value);
|
|
30
30
|
} }), hasCharacterLimit && (jsx(CharacterCounter, { size: size, value: value ? value.toString() : '', id: characterLimitId, ...characterLimit })), jsx("div", { className: 'fds-textarea__error-message', id: errorId, "aria-live": 'polite', "aria-relevant": 'additions removals', children: hasError && jsx(ErrorMessage, { size: size, children: props.error }) })] }) }));
|
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
import { useContext } from 'react';
|
|
3
3
|
import { useFormField } from '../useFormField.js';
|
|
4
4
|
import { FieldsetContext } from '../Fieldset/FieldsetContext.js';
|
|
5
|
+
import { getSize } from '../../../utilities/getSize.js';
|
|
5
6
|
|
|
6
7
|
/** Handles props for `Textarea` in context with `Fieldset` */
|
|
7
8
|
const useTextarea = (props) => {
|
|
8
9
|
const fieldset = useContext(FieldsetContext);
|
|
9
10
|
const { inputProps, readOnly, ...rest } = useFormField(props, 'textarea');
|
|
11
|
+
const size = fieldset?.size ?? getSize(props.size ?? 'md');
|
|
10
12
|
return {
|
|
11
13
|
...rest,
|
|
12
14
|
readOnly,
|
|
13
|
-
size
|
|
15
|
+
size,
|
|
14
16
|
textareaProps: {
|
|
15
17
|
...inputProps,
|
|
16
18
|
readOnly,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
3
|
import { forwardRef, useState, useId } from 'react';
|
|
4
|
-
import { clsx } from '../../../node_modules/clsx/dist/
|
|
4
|
+
import { clsx } from '../../../node_modules/clsx/dist/lite.js';
|
|
5
5
|
import { PadlockLockedFillIcon } from '@navikt/aksel-icons';
|
|
6
6
|
import { CharacterCounter } from '../CharacterCounter.js';
|
|
7
7
|
import { useTextfield } from './useTextfield.js';
|
|
@@ -19,12 +19,12 @@ import { ErrorMessage } from '../../Typography/ErrorMessage/ErrorMessage.js';
|
|
|
19
19
|
*/
|
|
20
20
|
const Textfield = forwardRef((props, ref) => {
|
|
21
21
|
const { label, description, suffix, prefix, style, characterLimit, hideLabel, type = 'text', htmlSize = 20, className, ...rest } = props;
|
|
22
|
-
const { inputProps, descriptionId, hasError, errorId, size = '
|
|
23
|
-
const [inputValue, setInputValue] = useState(props.defaultValue);
|
|
22
|
+
const { inputProps, descriptionId, hasError, errorId, size = 'md', readOnly, } = useTextfield(props);
|
|
23
|
+
const [inputValue, setInputValue] = useState(props.value || props.defaultValue);
|
|
24
24
|
const characterLimitId = `textfield-charactercount-${useId()}`;
|
|
25
25
|
const hasCharacterLimit = characterLimit != null;
|
|
26
26
|
const describedBy = clsx(inputProps['aria-describedby'], hasCharacterLimit && characterLimitId) || undefined;
|
|
27
|
-
return (jsx(Paragraph, { asChild: true, size: size, children: jsxs("div", { style: style, className: clsx(`fds-textfield`, `fds-textfield--${size}`,
|
|
27
|
+
return (jsx(Paragraph, { asChild: true, size: size, children: jsxs("div", { style: style, className: clsx(`fds-textfield`, `fds-textfield--${size}`, readOnly && `fds-textfield--readonly`, hasError && `fds-textfield--error`, className), children: [label && (jsxs(Label, { size: size, weight: 'medium', htmlFor: inputProps.id, className: clsx(`fds-textfield__label`, hideLabel && `fds-sr-only`), children: [readOnly && (jsx(PadlockLockedFillIcon, { "aria-hidden": true, className: 'fds-textfield__readonly__icon' })), jsx("span", { children: label })] })), description && (jsx(Paragraph, { asChild: true, size: size, children: jsx("div", { id: descriptionId, className: clsx(`fds-textfield__description`, hideLabel && `fds-sr-only`), children: description }) })), jsxs("div", { className: 'fds-textfield__field', children: [prefix && (jsx(Paragraph, { asChild: true, size: size, variant: 'short', children: jsx("div", { className: clsx(`fds-textfield__adornment`, `fds-textfield__prefix`), "aria-hidden": 'true', children: prefix }) })), jsx("input", { className: clsx(`fds-textfield__input`, `fds-focus`, prefix && `fds-textfield__input--with-prefix`, suffix && `fds-textfield__input--with-suffix`), ref: ref, type: type, disabled: inputProps.disabled, "aria-describedby": describedBy, size: htmlSize, ...omit(['size', 'error', 'errorId'], rest), ...inputProps, onChange: (e) => {
|
|
28
28
|
inputProps?.onChange?.(e);
|
|
29
29
|
setInputValue(e.target.value);
|
|
30
30
|
} }), suffix && (jsx(Paragraph, { asChild: true, size: size, variant: 'short', children: jsx("div", { className: clsx(`fds-textfield__adornment`, `fds-textfield__suffix`), "aria-hidden": 'true', children: suffix }) }))] }), hasCharacterLimit && (jsx(CharacterCounter, { size: size, value: inputValue ? inputValue.toString() : '', id: characterLimitId, ...characterLimit })), jsx("div", { className: 'fds-textfield__error-message', id: errorId, "aria-live": 'polite', "aria-relevant": 'additions removals', children: hasError && jsx(ErrorMessage, { size: size, children: props.error }) })] }) }));
|
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
import { useContext } from 'react';
|
|
3
3
|
import { useFormField } from '../useFormField.js';
|
|
4
4
|
import { FieldsetContext } from '../Fieldset/FieldsetContext.js';
|
|
5
|
+
import { getSize } from '../../../utilities/getSize.js';
|
|
5
6
|
|
|
6
7
|
/** Handles props for `Textfield` in context with `Fieldset` */
|
|
7
8
|
const useTextfield = (props) => {
|
|
8
9
|
const fieldset = useContext(FieldsetContext);
|
|
9
10
|
const { inputProps, readOnly, ...rest } = useFormField(props, 'textfield');
|
|
11
|
+
const size = getSize(fieldset?.size ?? props.size ?? 'md');
|
|
10
12
|
return {
|
|
11
13
|
...rest,
|
|
12
14
|
readOnly,
|
|
13
|
-
size
|
|
15
|
+
size,
|
|
14
16
|
inputProps: {
|
|
15
17
|
...inputProps,
|
|
16
18
|
readOnly,
|