@navikt/ds-react 6.16.3 → 7.0.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.
Files changed (47) hide show
  1. package/cjs/form/combobox/Input/Input.d.ts +1 -1
  2. package/cjs/form/combobox/Input/Input.js +4 -3
  3. package/cjs/form/combobox/Input/Input.js.map +1 -1
  4. package/cjs/form/combobox/types.d.ts +1 -1
  5. package/cjs/form/error-summary/ErrorSummary.d.ts +4 -3
  6. package/cjs/form/error-summary/ErrorSummary.js +12 -8
  7. package/cjs/form/error-summary/ErrorSummary.js.map +1 -1
  8. package/cjs/form/error-summary/ErrorSummaryItem.d.ts +1 -1
  9. package/cjs/form/error-summary/ErrorSummaryItem.js +2 -1
  10. package/cjs/form/error-summary/ErrorSummaryItem.js.map +1 -1
  11. package/cjs/provider/i18n/LanguageProvider.d.ts +26 -0
  12. package/cjs/provider/i18n/LanguageProvider.js +64 -0
  13. package/cjs/provider/i18n/LanguageProvider.js.map +1 -0
  14. package/cjs/tooltip/Tooltip.d.ts +8 -2
  15. package/cjs/tooltip/Tooltip.js +11 -8
  16. package/cjs/tooltip/Tooltip.js.map +1 -1
  17. package/cjs/util/i18n/i18n.context.d.ts +1 -2
  18. package/cjs/util/i18n/i18n.context.js +3 -7
  19. package/cjs/util/i18n/i18n.context.js.map +1 -1
  20. package/esm/form/combobox/Input/Input.d.ts +1 -1
  21. package/esm/form/combobox/Input/Input.js +4 -3
  22. package/esm/form/combobox/Input/Input.js.map +1 -1
  23. package/esm/form/combobox/types.d.ts +1 -1
  24. package/esm/form/error-summary/ErrorSummary.d.ts +4 -3
  25. package/esm/form/error-summary/ErrorSummary.js +14 -10
  26. package/esm/form/error-summary/ErrorSummary.js.map +1 -1
  27. package/esm/form/error-summary/ErrorSummaryItem.d.ts +1 -1
  28. package/esm/form/error-summary/ErrorSummaryItem.js +2 -1
  29. package/esm/form/error-summary/ErrorSummaryItem.js.map +1 -1
  30. package/esm/provider/i18n/LanguageProvider.d.ts +26 -0
  31. package/esm/provider/i18n/LanguageProvider.js +33 -0
  32. package/esm/provider/i18n/LanguageProvider.js.map +1 -0
  33. package/esm/tooltip/Tooltip.d.ts +8 -2
  34. package/esm/tooltip/Tooltip.js +12 -9
  35. package/esm/tooltip/Tooltip.js.map +1 -1
  36. package/esm/util/i18n/i18n.context.d.ts +1 -2
  37. package/esm/util/i18n/i18n.context.js +4 -4
  38. package/esm/util/i18n/i18n.context.js.map +1 -1
  39. package/package.json +3 -3
  40. package/src/form/combobox/Input/Input.tsx +23 -11
  41. package/src/form/combobox/types.ts +11 -1
  42. package/src/form/error-summary/ErrorSummary.tsx +23 -13
  43. package/src/form/error-summary/ErrorSummaryItem.tsx +10 -8
  44. package/src/provider/i18n/LanguageProvider.tsx +51 -0
  45. package/src/tooltip/Tooltip.tsx +26 -15
  46. package/src/util/i18n/i18n.context.test.tsx +9 -6
  47. package/src/util/i18n/i18n.context.ts +5 -11
@@ -1,7 +1,8 @@
1
1
  import { renderHook } from "@testing-library/react";
2
2
  import React from "react";
3
3
  import { describe, expect, test } from "vitest";
