@navikt/ds-react 8.2.2 → 8.3.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 (85) hide show
  1. package/cjs/data/stories/DataTableProfiler.d.ts +6 -0
  2. package/cjs/data/stories/DataTableProfiler.js +124 -0
  3. package/cjs/data/stories/DataTableProfiler.js.map +1 -0
  4. package/cjs/data/stories/dummy-data.d.ts +2 -3
  5. package/cjs/data/stories/dummy-data.js +30 -9
  6. package/cjs/data/stories/dummy-data.js.map +1 -1
  7. package/cjs/data/table/index.d.ts +2 -2
  8. package/cjs/data/table/index.js +2 -1
  9. package/cjs/data/table/index.js.map +1 -1
  10. package/cjs/data/table/root/DataTableRoot.d.ts +15 -2
  11. package/cjs/data/table/root/DataTableRoot.js +4 -1
  12. package/cjs/data/table/root/DataTableRoot.js.map +1 -1
  13. package/cjs/data/table/tfoot/DataTableTfoot.d.ts +5 -0
  14. package/cjs/data/table/tfoot/DataTableTfoot.js +55 -0
  15. package/cjs/data/table/tfoot/DataTableTfoot.js.map +1 -0
  16. package/cjs/data/table/th/DataTableTh.d.ts +20 -4
  17. package/cjs/data/table/th/DataTableTh.js +24 -6
  18. package/cjs/data/table/th/DataTableTh.js.map +1 -1
  19. package/cjs/data/table/th/DataTableThActions.d.ts +5 -0
  20. package/cjs/data/table/th/DataTableThActions.js +23 -0
  21. package/cjs/data/table/th/DataTableThActions.js.map +1 -0
  22. package/cjs/data/table/th/DataTableThSortHandle.d.ts +6 -0
  23. package/cjs/data/table/th/DataTableThSortHandle.js +82 -0
  24. package/cjs/data/table/th/DataTableThSortHandle.js.map +1 -0
  25. package/cjs/tooltip/Tooltip.d.ts +1 -1
  26. package/cjs/tooltip/Tooltip.js +35 -2
  27. package/cjs/tooltip/Tooltip.js.map +1 -1
  28. package/cjs/utils/i18n/locales/en.d.ts +3 -0
  29. package/cjs/utils/i18n/locales/en.js +3 -0
  30. package/cjs/utils/i18n/locales/en.js.map +1 -1
  31. package/cjs/utils/i18n/locales/nb.d.ts +4 -0
  32. package/cjs/utils/i18n/locales/nb.js +4 -0
  33. package/cjs/utils/i18n/locales/nb.js.map +1 -1
  34. package/cjs/utils/i18n/locales/nn.d.ts +3 -0
  35. package/cjs/utils/i18n/locales/nn.js +3 -0
  36. package/cjs/utils/i18n/locales/nn.js.map +1 -1
  37. package/esm/data/stories/DataTableProfiler.d.ts +6 -0
  38. package/esm/data/stories/DataTableProfiler.js +89 -0
  39. package/esm/data/stories/DataTableProfiler.js.map +1 -0
  40. package/esm/data/stories/dummy-data.d.ts +2 -3
  41. package/esm/data/stories/dummy-data.js +30 -9
  42. package/esm/data/stories/dummy-data.js.map +1 -1
  43. package/esm/data/table/index.d.ts +2 -2
  44. package/esm/data/table/index.js +1 -1
  45. package/esm/data/table/index.js.map +1 -1
  46. package/esm/data/table/root/DataTableRoot.d.ts +15 -2
  47. package/esm/data/table/root/DataTableRoot.js +3 -1
  48. package/esm/data/table/root/DataTableRoot.js.map +1 -1
  49. package/esm/data/table/tfoot/DataTableTfoot.d.ts +5 -0
  50. package/esm/data/table/tfoot/DataTableTfoot.js +19 -0
  51. package/esm/data/table/tfoot/DataTableTfoot.js.map +1 -0
  52. package/esm/data/table/th/DataTableTh.d.ts +20 -4
  53. package/esm/data/table/th/DataTableTh.js +25 -7
  54. package/esm/data/table/th/DataTableTh.js.map +1 -1
  55. package/esm/data/table/th/DataTableThActions.d.ts +5 -0
  56. package/esm/data/table/th/DataTableThActions.js +18 -0
  57. package/esm/data/table/th/DataTableThActions.js.map +1 -0
  58. package/esm/data/table/th/DataTableThSortHandle.d.ts +6 -0
  59. package/esm/data/table/th/DataTableThSortHandle.js +47 -0
  60. package/esm/data/table/th/DataTableThSortHandle.js.map +1 -0
  61. package/esm/tooltip/Tooltip.d.ts +1 -1
  62. package/esm/tooltip/Tooltip.js +35 -2
  63. package/esm/tooltip/Tooltip.js.map +1 -1
  64. package/esm/utils/i18n/locales/en.d.ts +3 -0
  65. package/esm/utils/i18n/locales/en.js +3 -0
  66. package/esm/utils/i18n/locales/en.js.map +1 -1
  67. package/esm/utils/i18n/locales/nb.d.ts +4 -0
  68. package/esm/utils/i18n/locales/nb.js +4 -0
  69. package/esm/utils/i18n/locales/nb.js.map +1 -1
  70. package/esm/utils/i18n/locales/nn.d.ts +3 -0
  71. package/esm/utils/i18n/locales/nn.js +3 -0
  72. package/esm/utils/i18n/locales/nn.js.map +1 -1
  73. package/package.json +3 -3
  74. package/src/data/stories/DataTableProfiler.tsx +215 -0
  75. package/src/data/stories/dummy-data.tsx +39 -17
  76. package/src/data/table/index.tsx +2 -0
  77. package/src/data/table/root/DataTableRoot.tsx +19 -0
  78. package/src/data/table/tfoot/DataTableTfoot.tsx +21 -0
  79. package/src/data/table/th/DataTableTh.tsx +68 -31
  80. package/src/data/table/th/DataTableThActions.tsx +32 -0
  81. package/src/data/table/th/DataTableThSortHandle.tsx +67 -0
  82. package/src/tooltip/Tooltip.tsx +66 -11
  83. package/src/utils/i18n/locales/en.ts +3 -0
  84. package/src/utils/i18n/locales/nb.ts +3 -0
  85. package/src/utils/i18n/locales/nn.ts +3 -0
