@navikt/ds-react 7.9.0 → 7.9.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.
Files changed (235) hide show
  1. package/README.md +2 -2
  2. package/cjs/alert/Alert.js +2 -2
  3. package/cjs/alert/Alert.js.map +1 -1
  4. package/cjs/chips/Removable.js +2 -2
  5. package/cjs/chips/Removable.js.map +1 -1
  6. package/cjs/copybutton/CopyButton.js +2 -2
  7. package/cjs/copybutton/CopyButton.js.map +1 -1
  8. package/cjs/date/context/useDateTranslationContext.d.ts +1 -1
  9. package/cjs/date/datepicker/DatePicker.js +3 -3
  10. package/cjs/date/datepicker/DatePicker.js.map +1 -1
  11. package/cjs/date/datepicker/DatePickerStandalone.js +3 -3
  12. package/cjs/date/datepicker/DatePickerStandalone.js.map +1 -1
  13. package/cjs/date/hooks/useDatepicker.js +2 -2
  14. package/cjs/date/hooks/useDatepicker.js.map +1 -1
  15. package/cjs/date/hooks/useMonthPicker.js +2 -2
  16. package/cjs/date/hooks/useMonthPicker.js.map +1 -1
  17. package/cjs/date/hooks/useRangeDatepicker.js +2 -2
  18. package/cjs/date/hooks/useRangeDatepicker.js.map +1 -1
  19. package/cjs/date/monthpicker/MonthPicker.js +3 -3
  20. package/cjs/date/monthpicker/MonthPicker.js.map +1 -1
  21. package/cjs/date/monthpicker/MonthPickerStandalone.js +3 -3
  22. package/cjs/date/monthpicker/MonthPickerStandalone.js.map +1 -1
  23. package/cjs/date/parts/DateWrapper.d.ts +1 -1
  24. package/cjs/date/parts/DateWrapper.js +2 -2
  25. package/cjs/date/parts/DateWrapper.js.map +1 -1
  26. package/cjs/expansion-card/ExpansionCardHeader.js +2 -2
  27. package/cjs/expansion-card/ExpansionCardHeader.js.map +1 -1
  28. package/cjs/form/ReadOnlyIcon.js +2 -2
  29. package/cjs/form/ReadOnlyIcon.js.map +1 -1
  30. package/cjs/form/combobox/FilteredOptions/AddNewOption.js +2 -2
  31. package/cjs/form/combobox/FilteredOptions/AddNewOption.js.map +1 -1
  32. package/cjs/form/combobox/FilteredOptions/LoadingMessage.js +2 -2
  33. package/cjs/form/combobox/FilteredOptions/LoadingMessage.js.map +1 -1
  34. package/cjs/form/combobox/FilteredOptions/MaxSelectedMessage.js +2 -2
  35. package/cjs/form/combobox/FilteredOptions/MaxSelectedMessage.js.map +1 -1
  36. package/cjs/form/error-summary/ErrorSummary.js +2 -2
  37. package/cjs/form/error-summary/ErrorSummary.js.map +1 -1
  38. package/cjs/form/file-upload/parts/dropzone/Dropzone.js +2 -2
  39. package/cjs/form/file-upload/parts/dropzone/Dropzone.js.map +1 -1
  40. package/cjs/form/file-upload/parts/item/Item.js +2 -2
  41. package/cjs/form/file-upload/parts/item/Item.js.map +1 -1
  42. package/cjs/form/form-progress/FormProgress.js +2 -2
  43. package/cjs/form/form-progress/FormProgress.js.map +1 -1
  44. package/cjs/form/form-summary/FormSummaryEditLink.js +2 -2
  45. package/cjs/form/form-summary/FormSummaryEditLink.js.map +1 -1
  46. package/cjs/form/search/Search.js +2 -2
  47. package/cjs/form/search/Search.js.map +1 -1
  48. package/cjs/form/search/SearchButton.js +2 -2
  49. package/cjs/form/search/SearchButton.js.map +1 -1
  50. package/cjs/form/textarea/TextareaCounter.js +2 -2
  51. package/cjs/form/textarea/TextareaCounter.js.map +1 -1
  52. package/cjs/guide-panel/Illustration.darkside.js +2 -2
  53. package/cjs/guide-panel/Illustration.darkside.js.map +1 -1
  54. package/cjs/guide-panel/Illustration.js +2 -2
  55. package/cjs/guide-panel/Illustration.js.map +1 -1
  56. package/cjs/help-text/HelpText.js +2 -2
  57. package/cjs/help-text/HelpText.js.map +1 -1
  58. package/cjs/link/stories/RandomIcon.d.ts +2 -0
  59. package/cjs/link/stories/RandomIcon.js +39 -0
  60. package/cjs/link/stories/RandomIcon.js.map +1 -0
  61. package/cjs/loader/Loader.js +2 -2
  62. package/cjs/loader/Loader.js.map +1 -1
  63. package/cjs/modal/ModalHeader.js +2 -2
  64. package/cjs/modal/ModalHeader.js.map +1 -1
  65. package/cjs/pagination/Pagination.js +2 -2
  66. package/cjs/pagination/Pagination.js.map +1 -1
  67. package/cjs/progress-bar/ProgressBar.js +2 -2
  68. package/cjs/progress-bar/ProgressBar.js.map +1 -1
  69. package/cjs/table/ExpandableRow.js +2 -2
  70. package/cjs/table/ExpandableRow.js.map +1 -1
  71. package/cjs/timeline/AxisLabels.js +3 -3
  72. package/cjs/timeline/AxisLabels.js.map +1 -1
  73. package/cjs/timeline/Pin.js +2 -2
  74. package/cjs/timeline/Pin.js.map +1 -1
  75. package/cjs/timeline/TimelineRow.js +2 -2
  76. package/cjs/timeline/TimelineRow.js.map +1 -1
  77. package/cjs/timeline/period/ClickablePeriod.js +2 -2
  78. package/cjs/timeline/period/ClickablePeriod.js.map +1 -1
  79. package/cjs/timeline/period/NonClickablePeriod.js +2 -2
  80. package/cjs/timeline/period/NonClickablePeriod.js.map +1 -1
  81. package/cjs/timeline/utils/period.d.ts +1 -1
  82. package/cjs/timeline/zoom/ZoomButton.js +2 -2
  83. package/cjs/timeline/zoom/ZoomButton.js.map +1 -1
  84. package/cjs/util/i18n/i18n.hooks.d.ts +4 -0
  85. package/cjs/util/i18n/{i18n.context.js → i18n.hooks.js} +3 -7
  86. package/cjs/util/i18n/i18n.hooks.js.map +1 -0
  87. package/cjs/util/i18n/i18n.types.d.ts +4 -0
  88. package/cjs/util/i18n/locales/nb.d.ts +81 -4
  89. package/cjs/util/i18n/locales/nb.js +81 -4
  90. package/cjs/util/i18n/locales/nb.js.map +1 -1
  91. package/esm/alert/Alert.js +1 -1
  92. package/esm/alert/Alert.js.map +1 -1
  93. package/esm/chips/Removable.js +1 -1
  94. package/esm/chips/Removable.js.map +1 -1
  95. package/esm/copybutton/CopyButton.js +1 -1
  96. package/esm/copybutton/CopyButton.js.map +1 -1
  97. package/esm/date/context/useDateTranslationContext.d.ts +1 -1
  98. package/esm/date/datepicker/DatePicker.js +1 -1
  99. package/esm/date/datepicker/DatePicker.js.map +1 -1
  100. package/esm/date/datepicker/DatePickerStandalone.js +1 -1
  101. package/esm/date/datepicker/DatePickerStandalone.js.map +1 -1
  102. package/esm/date/hooks/useDatepicker.js +1 -1
  103. package/esm/date/hooks/useDatepicker.js.map +1 -1
  104. package/esm/date/hooks/useMonthPicker.js +1 -1
  105. package/esm/date/hooks/useMonthPicker.js.map +1 -1
  106. package/esm/date/hooks/useRangeDatepicker.js +1 -1
  107. package/esm/date/hooks/useRangeDatepicker.js.map +1 -1
  108. package/esm/date/monthpicker/MonthPicker.js +1 -1
  109. package/esm/date/monthpicker/MonthPicker.js.map +1 -1
  110. package/esm/date/monthpicker/MonthPickerStandalone.js +1 -1
  111. package/esm/date/monthpicker/MonthPickerStandalone.js.map +1 -1
  112. package/esm/date/parts/DateWrapper.d.ts +1 -1
  113. package/esm/date/parts/DateWrapper.js +1 -1
  114. package/esm/date/parts/DateWrapper.js.map +1 -1
  115. package/esm/expansion-card/ExpansionCardHeader.js +1 -1
  116. package/esm/expansion-card/ExpansionCardHeader.js.map +1 -1
  117. package/esm/form/ReadOnlyIcon.js +1 -1
  118. package/esm/form/ReadOnlyIcon.js.map +1 -1
  119. package/esm/form/combobox/FilteredOptions/AddNewOption.js +1 -1
  120. package/esm/form/combobox/FilteredOptions/AddNewOption.js.map +1 -1
  121. package/esm/form/combobox/FilteredOptions/LoadingMessage.js +1 -1
  122. package/esm/form/combobox/FilteredOptions/LoadingMessage.js.map +1 -1
  123. package/esm/form/combobox/FilteredOptions/MaxSelectedMessage.js +1 -1
  124. package/esm/form/combobox/FilteredOptions/MaxSelectedMessage.js.map +1 -1
  125. package/esm/form/error-summary/ErrorSummary.js +1 -1
  126. package/esm/form/error-summary/ErrorSummary.js.map +1 -1
  127. package/esm/form/file-upload/parts/dropzone/Dropzone.js +1 -1
  128. package/esm/form/file-upload/parts/dropzone/Dropzone.js.map +1 -1
  129. package/esm/form/file-upload/parts/item/Item.js +1 -1
  130. package/esm/form/file-upload/parts/item/Item.js.map +1 -1
  131. package/esm/form/form-progress/FormProgress.js +1 -1
  132. package/esm/form/form-progress/FormProgress.js.map +1 -1
  133. package/esm/form/form-summary/FormSummaryEditLink.js +1 -1
  134. package/esm/form/form-summary/FormSummaryEditLink.js.map +1 -1
  135. package/esm/form/search/Search.js +1 -1
  136. package/esm/form/search/Search.js.map +1 -1
  137. package/esm/form/search/SearchButton.js +1 -1
  138. package/esm/form/search/SearchButton.js.map +1 -1
  139. package/esm/form/textarea/TextareaCounter.js +1 -1
  140. package/esm/form/textarea/TextareaCounter.js.map +1 -1
  141. package/esm/guide-panel/Illustration.darkside.js +1 -1
  142. package/esm/guide-panel/Illustration.darkside.js.map +1 -1
  143. package/esm/guide-panel/Illustration.js +1 -1
  144. package/esm/guide-panel/Illustration.js.map +1 -1
  145. package/esm/help-text/HelpText.js +1 -1
  146. package/esm/help-text/HelpText.js.map +1 -1
  147. package/esm/link/stories/RandomIcon.d.ts +2 -0
  148. package/esm/link/stories/RandomIcon.js +9 -0
  149. package/esm/link/stories/RandomIcon.js.map +1 -0
  150. package/esm/loader/Loader.js +1 -1
  151. package/esm/loader/Loader.js.map +1 -1
  152. package/esm/modal/ModalHeader.js +1 -1
  153. package/esm/modal/ModalHeader.js.map +1 -1
  154. package/esm/pagination/Pagination.js +1 -1
  155. package/esm/pagination/Pagination.js.map +1 -1
  156. package/esm/progress-bar/ProgressBar.js +1 -1
  157. package/esm/progress-bar/ProgressBar.js.map +1 -1
  158. package/esm/table/ExpandableRow.js +1 -1
  159. package/esm/table/ExpandableRow.js.map +1 -1
  160. package/esm/timeline/AxisLabels.js +1 -1
  161. package/esm/timeline/AxisLabels.js.map +1 -1
  162. package/esm/timeline/Pin.js +1 -1
  163. package/esm/timeline/Pin.js.map +1 -1
  164. package/esm/timeline/TimelineRow.js +1 -1
  165. package/esm/timeline/TimelineRow.js.map +1 -1
  166. package/esm/timeline/period/ClickablePeriod.js +1 -1
  167. package/esm/timeline/period/ClickablePeriod.js.map +1 -1
  168. package/esm/timeline/period/NonClickablePeriod.js +1 -1
  169. package/esm/timeline/period/NonClickablePeriod.js.map +1 -1
  170. package/esm/timeline/utils/period.d.ts +1 -1
  171. package/esm/timeline/zoom/ZoomButton.js +1 -1
  172. package/esm/timeline/zoom/ZoomButton.js.map +1 -1
  173. package/esm/util/i18n/i18n.hooks.d.ts +4 -0
  174. package/esm/util/i18n/{i18n.context.js → i18n.hooks.js} +3 -7
  175. package/esm/util/i18n/{i18n.context.js.map → i18n.hooks.js.map} +1 -1
  176. package/esm/util/i18n/i18n.types.d.ts +4 -0
  177. package/esm/util/i18n/locales/nb.d.ts +81 -4
  178. package/esm/util/i18n/locales/nb.js +81 -4
  179. package/esm/util/i18n/locales/nb.js.map +1 -1
  180. package/package.json +17 -12
  181. package/src/alert/Alert.tsx +1 -1
  182. package/src/chips/Removable.tsx +1 -1
  183. package/src/copybutton/CopyButton.tsx +1 -1
  184. package/src/date/context/useDateTranslationContext.ts +1 -1
  185. package/src/date/datepicker/DatePicker.tsx +1 -1
  186. package/src/date/datepicker/DatePickerStandalone.tsx +1 -1
  187. package/src/date/datepicker/datepicker.test.tsx +2 -5
  188. package/src/date/hooks/useDatepicker.tsx +1 -1
  189. package/src/date/hooks/useMonthPicker.tsx +1 -1
  190. package/src/date/hooks/useRangeDatepicker.test.tsx +5 -10
  191. package/src/date/hooks/useRangeDatepicker.tsx +1 -1
  192. package/src/date/monthpicker/MonthPicker.tsx +1 -1
  193. package/src/date/monthpicker/MonthPickerStandalone.tsx +1 -1
  194. package/src/date/parts/DateWrapper.tsx +2 -1
  195. package/src/expansion-card/ExpansionCardHeader.tsx +1 -1
  196. package/src/form/ReadOnlyIcon.tsx +1 -1
  197. package/src/form/combobox/FilteredOptions/AddNewOption.tsx +1 -1
  198. package/src/form/combobox/FilteredOptions/LoadingMessage.tsx +1 -1
  199. package/src/form/combobox/FilteredOptions/MaxSelectedMessage.tsx +1 -1
  200. package/src/form/error-summary/ErrorSummary.tsx +1 -1
  201. package/src/form/file-upload/parts/dropzone/Dropzone.tsx +1 -1
  202. package/src/form/file-upload/parts/item/Item.tsx +1 -1
  203. package/src/form/form-progress/FormProgress.tsx +1 -1
  204. package/src/form/form-summary/FormSummaryEditLink.tsx +1 -1
  205. package/src/form/search/Search.tsx +1 -1
  206. package/src/form/search/SearchButton.tsx +1 -1
  207. package/src/form/textarea/TextareaCounter.tsx +1 -1
  208. package/src/guide-panel/Illustration.darkside.tsx +1 -1
  209. package/src/guide-panel/Illustration.tsx +1 -1
  210. package/src/help-text/HelpText.tsx +1 -1
  211. package/src/loader/Loader.tsx +1 -1
  212. package/src/modal/ModalHeader.tsx +1 -1
  213. package/src/pagination/Pagination.tsx +1 -1
  214. package/src/progress-bar/ProgressBar.tsx +1 -1
  215. package/src/table/ExpandableRow.tsx +1 -1
  216. package/src/tabs/Tabs.test.tsx +4 -12
  217. package/src/timeline/AxisLabels.tsx +2 -1
  218. package/src/timeline/Pin.tsx +1 -1
  219. package/src/timeline/TimelineRow.tsx +1 -1
  220. package/src/timeline/period/ClickablePeriod.tsx +1 -1
  221. package/src/timeline/period/NonClickablePeriod.tsx +1 -1
  222. package/src/timeline/utils/period.ts +1 -1
  223. package/src/timeline/zoom/ZoomButton.tsx +1 -1
  224. package/src/util/i18n/{i18n.context.test.tsx → i18n.hooks.test.tsx} +62 -3
  225. package/src/util/i18n/{i18n.context.ts → i18n.hooks.ts} +3 -19
  226. package/src/util/i18n/i18n.types.ts +12 -0
  227. package/cjs/modal/types.test-d.d.ts +0 -1
  228. package/cjs/modal/types.test-d.js +0 -67
  229. package/cjs/modal/types.test-d.js.map +0 -1
  230. package/cjs/util/i18n/i18n.context.d.ts +0 -9
  231. package/cjs/util/i18n/i18n.context.js.map +0 -1
  232. package/esm/modal/types.test-d.d.ts +0 -1
  233. package/esm/modal/types.test-d.js +0 -65
  234. package/esm/modal/types.test-d.js.map +0 -1
  235. package/esm/util/i18n/i18n.context.d.ts +0 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navikt/ds-react",