4
- import { I18nContext, useI18n } from "./i18n.context";
4
+ import UNSAFE_AkselLanguageProvider from "../../provider/i18n/LanguageProvider";
5
+ import { useI18n } from "./i18n.context";
5
6
 
6
7
  describe("useI18n", () => {
7
8
  test("should throw error if key is not found", () => {
@@ -15,7 +16,9 @@ describe("useI18n", () => {
15
16
  const i18n = { FileUpload: { item: { uploading: "Test translation" } } };
16
17
  const { result } = renderHook(() => useI18n("FileUpload"), {
17
18
  wrapper: ({ children }) => (
18
- <I18nContext.Provider value={i18n}>{children}</I18nContext.Provider>
19
+ <UNSAFE_AkselLanguageProvider translations={i18n}>
20
+ {children}
21
+ </UNSAFE_AkselLanguageProvider>
19
22
  ),
20
23
  });
21
24
  const translate = result.current;
@@ -29,9 +32,9 @@ describe("useI18n", () => {
29
32
  const i18n2 = { FileUpload: { item: { uploading: "Wrong translation" } } };
30
33
  const { result } = renderHook(() => useI18n("FileUpload"), {
31
34
  wrapper: ({ children }) => (
32
- <I18nContext.Provider value={[i18n1, i18n2]}>
35
+ <UNSAFE_AkselLanguageProvider translations={[i18n1, i18n2]}>
33
36
  {children}
34
- </I18nContext.Provider>
37
+ </UNSAFE_AkselLanguageProvider>
35
38
  ),
36
39
  });
37
40
  const translate = result.current;
@@ -45,9 +48,9 @@ describe("useI18n", () => {
45
48
  };
46
49
  const { result } = renderHook(() => useI18n("FileUpload"), {
47
50
  wrapper: ({ children }) => (
48
- <I18nContext.Provider value={[i18n1, i18n2]}>
51
+ <UNSAFE_AkselLanguageProvider translations={[i18n1, i18n2]}>
49
52
  {children}
50
- </I18nContext.Provider>
53
+ </UNSAFE_AkselLanguageProvider>
51
54
  ),
52
55
  });
53
56
  const translate = result.current;
@@ -1,10 +1,7 @@
1
- import { createContext, useContext } from "react";
1
+ import { useContext } from "react";
2
+ import { LanguageProviderContext } from "../../provider/i18n/LanguageProvider";
2
3
  import { get } from "./get";
3
- import {
4
- Component,
5
- ComponentTranslation,
6
- TranslationDictionary,
7
- } from "./i18n.types";
4
+ import { Component, ComponentTranslation } from "./i18n.types";
8
5
  import nb from "./locales/nb";
9
6
 
10
7
  /**
@@ -12,10 +9,6 @@ import nb from "./locales/nb";
12
9
  */
13
10
  const REPLACE_REGEX = /{[^}]*}/g;
14
11
 
15
- export const I18nContext = createContext<
16
- TranslationDictionary | TranslationDictionary[]
17
- >(nb);
18
-
19
12
  /* https://dev.to/pffigueiredo/typescript-utility-keyof-nested-object-2pa3 */
20
13
  type NestedKeyOf<ObjectType extends object> = {
21
14
  [Key in keyof ObjectType & (string | number)]: ObjectType[Key] extends object
@@ -27,7 +20,8 @@ export function useI18n<T extends Component>(
27
20
  componentName: T,
28
21
  ...local: (ComponentTranslation<T> | undefined)[]
29
22
  ) {
30
- const i18n = useContext(I18nContext);
23
+ const languageProviderContext = useContext(LanguageProviderContext);
24
+ const i18n = languageProviderContext.translations;
31
25
 
32
26
  /**
33
27
  * https://github.com/Shopify/polaris/blob/2115f9ba2f5bcbf2ad15745233501bff2db81ecf/polaris-react/src/utilities/i18n/I18n.ts#L24