@navikt/ds-react 7.8.0 → 7.8.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.
- package/cjs/form/combobox/ComboboxWrapper.js +0 -1
- package/cjs/form/combobox/ComboboxWrapper.js.map +1 -1
- package/cjs/form/combobox/Input/Input.js +9 -9
- package/cjs/form/combobox/Input/Input.js.map +1 -1
- package/cjs/form/combobox/Input/InputController.js +8 -2
- package/cjs/form/combobox/Input/InputController.js.map +1 -1
- package/cjs/form/combobox/SelectedOptions/selectedOptionsContext.js +5 -0
- package/cjs/form/combobox/SelectedOptions/selectedOptionsContext.js.map +1 -1
- package/cjs/form/search/Search.d.ts +1 -1
- package/cjs/form/search/Search.js +1 -1
- package/cjs/layout/box/Box.d.ts +3 -2
- package/cjs/layout/box/Box.darkside.d.ts +10 -6
- package/cjs/layout/box/Box.darkside.js.map +1 -1
- package/cjs/layout/box/Box.js.map +1 -1
- package/cjs/layout/utilities/types.d.ts +7 -23
- package/cjs/tag/Tag.d.ts +1 -1
- package/cjs/tag/Tag.js +4 -1
- package/cjs/tag/Tag.js.map +1 -1
- package/cjs/timeline/Pin.js +5 -2
- package/cjs/timeline/Pin.js.map +1 -1
- package/cjs/timeline/hooks/useTimelineRows.d.ts +5 -1
- package/cjs/timeline/hooks/useTimelineRows.js +14 -3
- package/cjs/timeline/hooks/useTimelineRows.js.map +1 -1
- package/cjs/timeline/period/ClickablePeriod.js +5 -2
- package/cjs/timeline/period/ClickablePeriod.js.map +1 -1
- package/cjs/tooltip/Tooltip.js +6 -3
- package/cjs/tooltip/Tooltip.js.map +1 -1
- package/esm/form/combobox/ComboboxWrapper.js +0 -1
- package/esm/form/combobox/ComboboxWrapper.js.map +1 -1
- package/esm/form/combobox/Input/Input.js +9 -9
- package/esm/form/combobox/Input/Input.js.map +1 -1
- package/esm/form/combobox/Input/InputController.js +8 -2
- package/esm/form/combobox/Input/InputController.js.map +1 -1
- package/esm/form/combobox/SelectedOptions/selectedOptionsContext.js +5 -0
- package/esm/form/combobox/SelectedOptions/selectedOptionsContext.js.map +1 -1
- package/esm/form/search/Search.d.ts +1 -1
- package/esm/form/search/Search.js +1 -1
- package/esm/layout/box/Box.d.ts +3 -2
- package/esm/layout/box/Box.darkside.d.ts +10 -6
- package/esm/layout/box/Box.darkside.js.map +1 -1
- package/esm/layout/box/Box.js.map +1 -1
- package/esm/layout/utilities/types.d.ts +7 -23
- package/esm/tag/Tag.d.ts +1 -1
- package/esm/tag/Tag.js +4 -1
- package/esm/tag/Tag.js.map +1 -1
- package/esm/timeline/Pin.js +5 -2
- package/esm/timeline/Pin.js.map +1 -1
- package/esm/timeline/hooks/useTimelineRows.d.ts +5 -1
- package/esm/timeline/hooks/useTimelineRows.js +14 -3
- package/esm/timeline/hooks/useTimelineRows.js.map +1 -1
- package/esm/timeline/period/ClickablePeriod.js +5 -2
- package/esm/timeline/period/ClickablePeriod.js.map +1 -1
- package/esm/tooltip/Tooltip.js +6 -3
- package/esm/tooltip/Tooltip.js.map +1 -1
- package/package.json +4 -4
- package/src/form/combobox/ComboboxWrapper.tsx +0 -1
- package/src/form/combobox/Input/Input.tsx +9 -9
- package/src/form/combobox/Input/InputController.tsx +10 -2
- package/src/form/combobox/SelectedOptions/selectedOptionsContext.tsx +4 -0
- package/src/form/search/Search.tsx +1 -1
- package/src/layout/box/Box.darkside.tsx +19 -14
- package/src/layout/box/Box.tsx +4 -2
- package/src/layout/utilities/types.ts +20 -42
- package/src/tag/Tag.tsx +32 -18
- package/src/timeline/Pin.tsx +16 -10
- package/src/timeline/hooks/useTimelineRows.ts +25 -9
- package/src/timeline/period/ClickablePeriod.tsx +16 -10
- package/src/timeline/tests/useTimelineRows.test.ts +131 -0
- package/src/tooltip/Tooltip.tsx +7 -2
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { renderHook } from "@testing-library/react";
|
|
2
|
+
import { addDays, isSameDay } from "date-fns";
|
|
3
|
+
import { describe, expect, test } from "vitest";
|
|
4
|
+
import {
|
|
5
|
+
useEarliestDate,
|
|
6
|
+
useLatestDate,
|
|
7
|
+
useTimelineRows,
|
|
8
|
+
} from "../hooks/useTimelineRows";
|
|
9
|
+
|
|
10
|
+
describe("useEarliestDate", () => {
|
|
11
|
+
test("returns the provided startDate if it exists", () => {
|
|
12
|
+
const startDate = new Date(2023, 0, 1);
|
|
13
|
+
const { result } = renderHook(() =>
|
|
14
|
+
useEarliestDate({ startDate, rows: [] }),
|
|
15
|
+
);
|
|
16
|
+
expect(result.current).toEqual(startDate);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("returns the earliest date from the rows if startDate is not provided", () => {
|
|
20
|
+
const rows = [
|
|
21
|
+
[{ start: new Date(2023, 0, 1) }],
|
|
22
|
+
[{ start: new Date(2022, 0, 1) }],
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const { result } = renderHook(() => useEarliestDate({ rows }));
|
|
26
|
+
expect(result.current).toEqual(new Date(2022, 0, 1));
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("returns the earliest date from the rows if startDate is not provided and date is later than todays date", () => {
|
|
30
|
+
const earliestDate = addDays(new Date(), 400);
|
|
31
|
+
const rows = [
|
|
32
|
+
[{ start: earliestDate }],
|
|
33
|
+
[{ start: addDays(earliestDate, 40) }],
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
const { result } = renderHook(() => useEarliestDate({ rows }));
|
|
37
|
+
expect(result.current).toEqual(earliestDate);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("returns the current date if no startDate and rows are empty", () => {
|
|
41
|
+
const { result } = renderHook(() => useEarliestDate({ rows: [] }));
|
|
42
|
+
expect(isSameDay(result.current, new Date())).toBeTruthy();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe("useLatestDate", () => {
|
|
47
|
+
test("returns the provided endDate if it exists", () => {
|
|
48
|
+
const endDate = new Date(2023, 0, 1);
|
|
49
|
+
const { result } = renderHook(() => useLatestDate({ endDate, rows: [] }));
|
|
50
|
+
expect(result.current).toEqual(endDate);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("returns the latest date from the rows plus one day if endDate is not provided", () => {
|
|
54
|
+
const rows = [
|
|
55
|
+
[{ start: new Date(2023, 0, 1), end: new Date(2023, 0, 10) }],
|
|
56
|
+
[{ start: new Date(2022, 0, 1), end: new Date(2022, 0, 5) }],
|
|
57
|
+
];
|
|
58
|
+
const { result } = renderHook(() => useLatestDate({ rows }));
|
|
59
|
+
expect(result.current).toEqual(addDays(new Date(2023, 0, 10), 1));
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("returns the current date plus one day if no endDate and rows are empty", () => {
|
|
63
|
+
const { result } = renderHook(() => useLatestDate({ rows: [] }));
|
|
64
|
+
expect(result.current).toEqual(addDays(new Date(0), 1));
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe("useTimelineRows", () => {
|
|
69
|
+
const rows = [
|
|
70
|
+
{
|
|
71
|
+
label: "Row 1",
|
|
72
|
+
periods: [
|
|
73
|
+
{
|
|
74
|
+
start: new Date(2023, 0, 1),
|
|
75
|
+
end: new Date(2023, 0, 10),
|
|
76
|
+
status: "active",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
start: new Date(2023, 0, 15),
|
|
80
|
+
end: new Date(2023, 0, 20),
|
|
81
|
+
status: "inactive",
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
label: "Row 2",
|
|
87
|
+
periods: [
|
|
88
|
+
{
|
|
89
|
+
start: new Date(2022, 0, 1),
|
|
90
|
+
end: new Date(2022, 0, 5),
|
|
91
|
+
status: "active",
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
test("returns the correct timeline rows", () => {
|
|
98
|
+
const startDate = new Date(2022, 0, 1);
|
|
99
|
+
const endDate = new Date(2023, 0, 31);
|
|
100
|
+
const direction = "left";
|
|
101
|
+
const { result } = renderHook(() =>
|
|
102
|
+
useTimelineRows(rows, startDate, endDate, direction),
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
expect(result.current).toHaveLength(2);
|
|
106
|
+
expect(result.current[0].periods).toHaveLength(2);
|
|
107
|
+
expect(result.current[1].periods).toHaveLength(1);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("handles empty rows", () => {
|
|
111
|
+
const startDate = new Date(2022, 0, 1);
|
|
112
|
+
const endDate = new Date(2023, 0, 31);
|
|
113
|
+
const direction = "left";
|
|
114
|
+
const { result } = renderHook(() =>
|
|
115
|
+
useTimelineRows([], startDate, endDate, direction),
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
expect(result.current).toHaveLength(0);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("handles different directions", () => {
|
|
122
|
+
const startDate = new Date(2022, 0, 1);
|
|
123
|
+
const endDate = new Date(2023, 0, 31);
|
|
124
|
+
const direction = "right";
|
|
125
|
+
const { result } = renderHook(() =>
|
|
126
|
+
useTimelineRows(rows, startDate, endDate, direction),
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
expect(result.current[0].periods[0].start).toEqual(new Date(2023, 0, 15));
|
|
130
|
+
});
|
|
131
|
+
});
|
package/src/tooltip/Tooltip.tsx
CHANGED
|
@@ -15,6 +15,7 @@ import cl from "clsx";
|
|
|
15
15
|
import React, { HTMLAttributes, forwardRef, useRef } from "react";
|
|
16
16
|
import { useModalContext } from "../modal/Modal.context";
|
|
17
17
|
import { Portal } from "../portal";
|
|
18
|
+
import { UNSAFE_useAkselTheme } from "../provider";
|
|
18
19
|
import { Slot } from "../slot/Slot";
|
|
19
20
|
import { Detail } from "../typography";
|
|
20
21
|
import { useId } from "../util/hooks";
|
|
@@ -123,6 +124,9 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
|
|
|
123
124
|
},
|
|
124
125
|
ref,
|
|
125
126
|
) => {
|
|
127
|
+
const themeContext = UNSAFE_useAkselTheme(false);
|
|
128
|
+
const showArrow = _arrow && !themeContext;
|
|
129
|
+
|
|
126
130
|
const [_open, _setOpen] = useControllableState({
|
|
127
131
|
defaultValue: defaultOpen,
|
|
128
132
|
value: open,
|
|
@@ -149,7 +153,7 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
|
|
|
149
153
|
open: _open,
|
|
150
154
|
onOpenChange: (newState) => _setOpen(newState),
|
|
151
155
|
middleware: [
|
|
152
|
-
offset(_offset ?
|
|
156
|
+
offset(_offset ?? (themeContext ? 8 : _arrow ? 16 : 4)),
|
|
153
157
|
shift(),
|
|
154
158
|
flip({ padding: 5, fallbackPlacements: ["bottom", "top"] }),
|
|
155
159
|
flArrow({ element: arrowRef, padding: 5 }),
|
|
@@ -228,6 +232,7 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
|
|
|
228
232
|
),
|
|
229
233
|
})}
|
|
230
234
|
data-side={placement}
|
|
235
|
+
data-state="open"
|
|
231
236
|
>
|
|
232
237
|
{content}
|
|
233
238
|
{keys && (
|
|
@@ -239,7 +244,7 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
|
|
|
239
244
|
))}
|
|
240
245
|
</span>
|
|
241
246
|
)}
|
|
242
|
-
{
|
|
247
|
+
{showArrow && (
|
|
243
248
|
<div
|
|
244
249
|
ref={(node) => {
|
|
245
250
|
arrowRef.current = node;
|