@@ -0,0 +1,67 @@
1
+ import React, { useMemo } from "react";
2
+ import {
3
+ ArrowsUpDownIcon,
4
+ SortDownIcon,
5
+ SortUpIcon,
6
+ } from "@navikt/aksel-icons";
7
+ import { Button } from "../../../button";
8
+
9
+ const ICON_CONFIG = {
10
+ desc: {
11
+ icon: SortDownIcon,
12
+ title: "Sorter stigende",
13
+ },
14
+ asc: {
15
+ icon: SortUpIcon,
16
+ title: "Ingen sortering",
17
+ },
18
+ none: {
19
+ icon: ArrowsUpDownIcon,
20
+ title: "Sorter synkende",
21
+ },
22
+ };
23
+
24
+ function DataTableThSortHandle({
25
+ sortDirection = false,
26
+ onSortChange,
27
+ }: {
28
+ sortDirection?: "asc" | "desc" | "none" | false;
29
+ onSortChange?: (direction: "asc" | "desc" | "none", event: Event) => void;
30
+ }) {
31
+ const IconConfig = useMemo(() => {
32
+ if (!sortDirection) {
33
+ return null;
34
+ }
35
+ return ICON_CONFIG[sortDirection];
36
+ }, [sortDirection]);
37
+
38
+ if (!sortDirection || !IconConfig) {
39
+ return null;
40
+ }
41
+
42
+ return (
43
+ <Button
44
+ data-color="neutral"
45
+ variant="tertiary"
46
+ size="small"
47
+ icon={<IconConfig.icon title={IconConfig.title} />}
48
+ onClick={(event) => {
49
+ if (!onSortChange) return;
50
+
51
+ /* TODO: This configuration is not a given */
52
+ let newDirection: "asc" | "desc" | "none";
53
+ if (sortDirection === "none") {
54
+ newDirection = "asc";
55
+ } else if (sortDirection === "asc") {
56
+ newDirection = "desc";
57
+ } else {
58
+ newDirection = "none";
59
+ }
60
+ /* TODO: Handle types better */
61
+ onSortChange(newDirection, event as unknown as Event);
62
+ }}
63
+ />
64
+ );
65
+ }
66
+
67
+ export { DataTableThSortHandle };
@@ -12,6 +12,7 @@ import {
12
12
  useInteractions,
13
13
  } from "@floating-ui/react";
14
14
  import React, { HTMLAttributes, forwardRef, useRef } from "react";
15
+ import { HStack } from "../layout/stack";
15
16
  import { useModalContext } from "../modal/Modal.context";
16
17
  import { Portal } from "../portal";
17
18
  import { Detail } from "../typography";
@@ -19,6 +20,7 @@ import { useId } from "../utils-external";
19
20
  import { Slot } from "../utils/components/slot/Slot";
20
21
  import { cl } from "../utils/helpers";
