@purpurds/table 6.12.4 → 7.0.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/dist/LICENSE.txt +16 -16
- package/dist/cell-types/body-text-cell.d.ts.map +1 -1
- package/dist/cell-types/link-cell.d.ts.map +1 -1
- package/dist/story-utils/column-def.d.ts.map +1 -1
- package/dist/story-utils/table-data.d.ts +2 -4
- package/dist/story-utils/table-data.d.ts.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/table-action-bar.d.ts.map +1 -1
- package/dist/table-export-drawer.d.ts +3 -2
- package/dist/table-export-drawer.d.ts.map +1 -1
- package/dist/table-row-cell.d.ts.map +1 -1
- package/dist/table-settings-drawer.d.ts +2 -1
- package/dist/table-settings-drawer.d.ts.map +1 -1
- package/dist/table-toolbar.d.ts +6 -4
- package/dist/table-toolbar.d.ts.map +1 -1
- package/dist/table.cjs.js +63 -63
- package/dist/table.cjs.js.map +1 -1
- package/dist/table.d.ts +2 -1
- package/dist/table.d.ts.map +1 -1
- package/dist/table.es.js +3930 -3932
- package/dist/table.es.js.map +1 -1
- package/dist/test-utils/helpers.d.ts +2 -1
- package/dist/test-utils/helpers.d.ts.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/use-truncated-hook.d.ts +3 -5
- package/dist/use-truncated-hook.d.ts.map +1 -1
- package/package.json +24 -24
- package/src/cell-types/body-text-cell.tsx +7 -8
- package/src/cell-types/link-cell.tsx +13 -6
- package/src/story-utils/column-def.ts +2 -0
- package/src/story-utils/table-data.tsx +10 -8
- package/src/table-action-bar.tsx +3 -2
- package/src/table-column-header-cell.tsx +16 -6
- package/src/table-export-drawer.test.tsx +1 -0
- package/src/table-export-drawer.tsx +5 -3
- package/src/table-kitchen-sink.test.tsx +5 -18
- package/src/table-row-cell.tsx +1 -30
- package/src/table-settings-drawer.test.tsx +4 -0
- package/src/table-settings-drawer.tsx +46 -41
- package/src/table-toolbar.test.tsx +3 -0
- package/src/table-toolbar.tsx +12 -7
- package/src/table.module.scss +27 -18
- package/src/table.stories.tsx +10 -9
- package/src/table.tsx +32 -26
- package/src/test-utils/helpers.ts +2 -1
- package/src/types.ts +1 -1
- package/src/use-truncated-hook.tsx +16 -60
|
@@ -1,66 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Cell, RowData } from "@tanstack/react-table";
|
|
1
|
+
import { useRef, useState } from "react";
|
|
3
2
|
|
|
4
|
-
const useTruncatedTooltip =
|
|
5
|
-
const divRef = useRef<HTMLParagraphElement>(null);
|
|
6
|
-
const [isTruncated, setIsTruncated] = useState(false);
|
|
7
|
-
const timeoutIdRef = useRef<NodeJS.Timeout | undefined>(undefined);
|
|
3
|
+
const useTruncatedTooltip = () => {
|
|
8
4
|
const [showPopover, setShowPopover] = useState(false);
|
|
9
|
-
|
|
10
|
-
const debounce = (func: (...args: unknown[]) => void, delay: number) => {
|
|
11
|
-
let timeoutId: NodeJS.Timeout;
|
|
12
|
-
const debouncedFunction = (...args: unknown[]) => {
|
|
13
|
-
clearTimeout(timeoutId);
|
|
14
|
-
timeoutId = setTimeout(() => func.apply(this, args), delay);
|
|
15
|
-
};
|
|
16
|
-
return {
|
|
17
|
-
debouncedFunction,
|
|
18
|
-
get timeoutId() {
|
|
19
|
-
return timeoutId;
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
if (!cell) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const { debouncedFunction: checkTruncation, timeoutId } = debounce(() => {
|
|
30
|
-
if (divRef.current && cell) {
|
|
31
|
-
const pEl = divRef.current.querySelector("p");
|
|
32
|
-
if (pEl) {
|
|
33
|
-
setIsTruncated(pEl.scrollWidth > cell.column.getSize());
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}, 100); // Adjust debounce delay as needed
|
|
37
|
-
|
|
38
|
-
checkTruncation();
|
|
39
|
-
timeoutIdRef.current = timeoutId;
|
|
40
|
-
|
|
41
|
-
return () => {
|
|
42
|
-
clearTimeout(timeoutIdRef.current);
|
|
43
|
-
};
|
|
44
|
-
}, [cell]);
|
|
45
|
-
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
if (divRef.current && cell) {
|
|
48
|
-
if (divRef.current.textContent) {
|
|
49
|
-
const pEl = divRef.current.querySelector("p");
|
|
50
|
-
if (pEl) {
|
|
51
|
-
setIsTruncated(pEl.scrollWidth > cell.column.getSize());
|
|
52
|
-
}
|
|
53
|
-
const aEl = divRef.current.querySelector("a");
|
|
54
|
-
if (aEl) {
|
|
55
|
-
setIsTruncated(aEl.scrollWidth > cell.column.getSize());
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}, [divRef, cell, isTruncated]);
|
|
5
|
+
const containerRef = useRef<HTMLDivElement | null>(null);
|
|
60
6
|
|
|
61
7
|
const onMouseEnter = () => {
|
|
62
|
-
if (
|
|
63
|
-
|
|
8
|
+
if (containerRef.current) {
|
|
9
|
+
const contentElement: HTMLLinkElement | HTMLParagraphElement | null =
|
|
10
|
+
containerRef.current.querySelector("a, p"); // Find "a" or "p" tag
|
|
11
|
+
if (contentElement) {
|
|
12
|
+
const containerWidth = containerRef.current.clientWidth;
|
|
13
|
+
const contentWidth =
|
|
14
|
+
contentElement.tagName.toLowerCase() === "a"
|
|
15
|
+
? contentElement.offsetWidth
|
|
16
|
+
: contentElement.scrollWidth;
|
|
17
|
+
|
|
18
|
+
setShowPopover(contentWidth > containerWidth);
|
|
19
|
+
}
|
|
64
20
|
}
|
|
65
21
|
};
|
|
66
22
|
|
|
@@ -68,7 +24,7 @@ const useTruncatedTooltip = <TData extends RowData>(cell: Cell<TData, unknown> |
|
|
|
68
24
|
setShowPopover(false);
|
|
69
25
|
};
|
|
70
26
|
|
|
71
|
-
return {
|
|
27
|
+
return { showPopover, containerRef, onMouseEnter, onMouseLeave };
|
|
72
28
|
};
|
|
73
29
|
|
|
74
30
|
export default useTruncatedTooltip;
|