@navikt/ds-react 7.2.1 → 7.3.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 (222) hide show
  1. package/cjs/accordion/AccordionHeader.js +1 -1
  2. package/cjs/accordion/AccordionHeader.js.map +1 -1
  3. package/cjs/alert/Alert.d.ts +0 -3
  4. package/cjs/alert/Alert.js +11 -17
  5. package/cjs/alert/Alert.js.map +1 -1
  6. package/cjs/chips/Removable.d.ts +5 -5
  7. package/cjs/chips/Removable.js +4 -2
  8. package/cjs/chips/Removable.js.map +1 -1
  9. package/cjs/collapsible/Collapsible.context.d.ts +1 -1
  10. package/cjs/date/datepicker/DatePicker.d.ts +2 -2
  11. package/cjs/date/monthpicker/MonthPicker.d.ts +2 -2
  12. package/cjs/form/combobox/Input/Input.js +1 -1
  13. package/cjs/form/combobox/Input/Input.js.map +1 -1
  14. package/cjs/form/combobox/types.d.ts +3 -1
  15. package/cjs/form/file-upload/FileUpload.context.d.ts +1 -1
  16. package/cjs/index.d.ts +1 -0
  17. package/cjs/index.js +4 -2
  18. package/cjs/index.js.map +1 -1
  19. package/cjs/layout/base/BasePrimitive.d.ts +3 -0
  20. package/cjs/layout/base/BasePrimitive.js.map +1 -1
  21. package/cjs/layout/box/Box.d.ts +2 -2
  22. package/cjs/layout/box/Box.js.map +1 -1
  23. package/cjs/layout/grid/HGrid.d.ts +2 -2
  24. package/cjs/layout/grid/HGrid.js.map +1 -1
  25. package/cjs/layout/stack/Stack.d.ts +2 -2
  26. package/cjs/layout/stack/Stack.js.map +1 -1
  27. package/cjs/modal/ModalHeader.js +6 -1
  28. package/cjs/modal/ModalHeader.js.map +1 -1
  29. package/cjs/modal/dialog-polyfill.js +2 -2
  30. package/cjs/modal/dialog-polyfill.js.map +1 -1
  31. package/cjs/overlays/action-menu/ActionMenu.d.ts +310 -0
  32. package/cjs/overlays/action-menu/ActionMenu.js +227 -0
  33. package/cjs/overlays/action-menu/ActionMenu.js.map +1 -0
  34. package/cjs/overlays/action-menu/index.d.ts +1 -0
  35. package/cjs/overlays/action-menu/index.js +19 -0
  36. package/cjs/overlays/action-menu/index.js.map +1 -0
  37. package/cjs/overlays/floating/Floating.js +9 -10
  38. package/cjs/overlays/floating/Floating.js.map +1 -1
  39. package/cjs/overlays/floating/Floating.utils.d.ts +3 -5
  40. package/cjs/overlays/floating/Floating.utils.js +0 -2
  41. package/cjs/overlays/floating/Floating.utils.js.map +1 -1
  42. package/cjs/overlays/floating-menu/Menu.d.ts +15 -21
  43. package/cjs/overlays/floating-menu/Menu.js +119 -230
  44. package/cjs/overlays/floating-menu/Menu.js.map +1 -1
  45. package/cjs/overlays/floating-menu/parts/RovingFocus.d.ts +1 -1
  46. package/cjs/overlays/floating-menu/parts/RovingFocus.js.map +1 -1
  47. package/cjs/pagination/Pagination.d.ts +1 -6
  48. package/cjs/pagination/Pagination.js.map +1 -1
  49. package/cjs/provider/i18n/LanguageProvider.d.ts +3 -3
  50. package/cjs/stepper/context.d.ts +1 -1
  51. package/cjs/table/Body.d.ts +2 -4
  52. package/cjs/table/Body.js.map +1 -1
  53. package/cjs/table/ColumnHeader.d.ts +1 -2
  54. package/cjs/table/ColumnHeader.js.map +1 -1
  55. package/cjs/table/ExpandableRow.d.ts +1 -2
  56. package/cjs/table/ExpandableRow.js.map +1 -1
  57. package/cjs/table/Header.d.ts +2 -4
  58. package/cjs/table/Header.js.map +1 -1
  59. package/cjs/table/HeaderCell.d.ts +1 -2
  60. package/cjs/table/HeaderCell.js.map +1 -1
  61. package/cjs/table/Row.d.ts +1 -2
  62. package/cjs/table/Row.js.map +1 -1
  63. package/cjs/tabs/Tabs.context.d.ts +1 -1
  64. package/cjs/toggle-group/ToggleGroup.context.d.ts +1 -1
  65. package/cjs/util/hooks/descendants/useDescendant.js +4 -4
  66. package/cjs/util/hooks/descendants/useDescendant.js.map +1 -1
  67. package/cjs/util/i18n/get.d.ts +2 -2
  68. package/cjs/util/i18n/get.js.map +1 -1
  69. package/cjs/util/i18n/i18n.context.d.ts +2 -3
  70. package/cjs/util/i18n/i18n.context.js.map +1 -1
  71. package/cjs/util/i18n/i18n.types.d.ts +5 -9
  72. package/cjs/util/i18n/locales/en.d.ts +39 -0
  73. package/cjs/util/i18n/locales/en.js +41 -0
  74. package/cjs/util/i18n/locales/en.js.map +1 -0
  75. package/cjs/util/i18n/locales/nb.d.ts +14 -0
  76. package/cjs/util/i18n/locales/nb.js +14 -0
  77. package/cjs/util/i18n/locales/nb.js.map +1 -1
  78. package/cjs/util/i18n/locales/nn.d.ts +39 -0
  79. package/cjs/util/i18n/locales/nn.js +41 -0
  80. package/cjs/util/i18n/locales/nn.js.map +1 -0
  81. package/cjs/util/requireReactElement.d.ts +2 -0
  82. package/cjs/util/requireReactElement.js +22 -0
  83. package/cjs/util/requireReactElement.js.map +1 -0
  84. package/cjs/util/virtualfocus/Context.d.ts +1 -1
  85. package/cjs/util/virtualfocus/parts/VirtualFocusContent.d.ts +1 -2
  86. package/cjs/util/virtualfocus/parts/VirtualFocusContent.js.map +1 -1
  87. package/esm/accordion/AccordionHeader.js +1 -1
  88. package/esm/accordion/AccordionHeader.js.map +1 -1
  89. package/esm/alert/Alert.d.ts +0 -3
  90. package/esm/alert/Alert.js +11 -17
  91. package/esm/alert/Alert.js.map +1 -1
  92. package/esm/chips/Removable.d.ts +5 -5
  93. package/esm/chips/Removable.js +4 -2
  94. package/esm/chips/Removable.js.map +1 -1
  95. package/esm/collapsible/Collapsible.context.d.ts +1 -1
  96. package/esm/date/datepicker/DatePicker.d.ts +2 -2
  97. package/esm/date/monthpicker/MonthPicker.d.ts +2 -2
  98. package/esm/form/combobox/Input/Input.js +1 -1
  99. package/esm/form/combobox/Input/Input.js.map +1 -1
  100. package/esm/form/combobox/types.d.ts +3 -1
  101. package/esm/form/file-upload/FileUpload.context.d.ts +1 -1
  102. package/esm/index.d.ts +1 -0
  103. package/esm/index.js +1 -0
  104. package/esm/index.js.map +1 -1
  105. package/esm/layout/base/BasePrimitive.d.ts +3 -0
  106. package/esm/layout/base/BasePrimitive.js.map +1 -1
  107. package/esm/layout/box/Box.d.ts +2 -2
  108. package/esm/layout/box/Box.js.map +1 -1
  109. package/esm/layout/grid/HGrid.d.ts +2 -2
  110. package/esm/layout/grid/HGrid.js.map +1 -1
  111. package/esm/layout/stack/Stack.d.ts +2 -2
  112. package/esm/layout/stack/Stack.js.map +1 -1
  113. package/esm/modal/ModalHeader.js +6 -1
  114. package/esm/modal/ModalHeader.js.map +1 -1
  115. package/esm/modal/dialog-polyfill.js +2 -2
  116. package/esm/modal/dialog-polyfill.js.map +1 -1
  117. package/esm/overlays/action-menu/ActionMenu.d.ts +310 -0
  118. package/esm/overlays/action-menu/ActionMenu.js +197 -0
  119. package/esm/overlays/action-menu/ActionMenu.js.map +1 -0
  120. package/esm/overlays/action-menu/index.d.ts +1 -0
  121. package/esm/overlays/action-menu/index.js +3 -0
  122. package/esm/overlays/action-menu/index.js.map +1 -0
  123. package/esm/overlays/floating/Floating.js +9 -10
  124. package/esm/overlays/floating/Floating.js.map +1 -1
  125. package/esm/overlays/floating/Floating.utils.d.ts +3 -5
  126. package/esm/overlays/floating/Floating.utils.js +0 -2
  127. package/esm/overlays/floating/Floating.utils.js.map +1 -1
  128. package/esm/overlays/floating-menu/Menu.d.ts +15 -21
  129. package/esm/overlays/floating-menu/Menu.js +119 -230
  130. package/esm/overlays/floating-menu/Menu.js.map +1 -1
  131. package/esm/overlays/floating-menu/parts/RovingFocus.d.ts +1 -1
  132. package/esm/overlays/floating-menu/parts/RovingFocus.js.map +1 -1
  133. package/esm/pagination/Pagination.d.ts +1 -6
  134. package/esm/pagination/Pagination.js.map +1 -1
  135. package/esm/provider/i18n/LanguageProvider.d.ts +3 -3
  136. package/esm/stepper/context.d.ts +1 -1
  137. package/esm/table/Body.d.ts +2 -4
  138. package/esm/table/Body.js.map +1 -1
  139. package/esm/table/ColumnHeader.d.ts +1 -2
  140. package/esm/table/ColumnHeader.js.map +1 -1
  141. package/esm/table/ExpandableRow.d.ts +1 -2
  142. package/esm/table/ExpandableRow.js.map +1 -1
  143. package/esm/table/Header.d.ts +2 -4
  144. package/esm/table/Header.js.map +1 -1
  145. package/esm/table/HeaderCell.d.ts +1 -2
  146. package/esm/table/HeaderCell.js.map +1 -1
  147. package/esm/table/Row.d.ts +1 -2
  148. package/esm/table/Row.js.map +1 -1
  149. package/esm/tabs/Tabs.context.d.ts +1 -1
  150. package/esm/toggle-group/ToggleGroup.context.d.ts +1 -1
  151. package/esm/util/hooks/descendants/useDescendant.js +4 -4
  152. package/esm/util/hooks/descendants/useDescendant.js.map +1 -1
  153. package/esm/util/i18n/get.d.ts +2 -2
  154. package/esm/util/i18n/get.js.map +1 -1
  155. package/esm/util/i18n/i18n.context.d.ts +2 -3
  156. package/esm/util/i18n/i18n.context.js.map +1 -1
  157. package/esm/util/i18n/i18n.types.d.ts +5 -9
  158. package/esm/util/i18n/locales/en.d.ts +39 -0
  159. package/esm/util/i18n/locales/en.js +39 -0
  160. package/esm/util/i18n/locales/en.js.map +1 -0
  161. package/esm/util/i18n/locales/nb.d.ts +14 -0
  162. package/esm/util/i18n/locales/nb.js +14 -0
  163. package/esm/util/i18n/locales/nb.js.map +1 -1
  164. package/esm/util/i18n/locales/nn.d.ts +39 -0
  165. package/esm/util/i18n/locales/nn.js +39 -0
  166. package/esm/util/i18n/locales/nn.js.map +1 -0
  167. package/esm/util/requireReactElement.d.ts +2 -0
  168. package/esm/util/requireReactElement.js +15 -0
  169. package/esm/util/requireReactElement.js.map +1 -0
  170. package/esm/util/virtualfocus/Context.d.ts +1 -1
  171. package/esm/util/virtualfocus/parts/VirtualFocusContent.d.ts +1 -2
  172. package/esm/util/virtualfocus/parts/VirtualFocusContent.js.map +1 -1
  173. package/package.json +15 -7
  174. package/src/accordion/AccordionHeader.tsx +0 -1
  175. package/src/alert/Alert.tsx +11 -20
  176. package/src/chips/Removable.tsx +13 -9
  177. package/src/date/datepicker/DatePicker.tsx +2 -2
  178. package/src/date/monthpicker/MonthPicker.tsx +2 -2
  179. package/src/form/checkbox/Checkbox.test.tsx +2 -3
  180. package/src/form/combobox/Input/Input.tsx +1 -1
  181. package/src/form/combobox/types.ts +3 -1
  182. package/src/form/confirmation-panel/ConfirmationPanel.test.tsx +1 -2
  183. package/src/form/radio/Radio.test.tsx +4 -5
  184. package/src/index.ts +1 -0
  185. package/src/layout/base/BasePrimitive.tsx +3 -0
  186. package/src/layout/box/Box.tsx +35 -36
  187. package/src/layout/grid/HGrid.tsx +26 -27
  188. package/src/layout/stack/Stack.tsx +53 -54
  189. package/src/modal/ModalHeader.tsx +6 -0
  190. package/src/modal/dialog-polyfill.ts +2 -2
  191. package/src/overlays/action-menu/ActionMenu.tsx +971 -0
  192. package/src/overlays/action-menu/index.ts +29 -0
  193. package/src/overlays/floating/Floating.tsx +6 -12
  194. package/src/overlays/floating/Floating.utils.ts +2 -5
  195. package/src/overlays/floating-menu/Menu.tsx +183 -332
  196. package/src/overlays/floating-menu/parts/RovingFocus.tsx +3 -3
  197. package/src/pagination/Pagination.tsx +4 -1
  198. package/src/pagination/steps.test.ts +15 -16
  199. package/src/provider/i18n/LanguageProvider.tsx +3 -3
  200. package/src/table/Body.tsx +4 -6
  201. package/src/table/ColumnHeader.tsx +3 -4
  202. package/src/table/ExpandableRow.tsx +3 -4
  203. package/src/table/Header.tsx +4 -6
  204. package/src/table/HeaderCell.tsx +3 -4
  205. package/src/table/Row.tsx +3 -4
  206. package/src/util/hooks/descendants/useDescendant.tsx +5 -5
  207. package/src/util/i18n/get.ts +3 -3
  208. package/src/util/i18n/i18n.context.ts +2 -3
  209. package/src/util/i18n/i18n.types.ts +7 -11
  210. package/src/util/i18n/locales/en.ts +40 -0
  211. package/src/util/i18n/locales/nb.ts +23 -1
  212. package/src/util/i18n/locales/nn.ts +40 -0
  213. package/src/util/i18n/locales.test.tsx +23 -0
  214. package/src/util/requireReactElement.ts +25 -0
  215. package/src/util/virtualfocus/parts/VirtualFocusContent.tsx +4 -2
  216. package/cjs/util/i18n/merge.d.ts +0 -2
  217. package/cjs/util/i18n/merge.js +0 -28
  218. package/cjs/util/i18n/merge.js.map +0 -1
  219. package/esm/util/i18n/merge.d.ts +0 -2
  220. package/esm/util/i18n/merge.js +0 -25
  221. package/esm/util/i18n/merge.js.map +0 -1
  222. package/src/util/i18n/merge.ts +0 -35