21
22
  import { useControllableState, useMergeRefs } from "../utils/hooks";
23
+ import { useI18n } from "../utils/i18n/i18n.hooks";
22
24
 
23
25
  export interface TooltipProps extends HTMLAttributes<HTMLDivElement> {
24
26
  /**
@@ -79,7 +81,7 @@ export interface TooltipProps extends HTMLAttributes<HTMLDivElement> {
79
81
  /**
80
82
  * List of Keyboard-keys for shortcuts.
81
83
  */
82
- keys?: string[];
84
+ keys?: string[] | [string[], string[]];
83
85
  /**
84
86
  * When false, Tooltip labels the element, and child-elements content will be ignored by screen-readers.
85
87
  * When true, content is added as additional information to the child element.
@@ -204,7 +206,7 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
204
206
  ref={refs.setReference}
205
207
  {...getReferenceProps()}
206
208
  {...labelProps}
207
- aria-keyshortcuts={keys ? keys.join("+") : undefined}
209
+ aria-keyshortcuts={ariaShortcuts(keys)}
208
210
  >
209
211
  {children}
210
212
  </Slot>
@@ -232,15 +234,7 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
232
234
  data-state="open"
233
235
  >
234
236
  {content}
235
- {keys && (
236
- <span className="aksel-tooltip__keys" aria-hidden>
237
- {keys.map((key) => (
238
- <Detail as="kbd" key={key} className="aksel-tooltip__key">
239
- {key}
240
- </Detail>
241
- ))}
242
- </span>
243
- )}
237
+ <TooltipShortcuts shortcuts={keys} />
244
238
  {_arrow && (
245
239
  <div
246
240
  ref={(node) => {
@@ -269,4 +263,65 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
269
263
  },
270
264
  );
271
265
 
266
+ function isKeyShortcutNested(
267
+ shortcuts: TooltipProps["keys"],
268
+ ): shortcuts is [string[], string[]] {
269
+ return Array.isArray(shortcuts?.[0]);
270
+ }
271
+
272
+ /**
273
+ * https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-keyshortcuts
274
+ * Space-separated shortcuts is valid syntax
275
+ */
276
+ function ariaShortcuts(shortcuts: TooltipProps["keys"]) {
277
+ if (!shortcuts) {
278
+ return undefined;
279
+ }
280
+
281
+ if (isKeyShortcutNested(shortcuts)) {
282
+ return shortcuts.map((key) => key.join("+")).join(" ");
283
+ }
284
+
285
+ return shortcuts.join("+");
286
+ }
287
+
288
+ function TooltipShortcuts({ shortcuts }: { shortcuts: TooltipProps["keys"] }) {
289
+ const translate = useI18n("Tooltip");
290
+
291
+ if (!shortcuts) {
292
+ return null;
293
+ }
294
+
295
+ if (isKeyShortcutNested(shortcuts)) {
296
+ return (
297
+ <span className="aksel-tooltip__keys" aria-hidden>
298
+ {shortcuts.map((key, index) => (
299
+ <>
300
+ <HStack gap="space-4">
301
+ {key.map((k, i) => (
302
+ <Detail as="kbd" key={i} className="aksel-tooltip__key">
303
+ {k}
304
+ </Detail>
305
+ ))}
306
+ </HStack>
307
+ {index < shortcuts.length - 1 && (
308
+ <span> {translate("shortcutSeparator")} </span>
309
+ )}
310
+ </>
311
+ ))}
312
+ </span>
313
+ );
314
+ }
315
+
316
+ return (
317
+ <span className="aksel-tooltip__keys" aria-hidden>
318
+ {shortcuts.map((k, i) => (
319
+ <Detail as="kbd" key={i} className="aksel-tooltip__key">
320
+ {k}
321
+ </Detail>
322
+ ))}
323
+ </span>
324
+ );
325
+ }
326
+
272
327
  export default Tooltip;
@@ -132,4 +132,7 @@ export default {
132
132
  reset: "Reset zoom",
133
133
  },
134
134
  },
135
+ Tooltip: {
136
+ shortcutSeparator: "or",
137
+ },
135
138
  } satisfies Translations;
@@ -139,4 +139,7 @@ export default {
139
139
  reset: "Tilbakestill tidsperspektiv",
140
140
  },
141
141
  },
142
+ Tooltip: {
143
+ shortcutSeparator: "eller",
144
+ },
142
145
  } satisfies TranslationMap;
@@ -132,4 +132,7 @@ export default {
132
132
  reset: "Tilbakestill tidsperspektiv",
133
133
  },
134
134
  },
135
+ Tooltip: {
136
+ shortcutSeparator: "eller",
137
+ },
135
138
  } satisfies Translations;