@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.
- package/cjs/data/stories/DataTableProfiler.d.ts +6 -0
- package/cjs/data/stories/DataTableProfiler.js +124 -0
- package/cjs/data/stories/DataTableProfiler.js.map +1 -0
- package/cjs/data/stories/dummy-data.d.ts +2 -3
- package/cjs/data/stories/dummy-data.js +30 -9
- package/cjs/data/stories/dummy-data.js.map +1 -1
- package/cjs/data/table/index.d.ts +2 -2
- package/cjs/data/table/index.js +2 -1
- package/cjs/data/table/index.js.map +1 -1
- package/cjs/data/table/root/DataTableRoot.d.ts +15 -2
- package/cjs/data/table/root/DataTableRoot.js +4 -1
- package/cjs/data/table/root/DataTableRoot.js.map +1 -1
- package/cjs/data/table/tfoot/DataTableTfoot.d.ts +5 -0
- package/cjs/data/table/tfoot/DataTableTfoot.js +55 -0
- package/cjs/data/table/tfoot/DataTableTfoot.js.map +1 -0
- package/cjs/data/table/th/DataTableTh.d.ts +20 -4
- package/cjs/data/table/th/DataTableTh.js +24 -6
- package/cjs/data/table/th/DataTableTh.js.map +1 -1
- package/cjs/data/table/th/DataTableThActions.d.ts +5 -0
- package/cjs/data/table/th/DataTableThActions.js +23 -0
- package/cjs/data/table/th/DataTableThActions.js.map +1 -0
- package/cjs/data/table/th/DataTableThSortHandle.d.ts +6 -0
- package/cjs/data/table/th/DataTableThSortHandle.js +82 -0
- package/cjs/data/table/th/DataTableThSortHandle.js.map +1 -0
- package/cjs/tooltip/Tooltip.d.ts +1 -1
- package/cjs/tooltip/Tooltip.js +35 -2
- package/cjs/tooltip/Tooltip.js.map +1 -1
- package/cjs/utils/i18n/locales/en.d.ts +3 -0
- package/cjs/utils/i18n/locales/en.js +3 -0
- package/cjs/utils/i18n/locales/en.js.map +1 -1
- package/cjs/utils/i18n/locales/nb.d.ts +4 -0
- package/cjs/utils/i18n/locales/nb.js +4 -0
- package/cjs/utils/i18n/locales/nb.js.map +1 -1
- package/cjs/utils/i18n/locales/nn.d.ts +3 -0
- package/cjs/utils/i18n/locales/nn.js +3 -0
- package/cjs/utils/i18n/locales/nn.js.map +1 -1
- package/esm/data/stories/DataTableProfiler.d.ts +6 -0
- package/esm/data/stories/DataTableProfiler.js +89 -0
- package/esm/data/stories/DataTableProfiler.js.map +1 -0
- package/esm/data/stories/dummy-data.d.ts +2 -3
- package/esm/data/stories/dummy-data.js +30 -9
- package/esm/data/stories/dummy-data.js.map +1 -1
- package/esm/data/table/index.d.ts +2 -2
- package/esm/data/table/index.js +1 -1
- package/esm/data/table/index.js.map +1 -1
- package/esm/data/table/root/DataTableRoot.d.ts +15 -2
- package/esm/data/table/root/DataTableRoot.js +3 -1
- package/esm/data/table/root/DataTableRoot.js.map +1 -1
- package/esm/data/table/tfoot/DataTableTfoot.d.ts +5 -0
- package/esm/data/table/tfoot/DataTableTfoot.js +19 -0
- package/esm/data/table/tfoot/DataTableTfoot.js.map +1 -0
- package/esm/data/table/th/DataTableTh.d.ts +20 -4
- package/esm/data/table/th/DataTableTh.js +25 -7
- package/esm/data/table/th/DataTableTh.js.map +1 -1
- package/esm/data/table/th/DataTableThActions.d.ts +5 -0
- package/esm/data/table/th/DataTableThActions.js +18 -0
- package/esm/data/table/th/DataTableThActions.js.map +1 -0
- package/esm/data/table/th/DataTableThSortHandle.d.ts +6 -0
- package/esm/data/table/th/DataTableThSortHandle.js +47 -0
- package/esm/data/table/th/DataTableThSortHandle.js.map +1 -0
- package/esm/tooltip/Tooltip.d.ts +1 -1
- package/esm/tooltip/Tooltip.js +35 -2
- package/esm/tooltip/Tooltip.js.map +1 -1
- package/esm/utils/i18n/locales/en.d.ts +3 -0
- package/esm/utils/i18n/locales/en.js +3 -0
- package/esm/utils/i18n/locales/en.js.map +1 -1
- package/esm/utils/i18n/locales/nb.d.ts +4 -0
- package/esm/utils/i18n/locales/nb.js +4 -0
- package/esm/utils/i18n/locales/nb.js.map +1 -1
- package/esm/utils/i18n/locales/nn.d.ts +3 -0
- package/esm/utils/i18n/locales/nn.js +3 -0
- package/esm/utils/i18n/locales/nn.js.map +1 -1
- package/package.json +3 -3
- package/src/data/stories/DataTableProfiler.tsx +215 -0
- package/src/data/stories/dummy-data.tsx +39 -17
- package/src/data/table/index.tsx +2 -0
- package/src/data/table/root/DataTableRoot.tsx +19 -0
- package/src/data/table/tfoot/DataTableTfoot.tsx +21 -0
- package/src/data/table/th/DataTableTh.tsx +68 -31
- package/src/data/table/th/DataTableThActions.tsx +32 -0
- package/src/data/table/th/DataTableThSortHandle.tsx +67 -0
- package/src/tooltip/Tooltip.tsx +66 -11
- package/src/utils/i18n/locales/en.ts +3 -0
- package/src/utils/i18n/locales/nb.ts +3 -0
- 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 };
|
package/src/tooltip/Tooltip.tsx
CHANGED
|
@@ -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
|
|
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;
|