@navikt/ds-react 7.10.0 → 7.11.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/form/combobox/Combobox.d.ts +1 -1
- package/cjs/form/combobox/Input/InputController.d.ts +1 -1
- package/cjs/modal/types.test-d.d.ts +1 -0
- package/cjs/modal/types.test-d.js +67 -0
- package/cjs/modal/types.test-d.js.map +1 -0
- package/cjs/tabs/Tabs.context.d.ts +1 -1
- package/cjs/util/i18n/i18n.context.d.ts +9 -0
- package/cjs/util/i18n/i18n.context.js +54 -0
- package/cjs/util/i18n/i18n.context.js.map +1 -0
- package/esm/form/combobox/Combobox.d.ts +1 -1
- package/esm/form/combobox/Input/InputController.d.ts +1 -1
- package/esm/modal/types.test-d.d.ts +1 -0
- package/esm/modal/types.test-d.js +65 -0
- package/esm/modal/types.test-d.js.map +1 -0
- package/esm/tabs/Tabs.context.d.ts +1 -1
- package/esm/util/i18n/i18n.context.d.ts +9 -0
- package/esm/util/i18n/i18n.context.js +50 -0
- package/esm/util/i18n/i18n.context.js.map +1 -0
- package/package.json +7 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { ComboboxProps } from "./types";
|
|
3
|
-
export declare const Combobox: React.ForwardRefExoticComponent<Omit<ComboboxProps, "
|
|
3
|
+
export declare const Combobox: React.ForwardRefExoticComponent<Omit<ComboboxProps, "disabled" | "onChange" | "value" | "options" | "size" | "onClear"> & React.RefAttributes<HTMLInputElement>>;
|
|
4
4
|
export default Combobox;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { ComboboxProps } from "../types";
|
|
3
|
-
export declare const InputController: React.ForwardRefExoticComponent<Omit<ComboboxProps, "
|
|
3
|
+
export declare const InputController: React.ForwardRefExoticComponent<Omit<ComboboxProps, "disabled" | "onChange" | "value" | "options" | "label" | "size" | "hideLabel" | "description" | "onClear"> & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
test("ModalProps works as intended", () => {
|
|
5
|
+
(0, vitest_1.expectTypeOf)({
|
|
6
|
+
header: { heading: "Label" },
|
|
7
|
+
children: "OK",
|
|
8
|
+
}).toMatchTypeOf();
|
|
9
|
+
(0, vitest_1.expectTypeOf)({
|
|
10
|
+
header: { heading: "Label" },
|
|
11
|
+
"aria-label": "Label",
|
|
12
|
+
children: "OK",
|
|
13
|
+
}).toMatchTypeOf();
|
|
14
|
+
(0, vitest_1.expectTypeOf)({
|
|
15
|
+
header: { heading: "Label" },
|
|
16
|
+
"aria-labelledby": "Label",
|
|
17
|
+
children: "OK",
|
|
18
|
+
}).toMatchTypeOf();
|
|
19
|
+
(0, vitest_1.expectTypeOf)({
|
|
20
|
+
"aria-label": "Label",
|
|
21
|
+
children: "OK",
|
|
22
|
+
}).toMatchTypeOf();
|
|
23
|
+
(0, vitest_1.expectTypeOf)({
|
|
24
|
+
"aria-labelledby": "Label",
|
|
25
|
+
children: "OK",
|
|
26
|
+
}).toMatchTypeOf();
|
|
27
|
+
(0, vitest_1.expectTypeOf)({
|
|
28
|
+
"aria-label": "Label",
|
|
29
|
+
open: true,
|
|
30
|
+
onClose: () => null,
|
|
31
|
+
children: "OK",
|
|
32
|
+
}).toMatchTypeOf();
|
|
33
|
+
(0, vitest_1.expectTypeOf)({
|
|
34
|
+
children: "Mangler label",
|
|
35
|
+
}).not.toMatchTypeOf();
|
|
36
|
+
(0, vitest_1.expectTypeOf)({
|
|
37
|
+
open: true,
|
|
38
|
+
children: "Mangler onClose eller label",
|
|
39
|
+
}).not.toMatchTypeOf();
|
|
40
|
+
(0, vitest_1.expectTypeOf)({
|
|
41
|
+
open: true,
|
|
42
|
+
"aria-label": "Label",
|
|
43
|
+
children: "Mangler onClose",
|
|
44
|
+
}).not.toMatchTypeOf();
|
|
45
|
+
(0, vitest_1.expectTypeOf)({
|
|
46
|
+
open: true,
|
|
47
|
+
onClose: () => null,
|
|
48
|
+
children: "Mangler label",
|
|
49
|
+
}).not.toMatchTypeOf();
|
|
50
|
+
(0, vitest_1.expectTypeOf)({
|
|
51
|
+
header: { heading: "Label" },
|
|
52
|
+
open: true,
|
|
53
|
+
children: "Mangler onClose",
|
|
54
|
+
}).not.toMatchTypeOf();
|
|
55
|
+
(0, vitest_1.expectTypeOf)({
|
|
56
|
+
header: { heading: "Label" },
|
|
57
|
+
"aria-label": "Label",
|
|
58
|
+
"aria-labelledby": "Label",
|
|
59
|
+
children: "For mange labels",
|
|
60
|
+
}).not.toMatchTypeOf();
|
|
61
|
+
(0, vitest_1.expectTypeOf)({
|
|
62
|
+
"aria-label": "Label",
|
|
63
|
+
"aria-labelledby": "Label",
|
|
64
|
+
children: "For mange labels",
|
|
65
|
+
}).not.toMatchTypeOf();
|
|
66
|
+
});
|
|
67
|
+
//# sourceMappingURL=types.test-d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.test-d.js","sourceRoot":"","sources":["../../src/modal/types.test-d.ts"],"names":[],"mappings":";;AAAA,mCAAsC;AAGtC,IAAI,CAAC,8BAA8B,EAAE,GAAG,EAAE;IACxC,IAAA,qBAAY,EAAC;QACX,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE;QAC5B,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC,aAAa,EAAc,CAAC;IAE/B,IAAA,qBAAY,EAAC;QACX,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE;QAC5B,YAAY,EAAE,OAAO;QACrB,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC,aAAa,EAAc,CAAC;IAE/B,IAAA,qBAAY,EAAC;QACX,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE;QA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,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE;QAC5B,YAAY,EAAE,OAAO;QACrB,iBAAiB,EAAE,OAAO;QAC1B,QAAQ,EAAE,kBAAkB;KAC7B,CAAC,CAAC,GAAG,CAAC,aAAa,EAAc,CAAC;IAEnC,IAAA,qBAAY,EAAC;QACX,YAAY,EAAE,OAAO;QACrB,iBAAiB,EAAE,OAAO;QAC1B,QAAQ,EAAE,kBAAkB;KAC7B,CAAC,CAAC,GAAG,CAAC,aAAa,EAAc,CAAC;AACrC,CAAC,CAAC,CAAC"}
|
|
@@ -27,7 +27,7 @@ export declare const TabsProvider: import("react").ForwardRefExoticComponent<{
|
|
|
27
27
|
setFocusedValue: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
28
28
|
makeTabId: (id: string, value: string) => string;
|
|
29
29
|
makeTabPanelId: (id: string, value: string) => string;
|
|
30
|
-
} & Pick<TabsProps, "
|
|
30
|
+
} & Pick<TabsProps, "fill" | "size" | "iconPosition" | "loop" | "selectionFollowsFocus"> & {
|
|
31
31
|
children: import("react").ReactNode;
|
|
32
32
|
} & import("react").RefAttributes<unknown>>, useTabsContext: <S extends boolean = true>(strict?: S) => S extends true ? TabsProviderProps : TabsProviderProps | undefined;
|
|
33
33
|
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Locale } from "date-fns";
|
|
2
|
+
import { Component, ComponentTranslation, Translations } from "./i18n.types";
|
|
3
|
+
type NestedKeyOf<ObjectType extends object> = {
|
|
4
|
+
[Key in keyof ObjectType & (string | number)]: ObjectType[Key] extends object ? `${Key}.${NestedKeyOf<ObjectType[Key]>}` : `${Key}`;
|
|
5
|
+
}[keyof ObjectType & (string | number)];
|
|
6
|
+
export type TFunction<T extends Component> = (keypath: NestedKeyOf<Translations[T]>, replacements?: Record<string, string | number>) => string;
|
|
7
|
+
export declare function useI18n<T extends Component>(componentName: T, ...localTranslations: (ComponentTranslation<T> | undefined)[]): TFunction<T>;
|
|
8
|
+
export declare function useDateLocale(): Locale;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useI18n = useI18n;
|
|
4
|
+
exports.useDateLocale = useDateLocale;
|
|
5
|
+
const Provider_1 = require("../../provider/Provider");
|
|
6
|
+
const get_1 = require("./get");
|
|
7
|
+
/**
|
|
8
|
+
* https://regex101.com/r/LYKWi3/1
|
|
9
|
+
*/
|
|
10
|
+
const REPLACE_REGEX = /{[^}]*}/g;
|
|
11
|
+
function useI18n(componentName, ...localTranslations) {
|
|
12
|
+
const context = (0, Provider_1.useProvider)();
|
|
13
|
+
const contextTranslations = context.translations || [];
|
|
14
|
+
const i18nObjects = [
|
|
15
|
+
...localTranslations,
|
|
16
|
+
...(Array.isArray(contextTranslations)
|
|
17
|
+
? contextTranslations.map((t) => t[componentName])
|
|
18
|
+
: [contextTranslations[componentName]]),
|
|
19
|
+
context.locale[componentName],
|
|
20
|
+
];
|
|
21
|
+
/**
|
|
22
|
+
* https://github.com/Shopify/polaris/blob/2115f9ba2f5bcbf2ad15745233501bff2db81ecf/polaris-react/src/utilities/i18n/I18n.ts#L24
|
|
23
|
+
*/
|
|
24
|
+
const translate = (keypath, replacements) => {
|
|
25
|
+
const text = (0, get_1.get)(keypath, i18nObjects);
|
|
26
|
+
if (replacements) {
|
|
27
|
+
return text.replace(REPLACE_REGEX, (match) => {
|
|
28
|
+
const replacement = match.substring(1, match.length - 1);
|
|
29
|
+
if (replacements[replacement] === undefined) {
|
|
30
|
+
const replacementData = JSON.stringify(replacements);
|
|
31
|
+
throw new Error(`Error translating key '${keypath}'. No replacement syntax ({}) found for key '${replacement}'. The following replacements were passed: '${replacementData}'`);
|
|
32
|
+
}
|
|
33
|
+
return replacements[replacement]; // can also be a number, but JS doesn't mind...
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return text;
|
|
37
|
+
};
|
|
38
|
+
return translate;
|
|
39
|
+
}
|
|
40
|
+
function useDateLocale() {
|
|
41
|
+
const context = (0, Provider_1.useProvider)();
|
|
42
|
+
const contextTranslations = context.translations || [];
|
|
43
|
+
const i18nObjects = Array.isArray(contextTranslations)
|
|
44
|
+
? contextTranslations.map((t) => t.global)
|
|
45
|
+
: [contextTranslations.global];
|
|
46
|
+
i18nObjects.push(context.locale.global);
|
|
47
|
+
for (const obj of i18nObjects) {
|
|
48
|
+
if (obj === null || obj === void 0 ? void 0 : obj.dateLocale) {
|
|
49
|
+
return obj.dateLocale;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
throw new Error("dateLocale not found.");
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=i18n.context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.context.js","sourceRoot":"","sources":["../../../src/util/i18n/i18n.context.ts"],"names":[],"mappings":";;AA2BA,0BAuCC;AAED,sCAcC;AAjFD,sDAAsD;AACtD,+BAA4B;AAQ5B;;GAEG;AACH,MAAM,aAAa,GAAG,UAAU,CAAC;AAcjC,SAAgB,OAAO,CACrB,aAAgB,EAChB,GAAG,iBAA0D;IAE7D,MAAM,OAAO,GAAG,IAAA,sBAAW,GAAE,CAAC;IAC9B,MAAM,mBAAmB,GAAG,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC;IACvD,MAAM,WAAW,GAAwC;QACvD,GAAG,iBAAiB;QACpB,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,mBAAmB,CAAC;YACpC,CAAC,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC;YAClD,CAAC,CAAC,CAAC,mBAAmB,CAAC,aAAa,CAAC,CAAC,CAAC;QACzC,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC;KAC9B,CAAC;IAEF;;OAEG;IACH,MAAM,SAAS,GAAiB,CAAC,OAAO,EAAE,YAAY,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CAAC;YACpB,OAAO,GAAG,CAAC,UAAoB,CAAC;QAClC,CAAC;IACH,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { ComboboxProps } from "./types.js";
|
|
3
|
-
export declare const Combobox: React.ForwardRefExoticComponent<Omit<ComboboxProps, "
|
|
3
|
+
export declare const Combobox: React.ForwardRefExoticComponent<Omit<ComboboxProps, "disabled" | "onChange" | "value" | "options" | "size" | "onClear"> & React.RefAttributes<HTMLInputElement>>;
|
|
4
4
|
export default Combobox;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { ComboboxProps } from "../types.js";
|
|
3
|
-
export declare const InputController: React.ForwardRefExoticComponent<Omit<ComboboxProps, "
|
|
3
|
+
export declare const InputController: React.ForwardRefExoticComponent<Omit<ComboboxProps, "disabled" | "onChange" | "value" | "options" | "label" | "size" | "hideLabel" | "description" | "onClear"> & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { expectTypeOf } from "vitest";
|
|
2
|
+
test("ModalProps works as intended", () => {
|
|
3
|
+
expectTypeOf({
|
|
4
|
+
header: { heading: "Label" },
|
|
5
|
+
children: "OK",
|
|
6
|
+
}).toMatchTypeOf();
|
|
7
|
+
expectTypeOf({
|
|
8
|
+
header: { heading: "Label" },
|
|
9
|
+
"aria-label": "Label",
|
|
10
|
+
children: "OK",
|
|
11
|
+
}).toMatchTypeOf();
|
|
12
|
+
expectTypeOf({
|
|
13
|
+
header: { heading: "Label" },
|
|
14
|
+
"aria-labelledby": "Label",
|
|
15
|
+
children: "OK",
|
|
16
|
+
}).toMatchTypeOf();
|
|
17
|
+
expectTypeOf({
|
|
18
|
+
"aria-label": "Label",
|
|
19
|
+
children: "OK",
|
|
20
|
+
}).toMatchTypeOf();
|
|
21
|
+
expectTypeOf({
|
|
22
|
+
"aria-labelledby": "Label",
|
|
23
|
+
children: "OK",
|
|
24
|
+
}).toMatchTypeOf();
|
|
25
|
+
expectTypeOf({
|
|
26
|
+
"aria-label": "Label",
|
|
27
|
+
open: true,
|
|
28
|
+
onClose: () => null,
|
|
29
|
+
children: "OK",
|
|
30
|
+
}).toMatchTypeOf();
|
|
31
|
+
expectTypeOf({
|
|
32
|
+
children: "Mangler label",
|
|
33
|
+
}).not.toMatchTypeOf();
|
|
34
|
+
expectTypeOf({
|
|
35
|
+
open: true,
|
|
36
|
+
children: "Mangler onClose eller label",
|
|
37
|
+
}).not.toMatchTypeOf();
|
|
38
|
+
expectTypeOf({
|
|
39
|
+
open: true,
|
|
40
|
+
"aria-label": "Label",
|
|
41
|
+
children: "Mangler onClose",
|
|
42
|
+
}).not.toMatchTypeOf();
|
|
43
|
+
expectTypeOf({
|
|
44
|
+
open: true,
|
|
45
|
+
onClose: () => null,
|
|
46
|
+
children: "Mangler label",
|
|
47
|
+
}).not.toMatchTypeOf();
|
|
48
|
+
expectTypeOf({
|
|
49
|
+
header: { heading: "Label" },
|
|
50
|
+
open: true,
|
|
51
|
+
children: "Mangler onClose",
|
|
52
|
+
}).not.toMatchTypeOf();
|
|
53
|
+
expectTypeOf({
|
|
54
|
+
header: { heading: "Label" },
|
|
55
|
+
"aria-label": "Label",
|
|
56
|
+
"aria-labelledby": "Label",
|
|
57
|
+
children: "For mange labels",
|
|
58
|
+
}).not.toMatchTypeOf();
|
|
59
|
+
expectTypeOf({
|
|
60
|
+
"aria-label": "Label",
|
|
61
|
+
"aria-labelledby": "Label",
|
|
62
|
+
children: "For mange labels",
|
|
63
|
+
}).not.toMatchTypeOf();
|
|
64
|
+
});
|
|
65
|
+
//# sourceMappingURL=types.test-d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.test-d.js","sourceRoot":"","sources":["../../src/modal/types.test-d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CAAC,CAAC,GAAG,CAAC,aAAa,EAAc,CAAC;IAEnC,YAAY,CAAC;QACX,IAAI,EAAE,IAAI;QACV,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI;QACnB,QAAQ,EAAE,eAAe;KAC1B,CAAC,CAAC,GAAG,CAAC,aAAa,EAAc,CAAC;IAEnC,YAAY,CAAC;QACX,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE;QAC5B,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,iBAAiB;KAC5B,CAAC,CAAC,GAAG,CAAC,aAAa,EAAc,CAAC;IAEnC,YAAY,CAAC;QACX,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE;QAC5B,YAAY,EAAE,OAAO;QACrB,iBAAiB,EAAE,OAAO;QAC1B,QAAQ,EAAE,kBAAkB;KAC7B,CAAC,CAAC,GAAG,CAAC,aAAa,EAAc,CAAC;IAEnC,YAAY,CAAC;QACX,YAAY,EAAE,OAAO;QACrB,iBAAiB,EAAE,OAAO;QAC1B,QAAQ,EAAE,kBAAkB;KAC7B,CAAC,CAAC,GAAG,CAAC,aAAa,EAAc,CAAC;AACrC,CAAC,CAAC,CAAC"}
|
|
@@ -27,7 +27,7 @@ export declare const TabsProvider: import("react").ForwardRefExoticComponent<{
|
|
|
27
27
|
setFocusedValue: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
28
28
|
makeTabId: (id: string, value: string) => string;
|
|
29
29
|
makeTabPanelId: (id: string, value: string) => string;
|
|
30
|
-
} & Pick<TabsProps, "
|
|
30
|
+
} & Pick<TabsProps, "fill" | "size" | "iconPosition" | "loop" | "selectionFollowsFocus"> & {
|
|
31
31
|
children: import("react").ReactNode;
|
|
32
32
|
} & import("react").RefAttributes<unknown>>, useTabsContext: <S extends boolean = true>(strict?: S) => S extends true ? TabsProviderProps : TabsProviderProps | undefined;
|
|
33
33
|
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Locale } from "date-fns";
|
|
2
|
+
import { Component, ComponentTranslation, Translations } from "./i18n.types.js";
|
|
3
|
+
type NestedKeyOf<ObjectType extends object> = {
|
|
4
|
+
[Key in keyof ObjectType & (string | number)]: ObjectType[Key] extends object ? `${Key}.${NestedKeyOf<ObjectType[Key]>}` : `${Key}`;
|
|
5
|
+
}[keyof ObjectType & (string | number)];
|
|
6
|
+
export type TFunction<T extends Component> = (keypath: NestedKeyOf<Translations[T]>, replacements?: Record<string, string | number>) => string;
|
|
7
|
+
export declare function useI18n<T extends Component>(componentName: T, ...localTranslations: (ComponentTranslation<T> | undefined)[]): TFunction<T>;
|
|
8
|
+
export declare function useDateLocale(): Locale;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useProvider } from "../../provider/Provider.js";
|
|
2
|
+
import { get } from "./get.js";
|
|
3
|
+
/**
|
|
4
|
+
* https://regex101.com/r/LYKWi3/1
|
|
5
|
+
*/
|
|
6
|
+
const REPLACE_REGEX = /{[^}]*}/g;
|
|
7
|
+
export function useI18n(componentName, ...localTranslations) {
|
|
8
|
+
const context = useProvider();
|
|
9
|
+
const contextTranslations = context.translations || [];
|
|
10
|
+
const i18nObjects = [
|
|
11
|
+
...localTranslations,
|
|
12
|
+
...(Array.isArray(contextTranslations)
|
|
13
|
+
? contextTranslations.map((t) => t[componentName])
|
|
14
|
+
: [contextTranslations[componentName]]),
|
|
15
|
+
context.locale[componentName],
|
|
16
|
+
];
|
|
17
|
+
/**
|
|
18
|
+
* https://github.com/Shopify/polaris/blob/2115f9ba2f5bcbf2ad15745233501bff2db81ecf/polaris-react/src/utilities/i18n/I18n.ts#L24
|
|
19
|
+
*/
|
|
20
|
+
const translate = (keypath, replacements) => {
|
|
21
|
+
const text = get(keypath, i18nObjects);
|
|
22
|
+
if (replacements) {
|
|
23
|
+
return text.replace(REPLACE_REGEX, (match) => {
|
|
24
|
+
const replacement = match.substring(1, match.length - 1);
|
|
25
|
+
if (replacements[replacement] === undefined) {
|
|
26
|
+
const replacementData = JSON.stringify(replacements);
|
|
27
|
+
throw new Error(`Error translating key '${keypath}'. No replacement syntax ({}) found for key '${replacement}'. The following replacements were passed: '${replacementData}'`);
|
|
28
|
+
}
|
|
29
|
+
return replacements[replacement]; // can also be a number, but JS doesn't mind...
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return text;
|
|
33
|
+
};
|
|
34
|
+
return translate;
|
|
35
|
+
}
|
|
36
|
+
export function useDateLocale() {
|
|
37
|
+
const context = useProvider();
|
|
38
|
+
const contextTranslations = context.translations || [];
|
|
39
|
+
const i18nObjects = Array.isArray(contextTranslations)
|
|
40
|
+
? contextTranslations.map((t) => t.global)
|
|
41
|
+
: [contextTranslations.global];
|
|
42
|
+
i18nObjects.push(context.locale.global);
|
|
43
|
+
for (const obj of i18nObjects) {
|
|
44
|
+
if (obj === null || obj === void 0 ? void 0 : obj.dateLocale) {
|
|
45
|
+
return obj.dateLocale;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
throw new Error("dateLocale not found.");
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=i18n.context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.context.js","sourceRoot":"","sources":["../../../src/util/i18n/i18n.context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAQ5B;;GAEG;AACH,MAAM,aAAa,GAAG,UAAU,CAAC;AAcjC,MAAM,UAAU,OAAO,CACrB,aAAgB,EAChB,GAAG,iBAA0D;IAE7D,MAAM,OAAO,GAAG,WAAW,EAAE,CAAC;IAC9B,MAAM,mBAAmB,GAAG,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC;IACvD,MAAM,WAAW,GAAwC;QACvD,GAAG,iBAAiB;QACpB,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,mBAAmB,CAAC;YACpC,CAA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,CAAC,CAAC,MAAM,CAAC;QAC1C,CAAC,CAAC,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;IACjC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAExC,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QAC9B,IAAI,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,UAAU,EAAE,CAAC;YACpB,OAAO,GAAG,CAAC,UAAoB,CAAC;QAClC,CAAC;IACH,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;AAC3C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navikt/ds-react",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.11.0-alpha.1",
|
|
4
4
|
"description": "React components from the Norwegian Labour and Welfare Administration.",
|
|
5
5
|
"author": "Aksel, a team part of the Norwegian Labour and Welfare Administration.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"typings": "./esm/index.d.ts",
|
|
19
19
|
"publishConfig": {
|
|
20
20
|
"access": "public",
|
|
21
|
-
"provenance":
|
|
21
|
+
"provenance": false
|
|
22
22
|
},
|
|
23
23
|
"files": [
|
|
24
24
|
"/cjs",
|
|
@@ -645,6 +645,11 @@
|
|
|
645
645
|
"@types/react": ">=17.0.30",
|
|
646
646
|
"react": ">=17.0.0 || >19.0.0-rc"
|
|
647
647
|
},
|
|
648
|
+
"overrides": {
|
|
649
|
+
"react-day-picker": {
|
|
650
|
+
"react": ">= 16.8.0"
|
|
651
|
+
}
|
|
652
|
+
},
|
|
648
653
|
"peerDependenciesMeta": {
|
|
649
654
|
"@types/react": {
|
|
650
655
|
"optional": true
|