@@ -7,7 +7,7 @@ import { DescendantsManager } from "../../../util/hooks/descendants/descendant";
7
7
  interface RovingFocusProps
8
8
  extends Omit<React.HTMLAttributes<HTMLDivElement>, "tabIndex"> {
9
9
  asChild?: boolean;
10
- descendants: DescendantsManager<HTMLDivElement, object>;
10
+ descendants: DescendantsManager<HTMLDivElement, any>;
11
11
  onEntryFocus?: (event: Event) => void;
12
12
  }
13
13
 
@@ -25,8 +25,8 @@ const RovingFocus = forwardRef<HTMLDivElement, RovingFocusProps>(
25
25
  onMouseDown,
26
26
  onFocus,
27
27
  ...rest
28
- }: RovingFocusProps,
29
- ref,
28
+ },
29
+ ref: React.Ref<HTMLDivElement>,
30
30
  ) => {
31
31
  const _ref = React.useRef<HTMLDivElement>(null);
32
32
  const composedRefs = useMergeRefs(ref, _ref);
@@ -69,7 +69,10 @@ export const getSteps = ({
69
69
  count,
70
70
  boundaryCount = 1,
71
71
  siblingCount = 1,
72
- }) => {
72
+ }: Pick<
73
+ PaginationProps,
74
+ "page" | "count" | "boundaryCount" | "siblingCount"
75
+ >) => {
73
76
  const range = (start: number, end: number) =>
74
77
  Array.from({ length: end - start + 1 }, (_, i) => start + i);
75
78
 
@@ -1,18 +1,17 @@
1
- import faker from "faker";
2
1
  import { describe, expect, test } from "vitest";
3
2
  import { getSteps } from "./Pagination";
4
3
 
5
4
  describe("getSteps", () => {
6
5
  test("lists all pages when count is <= 7", () => {
7
- const count = faker.datatype.number({ min: 1, max: 7 });
6
+ const count = 5;
8
7
  expect(getSteps({ page: 1, count })).toEqual(
9
8
  Array.from({ length: count }, (_, i) => i + 1),
10
9
  );
11
10
  });
12
11
 
13
12
  test("has an end ellipsis when count >= 8", () => {
14
- const count = faker.datatype.number({ min: 8 });
15
- const page = faker.datatype.number({ min: 1, max: 4 });
13
+ const count = 8;
14
+ const page = 3;
16
15
  expect(
17
16
  getSteps({
18
17
  page,
@@ -22,8 +21,8 @@ describe("getSteps", () => {
22
21
  });
23
22
 
24
23
  test("has a start ellipsis when count - page >= 3", () => {
25
- const count = faker.datatype.number({ min: 8 });
26
- const page = faker.datatype.number({ min: count - 3, max: count });
24
+ const count = 8;
25
+ const page = 5;
27
26
  expect(
28
27
  getSteps({
29
28
  page,
@@ -41,8 +40,8 @@ describe("getSteps", () => {
41
40
  });
42
41
 
43
42
  test("has start & end ellipsis when count is high", () => {
44
- const count = faker.datatype.number({ min: 9 });
45
- const page = faker.datatype.number({ min: 5, max: count - 4 });
43
+ const count = 9;
44
+ const page = 5;
46
45
  expect(
47
46
  getSteps({
48
47
  page,
@@ -52,8 +51,8 @@ describe("getSteps", () => {
52
51
  });
53
52
 
54
53
  test("can have a reduced siblingCount", () => {
55
- const count = faker.datatype.number({ min: 7 });
56
- const page = faker.datatype.number({ min: 4, max: count - 3 });
54
+ const count = 7;
55
+ const page = 4;
57
56
  expect(
58
57
  getSteps({
59
58
  page,
@@ -64,8 +63,8 @@ describe("getSteps", () => {
64
63
  });
65
64
 
66
65
  test("can have an increased siblingCount", () => {
67
- const count = faker.datatype.number({ min: 11 });
68
- const page = faker.datatype.number({ min: 6, max: count - 5 });
66
+ const count = 11;
67
+ const page = 6;
69
68
  expect(
70
69
  getSteps({
71
70
  page,
@@ -86,8 +85,8 @@ describe("getSteps", () => {
86
85
  });
87
86
 
88
87
  test("can have an reduced boundaryCount", () => {
89
- const count = faker.datatype.number({ min: 7 });
90
- const page = faker.datatype.number({ min: 4, max: count - 3 });
88
+ const count = 7;
89
+ const page = 4;
91
90
  expect(
92
91
  getSteps({
93
92
  page,
@@ -98,8 +97,8 @@ describe("getSteps", () => {
98
97
  });
99
98
 
100
99
  test("can have an increased boundaryCount", () => {
101
- const count = faker.datatype.number({ min: 11 });
102
- const page = faker.datatype.number({ min: 6, max: count - 5 });
100
+ const count = 11;
101
+ const page = 6;
103
102
  expect(
104
103
  getSteps({
105
104
  page,
@@ -1,12 +1,12 @@
1
1
  import React, { createContext, useContext } from "react";
2
- import { TranslationDictionary } from "../../util/i18n/i18n.types";
2
+ import { PartialTranslations } from "../../util/i18n/i18n.types";
3
3
  import nb from "../../util/i18n/locales/nb";
4
4
 
5
5
  export interface LanguageProviderContextType {
6
6
  /**
7
7
  * Merged with the default language translations object (officially provided translations).
8
8
  */
9
- translations: TranslationDictionary | TranslationDictionary[];
9
+ translations: PartialTranslations | PartialTranslations[];
10
10
  }
11
11
 
12
12
  export const LanguageProviderContext =
@@ -16,7 +16,7 @@ export const LanguageProviderContext =
16
16
 
17
17
  export interface LanguageProviderProps {
18
18
  children?: React.ReactNode;
19
- translations?: TranslationDictionary | TranslationDictionary[];
19
+ translations?: PartialTranslations | PartialTranslations[];
20
20
  }
21
21
 
22
22
  export const useProvider = () => useContext(LanguageProviderContext);
@@ -1,13 +1,11 @@
1
1
  import cl from "clsx";
2
2
  import React, { forwardRef } from "react";
3
3
 
4
- export interface BodyProps
5
- extends React.HTMLAttributes<HTMLTableSectionElement> {}
4
+ export type BodyProps = React.HTMLAttributes<HTMLTableSectionElement>;
6
5
 
7
- export interface BodyType
8
- extends React.ForwardRefExoticComponent<
9
- BodyProps & React.RefAttributes<HTMLTableSectionElement>
10
- > {}
6
+ export type BodyType = React.ForwardRefExoticComponent<
7
+ BodyProps & React.RefAttributes<HTMLTableSectionElement>
8
+ >;
11
9
 
12
10
  export const Body: BodyType = forwardRef(({ className, ...rest }, ref) => (
13
11
  <tbody {...rest} ref={ref} className={cl("navds-table__body", className)} />
@@ -19,10 +19,9 @@ export interface ColumnHeaderProps extends HeaderCellProps {
19
19
  sortable?: boolean;
20
20
  }
21
21
 
22
- export interface ColumnHeaderType
23
- extends React.ForwardRefExoticComponent<
24
- ColumnHeaderProps & React.RefAttributes<HTMLTableCellElement>
25
- > {}
22
+ export type ColumnHeaderType = React.ForwardRefExoticComponent<
23
+ ColumnHeaderProps & React.RefAttributes<HTMLTableCellElement>
24
+ >;
26
25
 
27
26
  export const ColumnHeader: ColumnHeaderType = forwardRef(
28
27
  ({ className, children, sortable = false, sortKey, ...rest }, ref) => {
@@ -49,10 +49,9 @@ export interface ExpandableRowProps extends Omit<RowProps, "content"> {
49
49
  colSpan?: number;
50
50
  }
51
51
 
52
- export interface ExpandableRowType
53
- extends React.ForwardRefExoticComponent<
54
- ExpandableRowProps & React.RefAttributes<HTMLTableRowElement>
55
- > {}
52
+ export type ExpandableRowType = React.ForwardRefExoticComponent<
53
+ ExpandableRowProps & React.RefAttributes<HTMLTableRowElement>
54
+ >;
56
55
 
57
56
  export const ExpandableRow: ExpandableRowType = forwardRef(
58
57
  (
@@ -1,13 +1,11 @@
1
1
  import cl from "clsx";
2
2
  import React, { forwardRef } from "react";
3
3
 
4
- export interface HeaderProps
5
- extends React.HTMLAttributes<HTMLTableSectionElement> {}
4
+ export type HeaderProps = React.HTMLAttributes<HTMLTableSectionElement>;
6
5
 
7
- export interface HeaderType
8
- extends React.ForwardRefExoticComponent<
9
- HeaderProps & React.RefAttributes<HTMLTableSectionElement>
10
- > {}
6
+ export type HeaderType = React.ForwardRefExoticComponent<
7
+ HeaderProps & React.RefAttributes<HTMLTableSectionElement>
8
+ >;
11
9
 
12
10
  export const Header: HeaderType = forwardRef(({ className, ...rest }, ref) => (
13
11
  <thead {...rest} ref={ref} className={cl("navds-table__header", className)} />
@@ -15,10 +15,9 @@ export interface HeaderCellProps
15
15
  textSize?: "medium" | "small";
16
16
  }
17
17
 
18
- export interface HeaderCellType
19
- extends React.ForwardRefExoticComponent<
20
- HeaderCellProps & React.RefAttributes<HTMLTableCellElement>
21
- > {}
18
+ export type HeaderCellType = React.ForwardRefExoticComponent<
19
+ HeaderCellProps & React.RefAttributes<HTMLTableCellElement>
20
+ >;
22
21
 
23
22
  export const HeaderCell: HeaderCellType = forwardRef(
24
23
  ({ className, children, align, textSize, ...rest }, ref) => {
package/src/table/Row.tsx CHANGED
@@ -14,10 +14,9 @@ export interface RowProps extends React.HTMLAttributes<HTMLTableRowElement> {
14
14
  shadeOnHover?: boolean;
15
15
  }
16
16
 
17
- export interface RowType
18
- extends React.ForwardRefExoticComponent<
19
- RowProps & React.RefAttributes<HTMLTableRowElement>
20
- > {}
17
+ export type RowType = React.ForwardRefExoticComponent<
18
+ RowProps & React.RefAttributes<HTMLTableRowElement>
19
+ >;
21
20
 
22
21
  export const Row: RowType = forwardRef(
23
22
  ({ className, selected = false, shadeOnHover = true, ...rest }, ref) => (
@@ -16,7 +16,7 @@ export function createDescendantContext<
16
16
  K extends Record<string, any> = object,
17
17
  >() {
18
18
  const [DescendantsContextProvider, useDescendantsContext] = createContext<
19
- ReturnType<typeof _useDescendants>
19
+ ReturnType<typeof useDescendants>
20
20
  >({
21
21
  name: "DescendantsProvider",
22
22
  errorMessage:
@@ -38,7 +38,7 @@ export function createDescendantContext<
38
38
  * - ref callback to register the descendant
39
39
  * - Its enabled index compared to other enabled descendants
40
40
  */
41
- function _useDescendant(options?: DescendantOptions<K>) {
41
+ function useDescendant(options?: DescendantOptions<K>) {
42
42
  const descendants = useDescendantsContext();
43
43
  const [index, setIndex] = useState(-1);
44
44
  const ref = useRef<T>(null);
@@ -74,7 +74,7 @@ export function createDescendantContext<
74
74
  * @internal
75
75
  * Initializing DescendantsManager
76
76
  */
77
- function _useDescendants() {
77
+ function useDescendants() {
78
78
  const descendants = useRef(new DescendantsManager<T, K>()).current;
79
79
 
80
80
  return descendants;
@@ -86,8 +86,8 @@ export function createDescendantContext<
86
86
  // call this when you need to read from context
87
87
  useDescendantsContext,
88
88
  // descendants state information, to be called and passed to `ContextProvider`
89
- _useDescendants,
89
+ useDescendants,
90
90
  // descendant index information
91
- _useDescendant,
91
+ useDescendant,
92
92
  ] as const;
93
93
  }
@@ -1,4 +1,4 @@
1
- import { TranslationObject } from "./i18n.types";
1
+ import { PartialTranslations } from "./i18n.types";
2
2
 
3
3
  /**
4
4
  * https://github.com/Shopify/polaris/blob/main/polaris-react/src/utilities/get.ts#L3
@@ -7,7 +7,7 @@ const OBJECT_NOTATION_MATCHER = /(\w+)/g;
7
7
 
8
8
  export function get(
9
9
  keypath: string | string[],
10
- ...objs: (TranslationObject | undefined)[]
10
+ ...objs: (PartialTranslations | undefined)[]
11
11
  ) {
12
12
  const keys = Array.isArray(keypath) ? keypath : getKeypath(keypath);
13
13
 
@@ -16,7 +16,7 @@ export function get(
16
16
  continue;
17
17
  }
18
18
 
19
- let acc: string | TranslationObject = obj;
19
+ let acc: string | PartialTranslations = obj;
20
20
 
21
21
  for (let i = 0; i < keys.length; i++) {
22
22
  const val = acc[keys[i]];
@@ -1,8 +1,7 @@
1
1
  import { useContext } from "react";
2
2
  import { LanguageProviderContext } from "../../provider/i18n/LanguageProvider";
3
3
  import { get } from "./get";
4
- import { Component, ComponentTranslation } from "./i18n.types";
5
- import nb from "./locales/nb";
4
+ import { Component, ComponentTranslation, Translations } from "./i18n.types";
6
5
 
7
6
  /**
8
7
  * https://regex101.com/r/LYKWi3/1
@@ -27,7 +26,7 @@ export function useI18n<T extends Component>(
27
26
  * https://github.com/Shopify/polaris/blob/2115f9ba2f5bcbf2ad15745233501bff2db81ecf/polaris-react/src/utilities/i18n/I18n.ts#L24
28
27
  */
29
28
  const translate = (
30
- keypath: NestedKeyOf<(typeof nb)[T]>,
29
+ keypath: NestedKeyOf<Translations[T]>,
31
30
  options?: { replacements: Record<string, string | number> },
32
31
  ) => {
33
32
  const text = get(
@@ -1,20 +1,16 @@
1
- import nb from "./locales/nb";
2
-
3
- export interface TranslationObject {
4
- [key: string]: string | TranslationObject | undefined;
5
- }
6
-
7
- export interface TranslationDictionary {
8
- [key: string]: TranslationObject | undefined;
9
- }
1
+ import type nb from "./locales/nb";
10
2
 
11
3
  /* https://stackoverflow.com/questions/47914536/use-partial-in-nested-property-with-typescripts */
12
4
  type RecursivePartial<T> = {
13
5
  [P in keyof T]?: RecursivePartial<T[P]>;
14
6
  };
15
7
 
16
- export type Component = keyof typeof nb;
8
+ export type Translations = typeof nb;
9
+
10
+ export type PartialTranslations = RecursivePartial<Translations>;
11
+
12
+ export type Component = keyof Translations;
17
13
 
18
14
  export type ComponentTranslation<T extends Component> = RecursivePartial<
19
- (typeof nb)[T]
15
+ Translations[T]
20
16
  >;
@@ -0,0 +1,40 @@
1
+ import type { Translations } from "../i18n.types";
2
+
3
+ export default {
4
+ FileUpload: {
5
+ dropzone: {
6
+ button: "Choose file",
7
+ buttonMultiple: "Choose files",
8
+ dragAndDrop: "Drag and drop file here",
9
+ dragAndDropMultiple: "Drag and drop files here",
10
+ drop: "Drop",
11
+ or: "or",
12
+ disabled: "File upload disabled",
13
+ disabledFilelimit: "You cannot upload more files",
14
+ },
15
+ item: {
16
+ retryButtonTitle: "Try uploading the file again",
17
+ deleteButtonTitle: "Delete file",
18
+ uploading: "Uploading…",
19
+ downloading: "Downloading…",
20
+ },
21
+ },
22
+ FormProgress: {
23
+ step: "Step {activeStep} of {totalSteps}",
24
+ showAllSteps: "Show all steps",
25
+ hideAllSteps: "Hide all steps",
26
+ },
27
+ Alert: {
28
+ closeAlert: "Close alert",
29
+ closeMessage: "Close message",
30
+ error: "Error",
31
+ info: "Information",
32
+ success: "Success",
33
+ warning: "Warning",
34
+ },
35
+ Chips: {
36
+ Removable: {
37
+ labelSuffix: "delete",
38
+ },
39
+ },
40
+ } satisfies Translations;
@@ -1,3 +1,11 @@
1
+ interface TranslationMap {
2
+ [component: string]:
3
+ | Record<string, string>
4
+ | {
5
+ [subComponent: string]: Record<string, string>;
6
+ };
7
+ }
8
+
1
9
  export default {
2
10
  FileUpload: {
3
11
  dropzone: {
@@ -22,4 +30,18 @@ export default {
22
30
  showAllSteps: "Vis alle steg",
23
31
  hideAllSteps: "Skjul alle steg",
24
32
  },
25
- };
33
+ Alert: {
34
+ closeAlert: "Lukk varsel",
35
+ closeMessage: "Lukk melding",
36
+ error: "Feil",
37
+ info: "Informasjon",
38
+ success: "Suksess",
39
+ warning: "Advarsel",
40
+ },
41
+ Chips: {
42
+ Removable: {
43
+ /** Will be appended to the accessible name for the button. */
44
+ labelSuffix: "slett",
45
+ },
46
+ },
47
+ } satisfies TranslationMap;
@@ -0,0 +1,40 @@
1
+ import type { Translations } from "../i18n.types";
2
+
3
+ export default {
4
+ FileUpload: {
5
+ dropzone: {
6
+ button: "Vel fil",
7
+ buttonMultiple: "Vel filer",
8
+ dragAndDrop: "Dra og slepp fila her",
9
+ dragAndDropMultiple: "Dra og slepp filer her",
10
+ drop: "Slepp",
11
+ or: "eller",
12
+ disabled: "Filopplasting er deaktivert",
13
+ disabledFilelimit: "Du kan ikkje laste opp fleire filer",
14
+ },
15
+ item: {
16
+ retryButtonTitle: "Prøv å laste opp fila på nytt",
17
+ deleteButtonTitle: "Slett fila",
18
+ uploading: "Lastar opp…",
19
+ downloading: "Lastar ned…",
20
+ },
21
+ },
22
+ FormProgress: {
23
+ step: "Steg {activeStep} av {totalSteps}",
24
+ showAllSteps: "Vis alle steg",
25
+ hideAllSteps: "Skjul alle steg",
26
+ },
27
+ Alert: {
28
+ closeAlert: "Lukk varsel",
29
+ closeMessage: "Lukk melding",
30
+ error: "Feil",
31
+ info: "Informasjon",
32
+ success: "Suksess",
33
+ warning: "Åtvaring",
34
+ },
35
+ Chips: {
36
+ Removable: {
37
+ labelSuffix: "slett",
38
+ },
39
+ },
40
+ } satisfies Translations;
@@ -0,0 +1,23 @@
1
+ /* eslint-disable @vitest/expect-expect */
2
+ import { describe, expect, test } from "vitest";
3
+ import { Translations } from "./i18n.types";
4
+ import en from "./locales/en";
5
+ import nb from "./locales/nb";
6
+ import nn from "./locales/nn";
7
+
8
+ function checkValues(obj: Translations | Record<string, string>) {
9
+ Object.values(obj).forEach((value) => {
10
+ if (typeof value === "object") {
11
+ checkValues(value);
12
+ } else {
13
+ expect(value).toBeTypeOf("string");
14
+ expect(value).not.toBe("");
15
+ }
16
+ });
17
+ }
18
+
19
+ describe("Locale", () => {
20
+ test("NB should have no empty strings", () => checkValues(nb));
21
+ test("NN should have no empty strings", () => checkValues(nn));
22
+ test("EN should have no empty strings", () => checkValues(en));
23
+ });
@@ -0,0 +1,25 @@
1
+ import React from "react";
2
+
3
+ export const requireReactElement = <T extends React.ReactNode>(
4
+ children: T,
5
+ ): T => {
6
+ const isReactElement = React.isValidElement(children);
7
+
8
+ if (!isReactElement) {
9
+ throw Error(
10
+ `Expected a single React Element child, but got: ${React.Children.toArray(
11
+ children,
12
+ )
13
+ .map((child) =>
14
+ typeof child === "object" &&
15
+ "type" in child &&
16
+ typeof child.type === "string"
17
+ ? child.type
18
+ : typeof child,
19
+ )
20
+ .join(", ")}`,
21
+ );
22
+ }
23
+
24
+ return children;
25
+ };
@@ -1,8 +1,10 @@
1
1
  import React, { forwardRef } from "react";
2
2
  import { useVirtualFocusInternalContext } from "../Context";
3
3
 
4
- export interface VirtualFocusContentProps
5
- extends Omit<React.HTMLAttributes<HTMLDivElement>, "id"> {}
4
+ export type VirtualFocusContentProps = Omit<
5
+ React.HTMLAttributes<HTMLDivElement>,
6
+ "id"
7
+ >;
6
8
 
7
9
  export const VirtualFocusContent = forwardRef<
8
10
  HTMLDivElement,
@@ -1,2 +0,0 @@
1
- import { TranslationDictionary } from "./i18n.types";
2
- export declare function merge(...objs: TranslationDictionary[]): TranslationDictionary;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.merge = merge;
4
- function merge(...objs) {
5
- let final = {};
6
- for (const obj of objs) {
7
- final = mergeRecursively(final, obj);
8
- }
9
- return final;
10
- }
11
- function mergeRecursively(objA, objB) {
12
- const objARes = Object.assign({}, objA);
13
- for (const key in objB) {
14
- if (!(key in objB)) {
15
- continue;
16
- }
17
- const a = objARes[key];
18
- const b = objB[key];
19
- if (b && typeof b !== "string" && typeof a !== "string") {
20
- objARes[key] = mergeRecursively(a, b);
21
- }
22
- else {
23
- objARes[key] = b;
24
- }
25
- }
26
- return objARes;
27
- }
28
- //# sourceMappingURL=merge.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"merge.js","sourceRoot":"","sources":["../../../src/util/i18n/merge.ts"],"names":[],"mappings":";;AAEA,sBAQC;AARD,SAAgB,KAAK,CAAC,GAAG,IAA6B;IACpD,IAAI,KAAK,GAA0B,EAAE,CAAC;IAEtC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,KAAK,GAAG,gBAAgB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,gBAAgB,CACvB,IAAO,EACP,IAA+C;IAE/C,MAAM,OAAO,qBAAQ,IAAI,CAAE,CAAC;IAE5B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC;YACnB,SAAS;QACX,CAAC;QAED,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;QACvB,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;QAEpB,IAAI,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;YACxD,OAAO,CAAC,GAAG,CAAC,GAAG,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACxC,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -1,2 +0,0 @@
1
- import { TranslationDictionary } from "./i18n.types.js";
2
- export declare function merge(...objs: TranslationDictionary[]): TranslationDictionary;
@@ -1,25 +0,0 @@
1
- export function merge(...objs) {
2
- let final = {};
3
- for (const obj of objs) {
4
- final = mergeRecursively(final, obj);
5
- }
6
- return final;
7
- }
8
- function mergeRecursively(objA, objB) {
9
- const objARes = Object.assign({}, objA);
10
- for (const key in objB) {
11
- if (!(key in objB)) {
12
- continue;
13
- }
14
- const a = objARes[key];
15
- const b = objB[key];
16
- if (b && typeof b !== "string" && typeof a !== "string") {
17
- objARes[key] = mergeRecursively(a, b);
18
- }
19
- else {
20
- objARes[key] = b;
21
- }
22
- }
23
- return objARes;
24
- }
25
- //# sourceMappingURL=merge.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"merge.js","sourceRoot":"","sources":["../../../src/util/i18n/merge.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,KAAK,CAAC,GAAG,IAA6B;IACpD,IAAI,KAAK,GAA0B,EAAE,CAAC;IAEtC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,KAAK,GAAG,gBAAgB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,gBAAgB,CACvB,IAAO,EACP,IAA+C;IAE/C,MAAM,OAAO,qBAAQ,IAAI,CAAE,CAAC;IAE5B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC;YACnB,SAAS;QACX,CAAC;QAED,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;QACvB,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;QAEpB,IAAI,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;YACxD,OAAO,CAAC,GAAG,CAAC,GAAG,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACxC,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -1,35 +0,0 @@
1
- import { TranslationDictionary, TranslationObject } from "./i18n.types";
2
-
3
- export function merge(...objs: TranslationDictionary[]) {
4
- let final: TranslationDictionary = {};
5
-
6
- for (const obj of objs) {
7
- final = mergeRecursively(final, obj);
8
- }
9
-
10
- return final;
11
- }
12
-
13
- function mergeRecursively<T>(
14
- objA: T,
15
- objB: TranslationDictionary | TranslationObject,
16
- ) {
17
- const objARes = { ...objA };
18
-
19
- for (const key in objB) {
20
- if (!(key in objB)) {
21
- continue;
22
- }
23
-
24
- const a = objARes[key];
25
- const b = objB[key];
26
-
27
- if (b && typeof b !== "string" && typeof a !== "string") {
28
- objARes[key] = mergeRecursively(a, b);
29
- } else {
30
- objARes[key] = b;
31
- }
32
- }
33
-
34
- return objARes;
35
- }