@navikt/ds-react 7.6.0 → 7.7.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/cjs/copybutton/CopyButton.d.ts +1 -6
- package/cjs/copybutton/CopyButton.js +8 -6
- package/cjs/copybutton/CopyButton.js.map +1 -1
- package/cjs/date/datepicker/parts/WeekNumber.js +11 -2
- package/cjs/date/datepicker/parts/WeekNumber.js.map +1 -1
- package/cjs/form/combobox/FilteredOptions/AddNewOption.js +3 -1
- package/cjs/form/combobox/FilteredOptions/AddNewOption.js.map +1 -1
- package/cjs/form/combobox/FilteredOptions/LoadingMessage.js +3 -1
- package/cjs/form/combobox/FilteredOptions/LoadingMessage.js.map +1 -1
- package/cjs/form/combobox/FilteredOptions/MaxSelectedMessage.js +6 -2
- package/cjs/form/combobox/FilteredOptions/MaxSelectedMessage.js.map +1 -1
- package/cjs/form/combobox/Input/Input.context.d.ts +1 -1
- package/cjs/form/combobox/Input/Input.context.js.map +1 -1
- package/cjs/form/combobox/Input/InputController.js +9 -7
- package/cjs/form/combobox/Input/InputController.js.map +1 -1
- package/cjs/form/combobox/Input/ToggleListButton.d.ts +1 -4
- package/cjs/form/combobox/Input/ToggleListButton.js +3 -5
- package/cjs/form/combobox/Input/ToggleListButton.js.map +1 -1
- package/cjs/form/combobox/SelectedOptions/SelectedOptions.js +8 -6
- package/cjs/form/combobox/SelectedOptions/SelectedOptions.js.map +1 -1
- package/cjs/form/combobox/types.d.ts +2 -7
- package/cjs/form/form-summary/FormSummaryEditLink.js +4 -2
- package/cjs/form/form-summary/FormSummaryEditLink.js.map +1 -1
- package/cjs/form/search/Search.js +8 -3
- package/cjs/form/search/Search.js.map +1 -1
- package/cjs/guide-panel/Illustration.js +3 -1
- package/cjs/guide-panel/Illustration.js.map +1 -1
- package/cjs/help-text/HelpText.d.ts +1 -1
- package/cjs/help-text/HelpText.js +6 -3
- package/cjs/help-text/HelpText.js.map +1 -1
- package/cjs/internal-header/InternalHeaderButton.d.ts +1 -1
- package/cjs/internal-header/InternalHeaderUserButton.d.ts +1 -1
- package/cjs/internal-header/InternalHeaderUserButton.js +1 -1
- package/cjs/internal-header/InternalHeaderUserButton.js.map +1 -1
- package/cjs/layout/base/BasePrimitive.js +4 -1
- package/cjs/layout/base/BasePrimitive.js.map +1 -1
- package/cjs/layout/bleed/Bleed.js +5 -2
- package/cjs/layout/bleed/Bleed.js.map +1 -1
- package/cjs/layout/box/Box.d.ts +6 -1
- package/cjs/layout/box/Box.darkside.d.ts +70 -0
- package/cjs/layout/box/Box.darkside.js +98 -0
- package/cjs/layout/box/Box.darkside.js.map +1 -0
- package/cjs/layout/box/Box.js +19 -6
- package/cjs/layout/box/Box.js.map +1 -1
- package/cjs/layout/box/index.js +2 -0
- package/cjs/layout/box/index.js.map +1 -1
- package/cjs/layout/grid/HGrid.js +4 -1
- package/cjs/layout/grid/HGrid.js.map +1 -1
- package/cjs/layout/page/Page.d.ts +1 -0
- package/cjs/layout/page/Page.js +5 -0
- package/cjs/layout/page/Page.js.map +1 -1
- package/cjs/layout/stack/Stack.js +4 -1
- package/cjs/layout/stack/Stack.js.map +1 -1
- package/cjs/layout/utilities/css.d.ts +2 -2
- package/cjs/layout/utilities/css.js +8 -9
- package/cjs/layout/utilities/css.js.map +1 -1
- package/cjs/layout/utilities/types.d.ts +10 -0
- package/cjs/util/i18n/locales/en.d.ts +19 -0
- package/cjs/util/i18n/locales/en.js +19 -0
- package/cjs/util/i18n/locales/en.js.map +1 -1
- package/cjs/util/i18n/locales/nb.d.ts +21 -0
- package/cjs/util/i18n/locales/nb.js +21 -0
- package/cjs/util/i18n/locales/nb.js.map +1 -1
- package/cjs/util/i18n/locales/nn.d.ts +19 -0
- package/cjs/util/i18n/locales/nn.js +19 -0
- package/cjs/util/i18n/locales/nn.js.map +1 -1
- package/esm/copybutton/CopyButton.d.ts +1 -6
- package/esm/copybutton/CopyButton.js +8 -6
- package/esm/copybutton/CopyButton.js.map +1 -1
- package/esm/date/datepicker/parts/WeekNumber.js +12 -3
- package/esm/date/datepicker/parts/WeekNumber.js.map +1 -1
- package/esm/form/combobox/FilteredOptions/AddNewOption.js +3 -1
- package/esm/form/combobox/FilteredOptions/AddNewOption.js.map +1 -1
- package/esm/form/combobox/FilteredOptions/LoadingMessage.js +3 -1
- package/esm/form/combobox/FilteredOptions/LoadingMessage.js.map +1 -1
- package/esm/form/combobox/FilteredOptions/MaxSelectedMessage.js +6 -2
- package/esm/form/combobox/FilteredOptions/MaxSelectedMessage.js.map +1 -1
- package/esm/form/combobox/Input/Input.context.d.ts +1 -1
- package/esm/form/combobox/Input/Input.context.js.map +1 -1
- package/esm/form/combobox/Input/InputController.js +9 -7
- package/esm/form/combobox/Input/InputController.js.map +1 -1
- package/esm/form/combobox/Input/ToggleListButton.d.ts +1 -4
- package/esm/form/combobox/Input/ToggleListButton.js +3 -5
- package/esm/form/combobox/Input/ToggleListButton.js.map +1 -1
- package/esm/form/combobox/SelectedOptions/SelectedOptions.js +8 -6
- package/esm/form/combobox/SelectedOptions/SelectedOptions.js.map +1 -1
- package/esm/form/combobox/types.d.ts +2 -7
- package/esm/form/form-summary/FormSummaryEditLink.js +4 -2
- package/esm/form/form-summary/FormSummaryEditLink.js.map +1 -1
- package/esm/form/search/Search.js +8 -3
- package/esm/form/search/Search.js.map +1 -1
- package/esm/guide-panel/Illustration.js +3 -1
- package/esm/guide-panel/Illustration.js.map +1 -1
- package/esm/help-text/HelpText.d.ts +1 -1
- package/esm/help-text/HelpText.js +6 -3
- package/esm/help-text/HelpText.js.map +1 -1
- package/esm/internal-header/InternalHeaderButton.d.ts +1 -1
- package/esm/internal-header/InternalHeaderUserButton.d.ts +1 -1
- package/esm/internal-header/InternalHeaderUserButton.js +1 -1
- package/esm/internal-header/InternalHeaderUserButton.js.map +1 -1
- package/esm/layout/base/BasePrimitive.js +4 -1
- package/esm/layout/base/BasePrimitive.js.map +1 -1
- package/esm/layout/bleed/Bleed.js +5 -2
- package/esm/layout/bleed/Bleed.js.map +1 -1
- package/esm/layout/box/Box.d.ts +6 -1
- package/esm/layout/box/Box.darkside.d.ts +70 -0
- package/esm/layout/box/Box.darkside.js +69 -0
- package/esm/layout/box/Box.darkside.js.map +1 -0
- package/esm/layout/box/Box.js +18 -5
- package/esm/layout/box/Box.js.map +1 -1
- package/esm/layout/grid/HGrid.js +4 -1
- package/esm/layout/grid/HGrid.js.map +1 -1
- package/esm/layout/page/Page.d.ts +1 -0
- package/esm/layout/page/Page.js +5 -0
- package/esm/layout/page/Page.js.map +1 -1
- package/esm/layout/stack/Stack.js +4 -1
- package/esm/layout/stack/Stack.js.map +1 -1
- package/esm/layout/utilities/css.d.ts +2 -2
- package/esm/layout/utilities/css.js +8 -9
- package/esm/layout/utilities/css.js.map +1 -1
- package/esm/layout/utilities/types.d.ts +10 -0
- package/esm/util/i18n/locales/en.d.ts +19 -0
- package/esm/util/i18n/locales/en.js +19 -0
- package/esm/util/i18n/locales/en.js.map +1 -1
- package/esm/util/i18n/locales/nb.d.ts +21 -0
- package/esm/util/i18n/locales/nb.js +21 -0
- package/esm/util/i18n/locales/nb.js.map +1 -1
- package/esm/util/i18n/locales/nn.d.ts +19 -0
- package/esm/util/i18n/locales/nn.js +19 -0
- package/esm/util/i18n/locales/nn.js.map +1 -1
- package/package.json +3 -3
- package/src/copybutton/CopyButton.tsx +14 -30
- package/src/date/datepicker/parts/WeekNumber.tsx +31 -6
- package/src/form/combobox/FilteredOptions/AddNewOption.tsx +3 -1
- package/src/form/combobox/FilteredOptions/LoadingMessage.tsx +3 -1
- package/src/form/combobox/FilteredOptions/MaxSelectedMessage.tsx +9 -2
- package/src/form/combobox/Input/Input.context.tsx +2 -2
- package/src/form/combobox/Input/InputController.tsx +13 -16
- package/src/form/combobox/Input/ToggleListButton.tsx +8 -24
- package/src/form/combobox/SelectedOptions/SelectedOptions.tsx +17 -11
- package/src/form/combobox/__tests__/combobox.test.tsx +2 -1
- package/src/form/combobox/types.ts +2 -7
- package/src/form/form-summary/FormSummaryEditLink.tsx +7 -6
- package/src/form/search/Search.tsx +33 -12
- package/src/guide-panel/Illustration.tsx +4 -1
- package/src/help-text/HelpText.tsx +8 -6
- package/src/internal-header/InternalHeaderButton.tsx +1 -1
- package/src/internal-header/InternalHeaderUserButton.tsx +2 -2
- package/src/layout/base/BasePrimitive.tsx +29 -25
- package/src/layout/bleed/Bleed.tsx +8 -0
- package/src/layout/box/Box.darkside.tsx +154 -0
- package/src/layout/box/Box.tsx +90 -61
- package/src/layout/box/index.ts +3 -0
- package/src/layout/grid/HGrid.tsx +7 -3
- package/src/layout/page/Page.tsx +10 -0
- package/src/layout/stack/Stack.tsx +8 -4
- package/src/layout/utilities/css.ts +18 -12
- package/src/layout/utilities/types.ts +24 -0
- package/src/util/i18n/locales/en.ts +19 -0
- package/src/util/i18n/locales/nb.ts +21 -0
- package/src/util/i18n/locales/nn.ts +19 -0
|
@@ -2,6 +2,7 @@ import cl from "clsx";
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { PlusIcon } from "@navikt/aksel-icons";
|
|
4
4
|
import { BodyShort, Label } from "../../../typography";
|
|
5
|
+
import { useI18n } from "../../../util/i18n/i18n.context";
|
|
5
6
|
import { useInputContext } from "../Input/Input.context";
|
|
6
7
|
import { useSelectedOptionsContext } from "../SelectedOptions/selectedOptionsContext";
|
|
7
8
|
import { isInList, toComboboxOption } from "../combobox-utils";
|
|
@@ -22,6 +23,7 @@ const AddNewOption = () => {
|
|
|
22
23
|
} = useFilteredOptionsContext();
|
|
23
24
|
const { isMultiSelect, selectedOptions, toggleOption } =
|
|
24
25
|
useSelectedOptionsContext();
|
|
26
|
+
const translate = useI18n("Combobox");
|
|
25
27
|
return (
|
|
26
28
|
<li
|
|
27
29
|
tabIndex={-1}
|
|
@@ -51,7 +53,7 @@ const AddNewOption = () => {
|
|
|
51
53
|
>
|
|
52
54
|
<PlusIcon aria-hidden />
|
|
53
55
|
<BodyShort size={size}>
|
|
54
|
-
|
|
56
|
+
{translate("addOption")}{" "}
|
|
55
57
|
<Label as="span" size={size}>
|
|
56
58
|
“{searchTerm}”
|
|
57
59
|
</Label>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { Loader } from "../../../loader";
|
|
3
|
+
import { useI18n } from "../../../util/i18n/i18n.context";
|
|
3
4
|
import { useInputContext } from "../Input/Input.context";
|
|
4
5
|
import filteredOptionsUtil from "./filtered-options-util";
|
|
5
6
|
|
|
@@ -7,12 +8,13 @@ const LoadingMessage = () => {
|
|
|
7
8
|
const {
|
|
8
9
|
inputProps: { id },
|
|
9
10
|
} = useInputContext();
|
|
11
|
+
const translate = useI18n("Combobox");
|
|
10
12
|
return (
|
|
11
13
|
<div
|
|
12
14
|
className="navds-combobox__list-item--loading"
|
|
13
15
|
id={filteredOptionsUtil.getIsLoadingId(id)}
|
|
14
16
|
>
|
|
15
|
-
<Loader title="
|
|
17
|
+
<Loader title={translate("loading")} />
|
|
16
18
|
</div>
|
|
17
19
|
);
|
|
18
20
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { useI18n } from "../../../util/i18n/i18n.context";
|
|
2
3
|
import { useInputContext } from "../Input/Input.context";
|
|
3
4
|
import { useSelectedOptionsContext } from "../SelectedOptions/selectedOptionsContext";
|
|
4
5
|
import filteredOptionsUtil from "./filtered-options-util";
|
|
@@ -8,6 +9,10 @@ const MaxSelectedMessage = () => {
|
|
|
8
9
|
inputProps: { id },
|
|
9
10
|
} = useInputContext();
|
|
10
11
|
const { maxSelected, selectedOptions } = useSelectedOptionsContext();
|
|
12
|
+
const translate = useI18n(
|
|
13
|
+
"Combobox",
|
|
14
|
+
maxSelected?.message ? { maxSelected: maxSelected.message } : undefined,
|
|
15
|
+
);
|
|
11
16
|
|
|
12
17
|
if (!maxSelected) {
|
|
13
18
|
return null;
|
|
@@ -18,8 +23,10 @@ const MaxSelectedMessage = () => {
|
|
|
18
23
|
className="navds-combobox__list-item--max-selected"
|
|
19
24
|
id={filteredOptionsUtil.getMaxSelectedOptionsId(id)}
|
|
20
25
|
>
|
|
21
|
-
{maxSelected
|
|
22
|
-
|
|
26
|
+
{translate("maxSelected", {
|
|
27
|
+
selected: selectedOptions.length,
|
|
28
|
+
limit: maxSelected.limit,
|
|
29
|
+
})}
|
|
23
30
|
</div>
|
|
24
31
|
);
|
|
25
32
|
};
|
|
@@ -15,7 +15,7 @@ interface InputContextValue extends FormFieldType {
|
|
|
15
15
|
searchTerm: string;
|
|
16
16
|
setSearchTerm: React.Dispatch<React.SetStateAction<string>>;
|
|
17
17
|
shouldAutocomplete?: boolean;
|
|
18
|
-
toggleOpenButtonRef: React.RefObject<
|
|
18
|
+
toggleOpenButtonRef: React.RefObject<HTMLDivElement>;
|
|
19
19
|
hideCaret: boolean;
|
|
20
20
|
setHideCaret: React.Dispatch<React.SetStateAction<boolean>>;
|
|
21
21
|
}
|
|
@@ -72,7 +72,7 @@ const InputProvider = ({ children, value: props }: Props) => {
|
|
|
72
72
|
"comboboxfield",
|
|
73
73
|
);
|
|
74
74
|
const inputRef = useRef<HTMLInputElement | null>(null);
|
|
75
|
-
const toggleOpenButtonRef = useRef<
|
|
75
|
+
const toggleOpenButtonRef = useRef<HTMLDivElement>(null);
|
|
76
76
|
const [internalValue, setInternalValue] = useState<string>(defaultValue);
|
|
77
77
|
const [hideCaret, setHideCaret] = useState(false);
|
|
78
78
|
|
|
@@ -3,6 +3,7 @@ import cl from "clsx";
|
|
|
3
3
|
import React, { forwardRef } from "react";
|
|
4
4
|
import { XMarkIcon } from "@navikt/aksel-icons";
|
|
5
5
|
import { useMergeRefs } from "../../../util/hooks";
|
|
6
|
+
import { useI18n } from "../../../util/i18n/i18n.context";
|
|
6
7
|
import { useFilteredOptionsContext } from "../FilteredOptions/filteredOptionsContext";
|
|
7
8
|
import SelectedOptions from "../SelectedOptions/SelectedOptions";
|
|
8
9
|
import { useSelectedOptionsContext } from "../SelectedOptions/selectedOptionsContext";
|
|
@@ -11,7 +12,6 @@ import Input from "./Input";
|
|
|
11
12
|
import { useInputContext } from "./Input.context";
|
|
12
13
|
import ToggleListButton from "./ToggleListButton";
|
|
13
14
|
|
|
14
|
-
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
15
15
|
export const InputController = forwardRef<
|
|
16
16
|
HTMLInputElement,
|
|
17
17
|
Omit<
|
|
@@ -31,7 +31,6 @@ export const InputController = forwardRef<
|
|
|
31
31
|
clearButton = true,
|
|
32
32
|
clearButtonLabel,
|
|
33
33
|
toggleListButton = true,
|
|
34
|
-
toggleListButtonLabel,
|
|
35
34
|
inputClassName,
|
|
36
35
|
shouldShowSelectedOptions = true,
|
|
37
36
|
...rest
|
|
@@ -53,7 +52,13 @@ export const InputController = forwardRef<
|
|
|
53
52
|
|
|
54
53
|
const mergedInputRef = useMergeRefs(inputRef, ref);
|
|
55
54
|
|
|
55
|
+
const translate = useI18n(
|
|
56
|
+
"Combobox",
|
|
57
|
+
clearButtonLabel ? { clear: clearButtonLabel } : undefined,
|
|
58
|
+
);
|
|
59
|
+
|
|
56
60
|
return (
|
|
61
|
+
// eslint-disable-next-line jsx-a11y/click-events-have-key-events
|
|
57
62
|
<div
|
|
58
63
|
className={cl("navds-combobox__wrapper-inner navds-text-field__input", {
|
|
59
64
|
"navds-combobox__wrapper-inner--virtually-unfocused":
|
|
@@ -83,24 +88,16 @@ export const InputController = forwardRef<
|
|
|
83
88
|
)}
|
|
84
89
|
<div>
|
|
85
90
|
{value && clearButton && (
|
|
86
|
-
<
|
|
87
|
-
type="button"
|
|
91
|
+
<div
|
|
88
92
|
onClick={clearInput}
|
|
89
93
|
className="navds-combobox__button-clear"
|
|
90
|
-
|
|
94
|
+
aria-hidden
|
|
95
|
+
title={translate("clear")}
|
|
91
96
|
>
|
|
92
|
-
<
|
|
93
|
-
|
|
94
|
-
</span>
|
|
95
|
-
<XMarkIcon aria-hidden />
|
|
96
|
-
</button>
|
|
97
|
-
)}
|
|
98
|
-
{toggleListButton && (
|
|
99
|
-
<ToggleListButton
|
|
100
|
-
toggleListButtonLabel={toggleListButtonLabel}
|
|
101
|
-
ref={toggleOpenButtonRef}
|
|
102
|
-
/>
|
|
97
|
+
<XMarkIcon />
|
|
98
|
+
</div>
|
|
103
99
|
)}
|
|
100
|
+
{toggleListButton && <ToggleListButton ref={toggleOpenButtonRef} />}
|
|
104
101
|
</div>
|
|
105
102
|
</div>
|
|
106
103
|
);
|
|
@@ -3,38 +3,22 @@ import { ChevronDownIcon, ChevronUpIcon } from "@navikt/aksel-icons";
|
|
|
3
3
|
import { useFilteredOptionsContext } from "../FilteredOptions/filteredOptionsContext";
|
|
4
4
|
import { useInputContext } from "./Input.context";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
toggleListButtonLabel?: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const ToggleListButton = forwardRef<
|
|
11
|
-
HTMLButtonElement,
|
|
12
|
-
ToggleListButtonProps
|
|
13
|
-
>(({ toggleListButtonLabel }, ref) => {
|
|
6
|
+
export const ToggleListButton = forwardRef<HTMLDivElement>((_, ref) => {
|
|
14
7
|
const { isListOpen, toggleIsListOpen } = useFilteredOptionsContext();
|
|
15
8
|
const { focusInput } = useInputContext();
|
|
9
|
+
|
|
16
10
|
return (
|
|
17
|
-
<
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
<div
|
|
12
|
+
ref={ref}
|
|
13
|
+
onClick={() => {
|
|
20
14
|
toggleIsListOpen();
|
|
21
15
|
focusInput();
|
|
22
16
|
}}
|
|
23
|
-
onKeyDown={({ key }) => key === "Enter" && toggleIsListOpen()}
|
|
24
17
|
className="navds-combobox__button-toggle-list"
|
|
25
|
-
aria-
|
|
26
|
-
tabIndex={-1}
|
|
27
|
-
ref={ref}
|
|
18
|
+
aria-hidden
|
|
28
19
|
>
|
|
29
|
-
<
|
|
30
|
-
|
|
31
|
-
</span>
|
|
32
|
-
{isListOpen ? (
|
|
33
|
-
<ChevronUpIcon aria-hidden />
|
|
34
|
-
) : (
|
|
35
|
-
<ChevronDownIcon aria-hidden />
|
|
36
|
-
)}
|
|
37
|
-
</button>
|
|
20
|
+
{isListOpen ? <ChevronUpIcon /> : <ChevronDownIcon />}
|
|
21
|
+
</div>
|
|
38
22
|
);
|
|
39
23
|
});
|
|
40
24
|
|
|
@@ -14,12 +14,6 @@ const Option = ({ option }: { option: ComboboxOption }) => {
|
|
|
14
14
|
const { isMultiSelect, removeSelectedOption } = useSelectedOptionsContext();
|
|
15
15
|
const { focusInput, readOnly, inputProps } = useInputContext();
|
|
16
16
|
|
|
17
|
-
const onClick = (e) => {
|
|
18
|
-
e.stopPropagation();
|
|
19
|
-
removeSelectedOption(option);
|
|
20
|
-
focusInput();
|
|
21
|
-
};
|
|
22
|
-
|
|
23
17
|
if (!isMultiSelect) {
|
|
24
18
|
return (
|
|
25
19
|
<div className="navds-combobox__selected-options--no-bg">
|
|
@@ -28,12 +22,24 @@ const Option = ({ option }: { option: ComboboxOption }) => {
|
|
|
28
22
|
);
|
|
29
23
|
}
|
|
30
24
|
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
if (readOnly || inputProps.disabled) {
|
|
26
|
+
return (
|
|
27
|
+
<Chips.Toggle variant="neutral" checkmark={false} as="div">
|
|
28
|
+
{option.label}
|
|
29
|
+
</Chips.Toggle>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<Chips.Removable
|
|
35
|
+
onClick={(event) => {
|
|
36
|
+
event.stopPropagation();
|
|
37
|
+
removeSelectedOption(option);
|
|
38
|
+
focusInput();
|
|
39
|
+
}}
|
|
40
|
+
>
|
|
33
41
|
{option.label}
|
|
34
|
-
</Chips.
|
|
35
|
-
) : (
|
|
36
|
-
<Chips.Removable onClick={onClick}>{option.label}</Chips.Removable>
|
|
42
|
+
</Chips.Removable>
|
|
37
43
|
);
|
|
38
44
|
};
|
|
39
45
|
|
|
@@ -3,6 +3,7 @@ import { act, render, screen } from "@testing-library/react";
|
|
|
3
3
|
import userEvent from "@testing-library/user-event";
|
|
4
4
|
import React, { useId } from "react";
|
|
5
5
|
import { describe, expect, test, vi } from "vitest";
|
|
6
|
+
import nb from "../../../util/i18n/locales/nb";
|
|
6
7
|
import { ComboboxProps, UNSAFE_Combobox } from "../index";
|
|
7
8
|
|
|
8
9
|
const options = [
|
|
@@ -73,7 +74,7 @@ describe("Render combobox", () => {
|
|
|
73
74
|
test("Should show loading icon when loading (used for async search)", async () => {
|
|
74
75
|
render(<App options={[]} isListOpen isLoading />);
|
|
75
76
|
|
|
76
|
-
expect(await screen.findByText(
|
|
77
|
+
expect(await screen.findByText(nb.Combobox.loading)).toBeInTheDocument();
|
|
77
78
|
});
|
|
78
79
|
|
|
79
80
|
test("Should not select previous focused element when closes", async () => {
|
|
@@ -132,7 +132,8 @@ export interface ComboboxProps
|
|
|
132
132
|
*/
|
|
133
133
|
limit: number;
|
|
134
134
|
/**
|
|
135
|
-
*
|
|
135
|
+
* Message to display when the limit for maximum selected options has been reached
|
|
136
|
+
* @default "{selected} av maks {limit} er valgt."
|
|
136
137
|
*/
|
|
137
138
|
message?: string;
|
|
138
139
|
};
|
|
@@ -154,12 +155,6 @@ export interface ComboboxProps
|
|
|
154
155
|
* @default true
|
|
155
156
|
*/
|
|
156
157
|
toggleListButton?: boolean;
|
|
157
|
-
/**
|
|
158
|
-
* Custom name for the toggle list-button. Requires "toggleListButton" to be `true`.
|
|
159
|
-
*
|
|
160
|
-
* @default "Alternativer"
|
|
161
|
-
*/
|
|
162
|
-
toggleListButtonLabel?: string;
|
|
163
158
|
/**
|
|
164
159
|
* Set this to override the value of the input field.
|
|
165
160
|
*
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import cl from "clsx";
|
|
2
2
|
import React, { forwardRef } from "react";
|
|
3
3
|
import { Link } from "../../link";
|
|
4
|
+
import { useI18n } from "../../util/i18n/i18n.context";
|
|
4
5
|
import { OverridableComponent } from "../../util/types";
|
|
5
6
|
|
|
6
|
-
// export type FormSummaryEditProps = Partial<LinkProps>;
|
|
7
7
|
export interface FormSummaryEditProps
|
|
8
8
|
extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
9
9
|
/**
|
|
@@ -22,17 +22,18 @@ export interface FormSummaryEditProps
|
|
|
22
22
|
export const FormSummaryEditLink: OverridableComponent<
|
|
23
23
|
FormSummaryEditProps,
|
|
24
24
|
HTMLAnchorElement
|
|
25
|
-
> = forwardRef(
|
|
26
|
-
|
|
25
|
+
> = forwardRef(({ children, className, as = "a", ...rest }, ref) => {
|
|
26
|
+
const translate = useI18n("FormSummary");
|
|
27
|
+
return (
|
|
27
28
|
<Link
|
|
28
29
|
ref={ref}
|
|
29
30
|
as={as}
|
|
30
31
|
{...rest}
|
|
31
32
|
className={cl("navds-form-summary__edit", className)}
|
|
32
33
|
>
|
|
33
|
-
{children}
|
|
34
|
+
{children || translate("editAnswer")}
|
|
34
35
|
</Link>
|
|
35
|
-
)
|
|
36
|
-
);
|
|
36
|
+
);
|
|
37
|
+
});
|
|
37
38
|
|
|
38
39
|
export default FormSummaryEditLink;
|
|
@@ -6,6 +6,8 @@ import React, {
|
|
|
6
6
|
useState,
|
|
7
7
|
} from "react";
|
|
8
8
|
import { MagnifyingGlassIcon, XMarkIcon } from "@navikt/aksel-icons";
|
|
9
|
+
import { Button } from "../../button";
|
|
10
|
+
import { UNSAFE_useAkselTheme } from "../../provider";
|
|
9
11
|
import { BodyShort, ErrorMessage, Label } from "../../typography";
|
|
10
12
|
import { omit } from "../../util";
|
|
11
13
|
import { useMergeRefs } from "../../util/hooks/useMergeRefs";
|
|
@@ -122,6 +124,8 @@ export const Search = forwardRef<HTMLInputElement, SearchProps>(
|
|
|
122
124
|
...rest
|
|
123
125
|
} = props;
|
|
124
126
|
|
|
127
|
+
const themeContext = UNSAFE_useAkselTheme(false);
|
|
128
|
+
|
|
125
129
|
const searchRef = useRef<HTMLInputElement | null>(null);
|
|
126
130
|
const mergedRef = useMergeRefs(searchRef, ref);
|
|
127
131
|
const translate = useI18n("Search");
|
|
@@ -142,6 +146,34 @@ export const Search = forwardRef<HTMLInputElement, SearchProps>(
|
|
|
142
146
|
onSearchClick?.(`${value ?? internalValue}`);
|
|
143
147
|
};
|
|
144
148
|
|
|
149
|
+
const showClearButton =
|
|
150
|
+
clearButton && !inputProps.disabled && (value ?? internalValue);
|
|
151
|
+
|
|
152
|
+
const ClearButton = () =>
|
|
153
|
+
themeContext ? (
|
|
154
|
+
<Button
|
|
155
|
+
className="navds-search__button-clear"
|
|
156
|
+
variant="tertiary-neutral"
|
|
157
|
+
size={size === "medium" ? "small" : "xsmall"}
|
|
158
|
+
icon={<XMarkIcon aria-hidden />}
|
|
159
|
+
title={clearButtonLabel || translate("clear")}
|
|
160
|
+
hidden={!showClearButton}
|
|
161
|
+
onClick={(event) => handleClear({ trigger: "Click", event })}
|
|
162
|
+
/>
|
|
163
|
+
) : (
|
|
164
|
+
<button
|
|
165
|
+
type="button"
|
|
166
|
+
onClick={(event) => handleClear({ trigger: "Click", event })}
|
|
167
|
+
className="navds-search__button-clear"
|
|
168
|
+
hidden={!showClearButton}
|
|
169
|
+
>
|
|
170
|
+
<span className="navds-sr-only">
|
|
171
|
+
{clearButtonLabel || translate("clear")}
|
|
172
|
+
</span>
|
|
173
|
+
<XMarkIcon aria-hidden />
|
|
174
|
+
</button>
|
|
175
|
+
);
|
|
176
|
+
|
|
145
177
|
return (
|
|
146
178
|
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
147
179
|
<div
|
|
@@ -210,18 +242,7 @@ export const Search = forwardRef<HTMLInputElement, SearchProps>(
|
|
|
210
242
|
)}
|
|
211
243
|
{...(htmlSize ? { size: Number(htmlSize) } : {})}
|
|
212
244
|
/>
|
|
213
|
-
|
|
214
|
-
<button
|
|
215
|
-
type="button"
|
|
216
|
-
onClick={(event) => handleClear({ trigger: "Click", event })}
|
|
217
|
-
className="navds-search__button-clear"
|
|
218
|
-
>
|
|
219
|
-
<span className="navds-sr-only">
|
|
220
|
-
{clearButtonLabel || translate("clear")}
|
|
221
|
-
</span>
|
|
222
|
-
<XMarkIcon aria-hidden />
|
|
223
|
-
</button>
|
|
224
|
-
)}
|
|
245
|
+
<ClearButton />
|
|
225
246
|
</div>
|
|
226
247
|
<SearchContext.Provider
|
|
227
248
|
value={{
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { SVGProps } from "react";
|
|
2
2
|
import { useId } from "../util/hooks";
|
|
3
|
+
import { useI18n } from "../util/i18n/i18n.context";
|
|
3
4
|
|
|
4
5
|
interface SVGRProps {
|
|
5
6
|
title?: string;
|
|
@@ -15,6 +16,8 @@ export const DefaultIllustration: DefaultIllustrationType = ({
|
|
|
15
16
|
titleId: _titleId,
|
|
16
17
|
...props
|
|
17
18
|
}) => {
|
|
19
|
+
const translate = useI18n("GuidePanel");
|
|
20
|
+
|
|
18
21
|
let titleId: string | undefined = useId();
|
|
19
22
|
titleId = title ? (_titleId ? _titleId : "title-" + titleId) : undefined;
|
|
20
23
|
|
|
@@ -25,7 +28,7 @@ export const DefaultIllustration: DefaultIllustrationType = ({
|
|
|
25
28
|
viewBox="0 0 56 85"
|
|
26
29
|
fill="none"
|
|
27
30
|
xmlns="http://www.w3.org/2000/svg"
|
|
28
|
-
aria-label="
|
|
31
|
+
aria-label={translate("illustrationLabel")}
|
|
29
32
|
focusable={false}
|
|
30
33
|
role="img"
|
|
31
34
|
aria-labelledby={titleId}
|
|
@@ -4,6 +4,7 @@ import { Popover, PopoverProps } from "../popover";
|
|
|
4
4
|
import { UNSAFE_useAkselTheme } from "../provider";
|
|
5
5
|
import { composeEventHandlers } from "../util/composeEventHandlers";
|
|
6
6
|
import { useMergeRefs } from "../util/hooks/useMergeRefs";
|
|
7
|
+
import { useI18n } from "../util/i18n/i18n.context";
|
|
7
8
|
import { HelpTextIcon } from "./HelpTextIcon";
|
|
8
9
|
|
|
9
10
|
export interface HelpTextProps
|
|
@@ -12,7 +13,7 @@ export interface HelpTextProps
|
|
|
12
13
|
children: React.ReactNode;
|
|
13
14
|
/**
|
|
14
15
|
* Adds a title-tooltip with the given text
|
|
15
|
-
* @default "
|
|
16
|
+
* @default "Mer informasjon"
|
|
16
17
|
*/
|
|
17
18
|
title?: string;
|
|
18
19
|
/**
|
|
@@ -41,7 +42,7 @@ export const HelpText = forwardRef<HTMLButtonElement, HelpTextProps>(
|
|
|
41
42
|
children,
|
|
42
43
|
placement,
|
|
43
44
|
strategy = "absolute",
|
|
44
|
-
title
|
|
45
|
+
title,
|
|
45
46
|
onClick,
|
|
46
47
|
wrapperClassName,
|
|
47
48
|
...rest
|
|
@@ -50,10 +51,11 @@ export const HelpText = forwardRef<HTMLButtonElement, HelpTextProps>(
|
|
|
50
51
|
) => {
|
|
51
52
|
const buttonRef = useRef<HTMLButtonElement | null>(null);
|
|
52
53
|
const mergedRef = useMergeRefs(buttonRef, ref);
|
|
53
|
-
|
|
54
54
|
const [open, setOpen] = useState(false);
|
|
55
|
-
|
|
56
55
|
const themeContext = UNSAFE_useAkselTheme(false);
|
|
56
|
+
const translate = useI18n("HelpText");
|
|
57
|
+
|
|
58
|
+
const titleWithFallback = title || translate("title");
|
|
57
59
|
|
|
58
60
|
return (
|
|
59
61
|
<div className={cl("navds-help-text", wrapperClassName)}>
|
|
@@ -65,8 +67,8 @@ export const HelpText = forwardRef<HTMLButtonElement, HelpTextProps>(
|
|
|
65
67
|
type="button"
|
|
66
68
|
aria-expanded={open}
|
|
67
69
|
>
|
|
68
|
-
<HelpTextIcon title={
|
|
69
|
-
<HelpTextIcon filled title={
|
|
70
|
+
<HelpTextIcon title={titleWithFallback} />
|
|
71
|
+
<HelpTextIcon filled title={titleWithFallback} />
|
|
70
72
|
</button>
|
|
71
73
|
<Popover
|
|
72
74
|
onClose={() => setOpen(false)}
|
|
@@ -3,7 +3,7 @@ import React, { forwardRef } from "react";
|
|
|
3
3
|
import { OverridableComponent } from "../util/types";
|
|
4
4
|
|
|
5
5
|
export interface InternalHeaderButtonProps
|
|
6
|
-
extends React.
|
|
6
|
+
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
7
7
|
/**
|
|
8
8
|
* Application Button
|
|
9
9
|
*/
|
|
@@ -6,7 +6,7 @@ import { OverridableComponent } from "../util/types";
|
|
|
6
6
|
import InternalHeaderButton from "./InternalHeaderButton";
|
|
7
7
|
|
|
8
8
|
export interface InternalHeaderUserButtonProps
|
|
9
|
-
extends React.
|
|
9
|
+
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
10
10
|
/**
|
|
11
11
|
* User name
|
|
12
12
|
*/
|
|
@@ -33,7 +33,7 @@ export const InternalHeaderUserButton: OverridableComponent<
|
|
|
33
33
|
</BodyShort>
|
|
34
34
|
{description && <Detail as="div">{description}</Detail>}
|
|
35
35
|
</div>
|
|
36
|
-
<ChevronDownIcon
|
|
36
|
+
<ChevronDownIcon aria-hidden />
|
|
37
37
|
</InternalHeaderButton>
|
|
38
38
|
));
|
|
39
39
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import cl from "clsx";
|
|
2
2
|
import React from "react";
|
|
3
|
+
import { UNSAFE_useAkselTheme } from "../../provider";
|
|
3
4
|
import { Slot } from "../../slot/Slot";
|
|
4
5
|
import { getResponsiveProps, getResponsiveValue } from "../utilities/css";
|
|
5
6
|
import { ResponsiveProp, SpacingScale } from "../utilities/types";
|
|
@@ -251,39 +252,42 @@ export const BasePrimitive = ({
|
|
|
251
252
|
flexShrink,
|
|
252
253
|
gridColumn,
|
|
253
254
|
}: BasePrimitiveProps) => {
|
|
255
|
+
const themeContext = UNSAFE_useAkselTheme(false);
|
|
256
|
+
const prefix = themeContext ? "ax" : "a";
|
|
257
|
+
|
|
254
258
|
const style: React.CSSProperties = {
|
|
255
259
|
/* Padding */
|
|
256
|
-
...getResponsiveProps("r", "p", "spacing", padding),
|
|
257
|
-
...getResponsiveProps("r", "pi", "spacing", paddingInline),
|
|
258
|
-
...getResponsiveProps("r", "pb", "spacing", paddingBlock),
|
|
260
|
+
...getResponsiveProps(prefix, "r", "p", "spacing", padding),
|
|
261
|
+
...getResponsiveProps(prefix, "r", "pi", "spacing", paddingInline),
|
|
262
|
+
...getResponsiveProps(prefix, "r", "pb", "spacing", paddingBlock),
|
|
259
263
|
/* Margin */
|
|
260
|
-
...getResponsiveProps("r", "m", "spacing", margin),
|
|
261
|
-
...getResponsiveProps("r", "mi", "spacing", marginInline),
|
|
262
|
-
...getResponsiveProps("r", "mb", "spacing", marginBlock),
|
|
264
|
+
...getResponsiveProps(prefix, "r", "m", "spacing", margin),
|
|
265
|
+
...getResponsiveProps(prefix, "r", "mi", "spacing", marginInline),
|
|
266
|
+
...getResponsiveProps(prefix, "r", "mb", "spacing", marginBlock),
|
|
263
267
|
/* Width & height */
|
|
264
|
-
...getResponsiveValue("r", "w", width),
|
|
265
|
-
...getResponsiveValue("r", "minw", minWidth),
|
|
266
|
-
...getResponsiveValue("r", "maxw", maxWidth),
|
|
267
|
-
...getResponsiveValue("r", "h", height),
|
|
268
|
-
...getResponsiveValue("r", "minh", minHeight),
|
|
269
|
-
...getResponsiveValue("r", "maxh", maxHeight),
|
|
268
|
+
...getResponsiveValue(prefix, "r", "w", width),
|
|
269
|
+
...getResponsiveValue(prefix, "r", "minw", minWidth),
|
|
270
|
+
...getResponsiveValue(prefix, "r", "maxw", maxWidth),
|
|
271
|
+
...getResponsiveValue(prefix, "r", "h", height),
|
|
272
|
+
...getResponsiveValue(prefix, "r", "minh", minHeight),
|
|
273
|
+
...getResponsiveValue(prefix, "r", "maxh", maxHeight),
|
|
270
274
|
/* Positon & inset */
|
|
271
|
-
...getResponsiveValue("r", "position", position),
|
|
272
|
-
...getResponsiveProps("r", "inset", "spacing", inset),
|
|
273
|
-
...getResponsiveProps("r", "top", "spacing", top),
|
|
274
|
-
...getResponsiveProps("r", "right", "spacing", right),
|
|
275
|
-
...getResponsiveProps("r", "bottom", "spacing", bottom),
|
|
276
|
-
...getResponsiveProps("r", "left", "spacing", left),
|
|
275
|
+
...getResponsiveValue(prefix, "r", "position", position),
|
|
276
|
+
...getResponsiveProps(prefix, "r", "inset", "spacing", inset),
|
|
277
|
+
...getResponsiveProps(prefix, "r", "top", "spacing", top),
|
|
278
|
+
...getResponsiveProps(prefix, "r", "right", "spacing", right),
|
|
279
|
+
...getResponsiveProps(prefix, "r", "bottom", "spacing", bottom),
|
|
280
|
+
...getResponsiveProps(prefix, "r", "left", "spacing", left),
|
|
277
281
|
/* Overflow */
|
|
278
|
-
...getResponsiveValue("r", "overflow", overflow),
|
|
279
|
-
...getResponsiveValue("r", "overflowx", overflowX),
|
|
280
|
-
...getResponsiveValue("r", "overflowy", overflowY),
|
|
282
|
+
...getResponsiveValue(prefix, "r", "overflow", overflow),
|
|
283
|
+
...getResponsiveValue(prefix, "r", "overflowx", overflowX),
|
|
284
|
+
...getResponsiveValue(prefix, "r", "overflowy", overflowY),
|
|
281
285
|
/* Flex */
|
|
282
|
-
...getResponsiveValue("r", "flex-basis", flexBasis),
|
|
283
|
-
...getResponsiveValue("r", "flex-grow", flexGrow),
|
|
284
|
-
...getResponsiveValue("r", "flex-shrink", flexShrink),
|
|
286
|
+
...getResponsiveValue(prefix, "r", "flex-basis", flexBasis),
|
|
287
|
+
...getResponsiveValue(prefix, "r", "flex-grow", flexGrow),
|
|
288
|
+
...getResponsiveValue(prefix, "r", "flex-shrink", flexShrink),
|
|
285
289
|
/* Grid */
|
|
286
|
-
...getResponsiveValue("r", "grid-column", gridColumn),
|
|
290
|
+
...getResponsiveValue(prefix, "r", "grid-column", gridColumn),
|
|
287
291
|
};
|
|
288
292
|
|
|
289
293
|
return (
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import cl from "clsx";
|
|
2
2
|
import React, { forwardRef } from "react";
|
|
3
|
+
import { UNSAFE_useAkselTheme } from "../../provider";
|
|
3
4
|
import { Slot } from "../../slot/Slot";
|
|
4
5
|
import { getResponsiveProps } from "../utilities/css";
|
|
5
6
|
import { ResponsiveProp, SpacingScale } from "../utilities/types";
|
|
@@ -80,9 +81,13 @@ export const Bleed = forwardRef<HTMLDivElement, BleedProps>(
|
|
|
80
81
|
},
|
|
81
82
|
ref,
|
|
82
83
|
) => {
|
|
84
|
+
const themeContext = UNSAFE_useAkselTheme(false);
|
|
85
|
+
const prefix = themeContext ? "ax" : "a";
|
|
86
|
+
|
|
83
87
|
let style: React.CSSProperties = {
|
|
84
88
|
..._style,
|
|
85
89
|
...getResponsiveProps(
|
|
90
|
+
prefix,
|
|
86
91
|
"bleed",
|
|
87
92
|
"margin-inline",
|
|
88
93
|
"spacing",
|
|
@@ -92,6 +97,7 @@ export const Bleed = forwardRef<HTMLDivElement, BleedProps>(
|
|
|
92
97
|
),
|
|
93
98
|
|
|
94
99
|
...getResponsiveProps(
|
|
100
|
+
prefix,
|
|
95
101
|
"bleed",
|
|
96
102
|
"margin-block",
|
|
97
103
|
"spacing",
|
|
@@ -105,6 +111,7 @@ export const Bleed = forwardRef<HTMLDivElement, BleedProps>(
|
|
|
105
111
|
style = {
|
|
106
112
|
...style,
|
|
107
113
|
...getResponsiveProps(
|
|
114
|
+
prefix,
|
|
108
115
|
"bleed",
|
|
109
116
|
"padding-inline",
|
|
110
117
|
"spacing",
|
|
@@ -113,6 +120,7 @@ export const Bleed = forwardRef<HTMLDivElement, BleedProps>(
|
|
|
113
120
|
["0", "full", "px"],
|
|
114
121
|
),
|
|
115
122
|
...getResponsiveProps(
|
|
123
|
+
prefix,
|
|
116
124
|
"bleed",
|
|
117
125
|
"padding-block",
|
|
118
126
|
"spacing",
|