3
- "version": "7.9.0",
3
+ "version": "7.9.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",
@@ -603,10 +603,11 @@
603
603
  "./package.json": "./package.json"
604
604
  },
605
605
  "scripts": {
606
- "docgen": "yarn tsx ../../../scripts/docgen.ts",
606
+ "docgen": "tsx ../../../scripts/docgen.ts",
607
+ "i18n-jsdoc": "tsx ./scripts/addJsdocToLocales.ts",
607
608
  "write-packagejson": "echo '{\"type\": \"module\"}' > esm/package.json",
608
609
  "clean": "rimraf cjs esm",
609
- "build": "concurrently \"tsc -p tsconfig.build.json\" \"tsc -p tsconfig.esm.json && tsc-alias -p tsconfig.esm.json && yarn write-packagejson\" ",
610
+ "build": "yarn i18n-jsdoc && concurrently \"tsc -p tsconfig.build.json\" \"tsc -p tsconfig.esm.json && tsc-alias -p tsconfig.esm.json && yarn write-packagejson\" && yarn i18n-jsdoc --cleanup",
610
611
  "watch": "tsc --watch -p tsconfig.esm.json",
611
612
  "test": "TZ=UTC vitest run -c tests/vitest.config.ts",
612
613
  "test:watch": "vitest watch"
@@ -614,20 +615,23 @@
614
615
  "dependencies": {
615
616
  "@floating-ui/react": "0.25.4",
616
617
  "@floating-ui/react-dom": "^2.0.9",
617
- "@navikt/aksel-icons": "^7.9.0",
618
- "@navikt/ds-tokens": "^7.9.0",
618
+ "@navikt/aksel-icons": "^7.9.1",
619
+ "@navikt/ds-tokens": "^7.9.1",
619
620
  "clsx": "^2.1.0",
620
621
  "date-fns": "^3.0.0",
621
622
  "react-day-picker": "8.10.1"
622
623
  },
623
624
  "devDependencies": {
624
- "@testing-library/dom": "9.3.4",
625
- "@testing-library/jest-dom": "^5.16.0",
626
- "@testing-library/react": "^15.0.7",
627
- "@testing-library/user-event": "^14.2.0",
625
+ "@testing-library/dom": "10.4.0",
626
+ "@testing-library/jest-dom": "^6.6.3",
627
+ "@testing-library/react": "^16.1.0",
628
+ "@testing-library/user-event": "^14.5.2",
629
+ "@types/jscodeshift": "^0.11.11",
630
+ "aksel": "workspace:^",
628
631
  "concurrently": "9.0.1",
629
632
  "fast-glob": "3.2.11",
630
- "jsdom": "24.0.0",
633
+ "jscodeshift": "^0.15.1",
634
+ "jsdom": "25.0.1",
631
635
  "react-dom": "^18.0.0",
632
636
  "react-router-dom": "^6.3.0",
633
637
  "rimraf": "6.0.1",
@@ -635,7 +639,7 @@
635
639
  "tsc-alias": "1.8.8",
636
640
  "tsx": "^4.19.1",
637
641
  "typescript": "5.5.4",
638
- "vitest": "^1.2.2"
642
+ "vitest": "^2.1.8"
639
643
  },
640
644
  "peerDependencies": {
641
645
  "@types/react": ">=17.0.30",
@@ -645,5 +649,6 @@
645
649
  "@types/react": {
646
650
  "optional": true
647
651
  }
648
- }
652
+ },
653
+ "_comment": "The 'aksel' dependency tells yarn to install the root deps when installing deps for this package. Helps make it possible to contribute without access to GPR."
649
654
  }
@@ -9,7 +9,7 @@ import {
9
9
  } from "@navikt/aksel-icons";
10
10
  import { Button } from "../button";
11
11
  import { BodyLong } from "../typography";
12
- import { useI18n } from "../util/i18n/i18n.context";
12
+ import { useI18n } from "../util/i18n/i18n.hooks";
13
13
 
14
14
  export interface AlertProps extends React.HTMLAttributes<HTMLDivElement> {
15
15
  /**
@@ -2,7 +2,7 @@ import cl from "clsx";
2
2
  import React, { forwardRef } from "react";
3
3
  import { XMarkIcon } from "@navikt/aksel-icons";
4
4
  import { composeEventHandlers } from "../util/composeEventHandlers";
5
- import { useI18n } from "../util/i18n/i18n.context";
5
+ import { useI18n } from "../util/i18n/i18n.hooks";
6
6
 
7
7
  export interface ChipsRemovableProps
8
8
  extends React.ButtonHTMLAttributes<HTMLButtonElement> {
@@ -10,7 +10,7 @@ import { CheckmarkIcon, FilesIcon } from "@navikt/aksel-icons";
10
10
  import { Label } from "../typography";
11
11
  import { composeEventHandlers } from "../util/composeEventHandlers";
12
12
  import copy from "../util/copy";
13
- import { useI18n } from "../util/i18n/i18n.context";
13
+ import { useI18n } from "../util/i18n/i18n.hooks";
14
14
 
15
15
  export interface CopyButtonProps
16
16
  extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children"> {
@@ -1,5 +1,5 @@
1
1
  import { createContext } from "../../util/create-context";
2
- import { TFunction } from "../../util/i18n/i18n.context";
2
+ import { TFunction } from "../../util/i18n/i18n.types";
3
3
 
4
4
  interface DateTranslationContextProps {
5
5
  translate: TFunction<"DatePicker">;
@@ -5,7 +5,7 @@ import { DateRange, DayPicker, isMatch } from "react-day-picker";
5
5
  import { omit } from "../../util";
6
6
  import { useId } from "../../util/hooks";
7
7
  import { useMergeRefs } from "../../util/hooks/useMergeRefs";
8
- import { useDateLocale, useI18n } from "../../util/i18n/i18n.context";
8
+ import { useDateLocale, useI18n } from "../../util/i18n/i18n.hooks";
9
9
  import { DateInputContext, DateTranslationContextProvider } from "../context";
10
10
  import { DatePickerInput } from "../parts/DateInput";
11
11
  import { DateWrapper } from "../parts/DateWrapper";
@@ -3,7 +3,7 @@ import { isWeekend } from "date-fns";
3
3
  import React, { forwardRef } from "react";
4
4
  import { DateRange, DayPicker, isMatch } from "react-day-picker";
5
5
  import { omit } from "../../util";
6
- import { useDateLocale, useI18n } from "../../util/i18n/i18n.context";
6
+ import { useDateLocale, useI18n } from "../../util/i18n/i18n.hooks";
7
7
  import { DateTranslationContextProvider } from "../context";
8
8
  import { getLocaleFromString, getTranslations } from "../utils";
9
9
  import Caption from "./parts/Caption";
@@ -1,4 +1,4 @@
1
- import { act, render, screen } from "@testing-library/react";
1
+ import { render, screen } from "@testing-library/react";
2
2
  import userEvent from "@testing-library/user-event";
3
3
  import React from "react";
4
4
  import { describe, test } from "vitest";
@@ -23,9 +23,6 @@ describe("Render datepicker", () => {
23
23
  test("Should not crash when e.target is window", async () => {
24
24
  render(<App />);
25
25
 
26
- // eslint-disable-next-line testing-library/no-unnecessary-act -- https://kentcdodds.com/blog/fix-the-not-wrapped-in-act-warning
27
- await act(async () => {
28
- await userEvent.click(screen.getByText("Velg dato"));
29
- });
26
+ await userEvent.click(screen.getByText("Velg dato"));
30
27
  });
31
28
  });
@@ -1,7 +1,7 @@
1
1
  import { differenceInCalendarDays, isWeekend } from "date-fns";
2
2
  import React, { useCallback, useState } from "react";
3
3
  import { DayClickEventHandler, isMatch } from "react-day-picker";
4
- import { useDateLocale } from "../../util/i18n/i18n.context";
4
+ import { useDateLocale } from "../../util/i18n/i18n.hooks";
5
5
  import { DatePickerProps } from "../datepicker/DatePicker";
6
6
  import { DateInputProps } from "../parts/DateInput";
7
7
  import {
@@ -1,5 +1,5 @@
1
1
  import React, { useCallback, useMemo, useState } from "react";
2
- import { useDateLocale } from "../../util/i18n/i18n.context";
2
+ import { useDateLocale } from "../../util/i18n/i18n.hooks";
3
3
  import { MonthPickerProps } from "../monthpicker/types";
4
4
  import { DateInputProps } from "../parts/DateInput";
5
5
  import {
@@ -1,5 +1,4 @@
1
- /* eslint-disable testing-library/no-unnecessary-act -- https://kentcdodds.com/blog/fix-the-not-wrapped-in-act-warning */
2
- import { act, render, screen } from "@testing-library/react";
1
+ import { render, screen } from "@testing-library/react";
3
2
  import userEvent from "@testing-library/user-event";
4
3
  import React from "react";
5
4
  import { describe, expect, test } from "vitest";
@@ -29,10 +28,8 @@ describe("Writing in input sets correct values", () => {
29
28
 
30
29
  const fraInput = screen.getByRole("textbox", { name: "Fra" });
31
30
  const tilInput = screen.getByRole("textbox", { name: "Til" });
32
- await act(async () => {
33
- await userEvent.type(fraInput, "03.08.2022");
34
- await userEvent.type(tilInput, "03.08.2022");
35
- });
31
+ await userEvent.type(fraInput, "03.08.2022");
32
+ await userEvent.type(tilInput, "03.08.2022");
36
33
  const res = screen.getByTitle("res");
37
34
  expect(res.innerHTML).toEqual(
38
35
  JSON.stringify({
@@ -47,10 +44,8 @@ describe("Writing in input sets correct values", () => {
47
44
 
48
45
  const fraInput = screen.getByRole("textbox", { name: "Fra" });
49
46
  const tilInput = screen.getByRole("textbox", { name: "Til" });
50
- await act(async () => {
51
- await userEvent.type(fraInput, "03.08.2022");
52
- await userEvent.type(tilInput, "02.08.2022");
53
- });
47
+ await userEvent.type(fraInput, "03.08.2022");
48
+ await userEvent.type(tilInput, "02.08.2022");
54
49
  const res = screen.getByTitle("res");
55
50
  expect(res.innerHTML).toEqual(
56
51
  JSON.stringify({
@@ -5,7 +5,7 @@ import {
5
5
  } from "date-fns";
6
6
  import React, { useState } from "react";
7
7
  import { DateRange, isMatch } from "react-day-picker";
8
- import { useDateLocale } from "../../util/i18n/i18n.context";
8
+ import { useDateLocale } from "../../util/i18n/i18n.hooks";
9
9
  import { DatePickerProps } from "../datepicker/DatePicker";
10
10
  import { DateInputProps } from "../parts/DateInput";
11
11
  import {
@@ -3,7 +3,7 @@ import React, { forwardRef, useState } from "react";
3
3
  import { DayPickerProvider } from "react-day-picker";
4
4
  import { useId } from "../../util/hooks";
5
5
  import { useMergeRefs } from "../../util/hooks/useMergeRefs";
6
- import { useDateLocale, useI18n } from "../../util/i18n/i18n.context";
6
+ import { useDateLocale, useI18n } from "../../util/i18n/i18n.hooks";
7
7
  import {
8
8
  DateInputContext,
9
9
  DateTranslationContextProvider,
@@ -1,7 +1,7 @@
1
1
  import cl from "clsx";
2
2
  import React, { forwardRef, useState } from "react";
3
3
  import { DayPickerProvider } from "react-day-picker";
4
- import { useDateLocale, useI18n } from "../../util/i18n/i18n.context";
4
+ import { useDateLocale, useI18n } from "../../util/i18n/i18n.hooks";
5
5
  import {
6
6
  DateTranslationContextProvider,
7
7
  SharedMonthProvider,
@@ -5,7 +5,8 @@ import { Modal } from "../../modal";
5
5
  import { useModalContext } from "../../modal/Modal.context";
6
6
  import { Popover } from "../../popover";
7
7
  import { useMedia } from "../../util/hooks";
8
- import { TFunction, useI18n } from "../../util/i18n/i18n.context";
8
+ import { useI18n } from "../../util/i18n/i18n.hooks";
9
+ import { TFunction } from "../../util/i18n/i18n.types";
9
10
  import { getGlobalTranslations } from "../utils";
10
11
 
11
12
  const variantToLabel = {
@@ -1,7 +1,7 @@
1
1
  import cl from "clsx";
2
2
  import React, { forwardRef, useContext } from "react";
3
3
  import { ChevronDownIcon } from "@navikt/aksel-icons";
4
- import { useI18n } from "../util/i18n/i18n.context";
4
+ import { useI18n } from "../util/i18n/i18n.hooks";
5
5
  import { ExpansionCardContext } from "./context";
6
6
 
7
7
  export interface ExpansionCardHeaderProps
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import { PadlockLockedFillIcon } from "@navikt/aksel-icons";
3
- import { useI18n } from "../util/i18n/i18n.context";
3
+ import { useI18n } from "../util/i18n/i18n.hooks";
4
4
 
5
5
  export const ReadOnlyIcon = () => (
6
6
  <PadlockLockedFillIcon
@@ -2,7 +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
+ import { useI18n } from "../../../util/i18n/i18n.hooks";
6
6
  import { useInputContext } from "../Input/Input.context";
7
7
  import { useSelectedOptionsContext } from "../SelectedOptions/selectedOptionsContext";
8
8
  import { isInList, toComboboxOption } from "../combobox-utils";
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import { Loader } from "../../../loader";
3
- import { useI18n } from "../../../util/i18n/i18n.context";
3
+ import { useI18n } from "../../../util/i18n/i18n.hooks";
4
4
  import { useInputContext } from "../Input/Input.context";
5
5
  import filteredOptionsUtil from "./filtered-options-util";
6
6
 
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { useI18n } from "../../../util/i18n/i18n.context";
2
+ import { useI18n } from "../../../util/i18n/i18n.hooks";
3
3
  import { useInputContext } from "../Input/Input.context";
4
4
  import { useSelectedOptionsContext } from "../SelectedOptions/selectedOptionsContext";
5
5
  import filteredOptionsUtil from "./filtered-options-util";
@@ -3,7 +3,7 @@ import React, { HTMLAttributes, forwardRef, useRef } from "react";
3
3
  import { BodyShort, Heading } from "../../typography";
4
4
  import { composeEventHandlers } from "../../util/composeEventHandlers";
5
5
  import { useMergeRefs } from "../../util/hooks";
6
- import { useI18n } from "../../util/i18n/i18n.context";
6
+ import { useI18n } from "../../util/i18n/i18n.hooks";
7
7
  import ErrorSummaryItem from "./ErrorSummaryItem";
8
8
 
9
9
  export interface ErrorSummaryProps
@@ -5,7 +5,7 @@ import { Button } from "../../../../button";
5
5
  import { BodyShort, ErrorMessage, Label } from "../../../../typography";
6
6
  import { composeEventHandlers } from "../../../../util/composeEventHandlers";
7
7
  import { useId } from "../../../../util/hooks";
8
- import { useI18n } from "../../../../util/i18n/i18n.context";
8
+ import { useI18n } from "../../../../util/i18n/i18n.hooks";
9
9
  import { omit } from "../../../../util/omit";
10
10
  import { useFormField } from "../../../useFormField";
11
11
  import { useFileUploadTranslation } from "../../FileUpload.context";
@@ -3,7 +3,7 @@ import React, { MouseEvent, forwardRef } from "react";
3
3
  import { ExclamationmarkTriangleIcon } from "@navikt/aksel-icons";
4
4
  import { BodyShort } from "../../../../typography";
5
5
  import { OverridableComponent } from "../../../../util";
6
- import { useI18n } from "../../../../util/i18n/i18n.context";
6
+ import { useI18n } from "../../../../util/i18n/i18n.hooks";
7
7
  import { ComponentTranslation } from "../../../../util/i18n/i18n.types";
8
8
  import { useFileUploadTranslation } from "../../FileUpload.context";
9
9
  import { FileItem } from "./Item.types";
@@ -6,7 +6,7 @@ import { HStack } from "../../layout/stack";
6
6
  import { ProgressBar } from "../../progress-bar";
7
7
  import { Stepper, StepperStepProps } from "../../stepper";
8
8
  import { BodyShort } from "../../typography";
9
- import { useI18n } from "../../util/i18n/i18n.context";
9
+ import { useI18n } from "../../util/i18n/i18n.hooks";
10
10
  import { ComponentTranslation } from "../../util/i18n/i18n.types";
11
11
 
12
12
  export interface FormProgressProps
@@ -1,7 +1,7 @@
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
+ import { useI18n } from "../../util/i18n/i18n.hooks";
5
5
  import { OverridableComponent } from "../../util/types";
6
6
 
7
7
  export interface FormSummaryEditProps
@@ -11,7 +11,7 @@ import { useThemeInternal } from "../../theme/Theme";
11
11
  import { BodyShort, ErrorMessage, Label } from "../../typography";
12
12
  import { omit } from "../../util";
13
13
  import { useMergeRefs } from "../../util/hooks/useMergeRefs";
14
- import { useI18n } from "../../util/i18n/i18n.context";
14
+ import { useI18n } from "../../util/i18n/i18n.hooks";
15
15
  import { FormFieldProps, useFormField } from "../useFormField";
16
16
  import SearchButton, { SearchButtonType } from "./SearchButton";
17
17
  import { SearchContext } from "./context";
@@ -3,7 +3,7 @@ import React, { forwardRef, useContext } from "react";
3
3
  import { MagnifyingGlassIcon } from "@navikt/aksel-icons";
4
4
  import { Button, ButtonProps } from "../../button";
5
5
  import { composeEventHandlers } from "../../util/composeEventHandlers";
6
- import { useI18n } from "../../util/i18n/i18n.context";
6
+ import { useI18n } from "../../util/i18n/i18n.hooks";
7
7
  import { SearchContext } from "./context";
8
8
 
9
9
  export interface SearchButtonProps
@@ -2,7 +2,7 @@ import cl from "clsx";
2
2
  import React, { useEffect, useState } from "react";
3
3
  import { BodyShort } from "../../typography";
4
4
  import debounce from "../../util/debounce";
5
- import { useI18n } from "../../util/i18n/i18n.context";
5
+ import { useI18n } from "../../util/i18n/i18n.hooks";
6
6
  import type { TextareaProps } from "./Textarea";
7
7
 
8
8
  interface Props {
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { useI18n } from "../util/i18n/i18n.context";
2
+ import { useI18n } from "../util/i18n/i18n.hooks";
3
3
 
4
4
  export const DarksideGudiepanelIllustration = () => {
5
5
  const translate = useI18n("GuidePanel");
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { useI18n } from "../util/i18n/i18n.context";
2
+ import { useI18n } from "../util/i18n/i18n.hooks";
3
3
 
4
4
  export const DefaultIllustration = () => {
5
5
  const translate = useI18n("GuidePanel");
@@ -4,7 +4,7 @@ import { Popover, PopoverProps } from "../popover";
4
4
  import { useThemeInternal } from "../theme/Theme";
5
5
  import { composeEventHandlers } from "../util/composeEventHandlers";
6
6
  import { useMergeRefs } from "../util/hooks/useMergeRefs";
7
- import { useI18n } from "../util/i18n/i18n.context";
7
+ import { useI18n } from "../util/i18n/i18n.hooks";
8
8
  import { HelpTextIcon } from "./HelpTextIcon";
9
9
 
10
10
  export interface HelpTextProps
@@ -2,7 +2,7 @@ import cl from "clsx";
2
2
  import React, { SVGProps, forwardRef } from "react";
3
3
  import { omit } from "../util";
4
4
  import { useId } from "../util/hooks";
5
- import { useI18n } from "../util/i18n/i18n.context";
5
+ import { useI18n } from "../util/i18n/i18n.hooks";
6
6
 
7
7
  export interface LoaderProps extends Omit<SVGProps<SVGSVGElement>, "ref"> {
8
8
  /**
@@ -2,7 +2,7 @@ import cl from "clsx";
2
2
  import React, { forwardRef } from "react";
3
3
  import { XMarkIcon } from "@navikt/aksel-icons";
4
4
  import { Button } from "../button";
5
- import { useI18n } from "../util/i18n/i18n.context";
5
+ import { useI18n } from "../util/i18n/i18n.hooks";
6
6
  import { useModalContext } from "./Modal.context";
7
7
 
8
8
  export interface ModalHeaderProps extends React.HTMLAttributes<HTMLDivElement> {
@@ -3,7 +3,7 @@ import React, { forwardRef } from "react";
3
3
  import { ChevronLeftIcon, ChevronRightIcon } from "@navikt/aksel-icons";
4
4
  import { BodyShort, Heading } from "../typography";
5
5
  import { useId } from "../util";
6
- import { useI18n } from "../util/i18n/i18n.context";
6
+ import { useI18n } from "../util/i18n/i18n.hooks";
7
7
  import PaginationItem, {
8
8
  PaginationItemProps,
9
9
  PaginationItemType,
@@ -1,6 +1,6 @@
1
1
  import cl from "clsx";
2
2
  import React, { HTMLAttributes, forwardRef, useEffect, useRef } from "react";
3
- import { useI18n } from "../util/i18n/i18n.context";
3
+ import { useI18n } from "../util/i18n/i18n.hooks";
4
4
 
5
5
  interface ProgressBarPropsBase
6
6
  extends Omit<HTMLAttributes<HTMLDivElement>, "role"> {
@@ -4,7 +4,7 @@ import { ChevronDownIcon } from "@navikt/aksel-icons";
4
4
  import { composeEventHandlers } from "../util/composeEventHandlers";
5
5
  import { useId } from "../util/hooks";
6
6
  import { useControllableState } from "../util/hooks/useControllableState";
7
- import { useI18n } from "../util/i18n/i18n.context";
7
+ import { useI18n } from "../util/i18n/i18n.hooks";
8
8
  import AnimateHeight from "./AnimateHeight";
9
9
  import DataCell from "./DataCell";
10
10
  import Row, { RowProps } from "./Row";
@@ -1,4 +1,4 @@
1
- import { act, fireEvent, render, screen } from "@testing-library/react";
1
+ import { fireEvent, render, screen } from "@testing-library/react";
2
2
  import userEvent from "@testing-library/user-event";
3
3
  import React from "react";
4
4
  import { describe, expect, test } from "vitest";
@@ -154,19 +154,11 @@ describe("Tabs", () => {
154
154
  expect(screen.getByTestId("tab2")).toHaveFocus();
155
155
 
156
156
  /* Move focus to tabPanel */
157
- // eslint-disable-next-line testing-library/no-unnecessary-act
158
- await act(async () => {
159
- /* Tablist handles tabbing with setTimeout, so we need to use act */
160
- await userEvent.tab();
161
- });
162
-
157
+ await userEvent.tab();
163
158
  expect(screen.getByTestId("tabpanel1")).toHaveFocus();
164
- /* Move focus back to tablist, now tab1 should have focus */
165
159
 
166
- // eslint-disable-next-line testing-library/no-unnecessary-act
167
- await act(async () => {
168
- await userEvent.tab({ shift: true });
169
- });
160
+ /* Move focus back to tablist, now tab1 should have focus */
161
+ await userEvent.tab({ shift: true });
170
162
  expect(screen.getByTestId("tab1")).toHaveFocus();
171
163
  });
172
164
  });
@@ -16,7 +16,8 @@ import {
16
16
  } from "date-fns";
17
17
  import React from "react";
18
18
  import { Detail } from "../typography/Detail";
19
- import { TFunction, useDateLocale, useI18n } from "../util/i18n/i18n.context";
19
+ import { useDateLocale, useI18n } from "../util/i18n/i18n.hooks";
20
+ import { TFunction } from "../util/i18n/i18n.types";
20
21
  import { useTimelineContext } from "./hooks/useTimelineContext";
21
22
  import { isVisible } from "./utils";
22
23
  import { horizontalPositionAndWidth } from "./utils/calc";
@@ -17,7 +17,7 @@ import { format } from "date-fns";
17
17
  import React, { forwardRef, useRef, useState } from "react";
18
18
  import { useThemeInternal } from "../theme/Theme";
19
19
  import { useMergeRefs } from "../util/hooks/useMergeRefs";
20
- import { useI18n } from "../util/i18n/i18n.context";
20
+ import { useI18n } from "../util/i18n/i18n.hooks";
21
21
  import { useTimelineContext } from "./hooks/useTimelineContext";
22
22
  import { position } from "./utils/calc";
23
23
  import { TimelineComponentTypes } from "./utils/types.internal";
@@ -2,7 +2,7 @@ import cl from "clsx";
2
2
  import { format } from "date-fns";
3
3
  import React, { forwardRef } from "react";
4
4
  import { BodyShort } from "../typography/BodyShort";
5
- import { useI18n } from "../util/i18n/i18n.context";
5
+ import { useI18n } from "../util/i18n/i18n.hooks";
6
6
  import { PeriodContext } from "./hooks/usePeriodContext";
7
7
  import { useRowContext } from "./hooks/useRowContext";
8
8
  import { useTimelineContext } from "./hooks/useTimelineContext";
@@ -17,7 +17,7 @@ import cl from "clsx";
17
17
  import React, { useRef, useState } from "react";
18
18
  import { useThemeInternal } from "../../theme/Theme";
19
19
  import { useMergeRefs } from "../../util/hooks/useMergeRefs";
20
- import { useI18n } from "../../util/i18n/i18n.context";
20
+ import { useI18n } from "../../util/i18n/i18n.hooks";
21
21
  import { usePeriodContext } from "../hooks/usePeriodContext";
22
22
  import { useRowContext } from "../hooks/useRowContext";
23
23
  import { useTimelineContext } from "../hooks/useTimelineContext";
@@ -1,6 +1,6 @@
1
1
  import cl from "clsx";
2
2
  import React from "react";
3
- import { useI18n } from "../../util/i18n/i18n.context";
3
+ import { useI18n } from "../../util/i18n/i18n.hooks";
4
4
  import { ariaLabel, getConditionalClasses } from "../utils/period";
5
5
  import type { PeriodProps } from "./types";
6
6
 
@@ -1,6 +1,6 @@
1
1
  import cl from "clsx";
2
2
  import { format } from "date-fns";
3
- import type { TFunction } from "../../util/i18n/i18n.context";
3
+ import type { TFunction } from "../../util/i18n/i18n.types";
4
4
  import type { PeriodProps } from "../period/types";
5
5
 
6
6
  export const getConditionalClasses = (
@@ -8,7 +8,7 @@ import {
8
8
  } from "date-fns";
9
9
  import React, { forwardRef } from "react";
10
10
  import { Detail } from "../../typography/Detail";
11
- import { useI18n } from "../../util/i18n/i18n.context";
11
+ import { useI18n } from "../../util/i18n/i18n.hooks";
12
12
  import { useTimelineContext } from "../hooks/useTimelineContext";
13
13
 
14
14
  export interface TimelineZoomButtonProps {
@@ -2,9 +2,8 @@ import { renderHook } from "@testing-library/react";
2
2
  import React from "react";
3
3
  import { describe, expect, test } from "vitest";
4
4
  import { Provider } from "../../provider";
5
- import { useI18n } from "./i18n.context";
6
- import en from "./locales/en";
7
- import nb from "./locales/nb";
5
+ import { useDateLocale, useI18n } from "./i18n.hooks";
6
+ import { en, nb, nn } from "./locales";
8
7
 
9
8
  describe("useI18n", () => {
10
9
  test("should throw error if key is not found", () => {
@@ -112,3 +111,63 @@ describe("useI18n", () => {
112
111
  expect(() => translate("item.uploading", { other: "John" })).toThrowError();
113
112
  });
114
113
  });
114
+
115
+ describe("useDateLocale", () => {
116
+ test("should return the default NB date locale when Provider is not used", () => {
117
+ const { result } = renderHook(() => useDateLocale());
118
+ const dateLocale = result.current;
119
+ expect(dateLocale).toBe(nb.global.dateLocale);
120
+ });
121
+
122
+ test("should return the default NB date locale when Provider is used without the locale prop", () => {
123
+ const { result } = renderHook(() => useDateLocale(), {
124
+ wrapper: ({ children }) => <Provider>{children}</Provider>,
125
+ });
126
+ const dateLocale = result.current;
127
+ expect(dateLocale).toBe(nb.global.dateLocale);
128
+ });
129
+
130
+ test("should return date locale from context.locale when using Provider with just locale prop", () => {
131
+ const { result } = renderHook(() => useDateLocale(), {
132
+ wrapper: ({ children }) => <Provider locale={en}>{children}</Provider>,
133
+ });
134
+ const dateLocale = result.current;
135
+ expect(dateLocale).toBe(en.global.dateLocale);
136
+ });
137
+
138
+ test("should return date locale from context.locale when it does not exist in translations", () => {
139
+ const { result } = renderHook(() => useDateLocale(), {
140
+ wrapper: ({ children }) => (
141
+ <Provider locale={en} translations={{ global: {} }}>
142
+ {children}
143
+ </Provider>
144
+ ),
145
+ });
146
+ const dateLocale = result.current;
147
+ expect(dateLocale).toBe(en.global.dateLocale);
148
+ });
149
+
150
+ test("should return date locale from context.translations", () => {
151
+ const { result } = renderHook(() => useDateLocale(), {
152
+ wrapper: ({ children }) => (
153
+ <Provider locale={en} translations={nn}>
154
+ {children}
155
+ </Provider>
156
+ ),
157
+ });
158
+ const dateLocale = result.current;
159
+ expect(dateLocale).toBe(nn.global.dateLocale);
160
+ });
161
+
162
+ test("should return date locale from second object in context.translations", () => {
163
+ const { result } = renderHook(() => useDateLocale(), {
164
+ wrapper: ({ children }) => (
165
+ <Provider locale={nb} translations={[{}, nn, en]}>
166
+ {children}
167
+ </Provider>
168
+ ),
169
+ });
170
+ const dateLocale = result.current;
171
+ expect(dateLocale).toBe(nn.global.dateLocale);
172
+ });
173
+ });