lecom-ui 5.2.43 → 5.2.44
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.
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { cn } from '../../lib/utils.js';
|
|
3
|
-
import { getSortedRowModel, getCoreRowModel
|
|
3
|
+
import { useReactTable, getSortedRowModel, getCoreRowModel } from '@tanstack/react-table';
|
|
4
4
|
import { Pagination } from '../Pagination/Pagination.js';
|
|
5
5
|
import { ScrollArea, ScrollBar } from '../ScrollArea/ScrollArea.js';
|
|
6
6
|
import { buildColumns } from './DataTable.utils.js';
|
|
7
7
|
import { Table } from './Table.js';
|
|
8
|
-
import { useOptimizedTable } from './useOptimizedTable.js';
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
function DataTable({
|
|
11
10
|
isLoading,
|
|
12
11
|
columns,
|
|
13
12
|
data,
|
|
@@ -22,61 +21,90 @@ const DataTable = React.memo(function DataTable2({
|
|
|
22
21
|
onIsSelected
|
|
23
22
|
}) {
|
|
24
23
|
const [sorting, setSorting] = React.useState([]);
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
const table = useReactTable({
|
|
25
|
+
data,
|
|
26
|
+
columns: buildColumns({ columns, size }),
|
|
27
|
+
getCoreRowModel: getCoreRowModel(),
|
|
28
|
+
onSortingChange: setSorting,
|
|
29
|
+
getSortedRowModel: getSortedRowModel(),
|
|
30
|
+
state: {
|
|
31
|
+
sorting
|
|
32
|
+
}
|
|
28
33
|
});
|
|
29
|
-
const
|
|
30
|
-
()
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
sorting
|
|
38
|
-
}
|
|
39
|
-
}),
|
|
40
|
-
[data, columns, size, sorting]
|
|
41
|
-
);
|
|
42
|
-
const table = useReactTable(tableConfig);
|
|
43
|
-
const containerStyle = React.useMemo(
|
|
44
|
-
() => ({
|
|
45
|
-
width: vwDiff ? `calc(100vw - ${vwDiff}px)` : "100%",
|
|
46
|
-
height: vhDiff ? `calc(100vh - ${vhDiff}px)` : "100%"
|
|
47
|
-
}),
|
|
48
|
-
[vwDiff, vhDiff]
|
|
49
|
-
);
|
|
50
|
-
const paginationComponent = React.useMemo(() => {
|
|
51
|
-
if (!pagination) return null;
|
|
34
|
+
const styleDataTableContainer = () => ({
|
|
35
|
+
width: vwDiff ? `calc(100vw - ${vwDiff}px)` : "100%",
|
|
36
|
+
height: vhDiff ? `calc(100vh - ${vhDiff}px)` : "100%"
|
|
37
|
+
});
|
|
38
|
+
const hasPagination = () => {
|
|
39
|
+
if (!pagination) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
52
42
|
return /* @__PURE__ */ React.createElement(Pagination, { ...pagination });
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
()
|
|
56
|
-
|
|
57
|
-
{
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
43
|
+
};
|
|
44
|
+
React.useEffect(() => {
|
|
45
|
+
if (!isLoading) {
|
|
46
|
+
const listRows = document.querySelectorAll(`table#data-table tr`);
|
|
47
|
+
listRows.forEach((listRow, listRowIndex) => {
|
|
48
|
+
const rowsElem = listRow.querySelectorAll("[data-fixed]");
|
|
49
|
+
rowsElem.forEach((rowElem, rowElemIndex) => {
|
|
50
|
+
const beforeElem = rowsElem[rowElemIndex - 1];
|
|
51
|
+
const currentElem = rowElem;
|
|
52
|
+
const beforeElemWidth = beforeElem?.getBoundingClientRect()?.width ?? 0;
|
|
53
|
+
const beforeElemLeft = beforeElem?.style?.left ? Number(beforeElem.style.left.replace(/px/g, "")) : 0;
|
|
54
|
+
const lastColumnFixed = rowsElem.length - 1 === rowElemIndex;
|
|
55
|
+
const lastRow = listRows.length - 1 === listRowIndex;
|
|
56
|
+
const currentElemIsTh = currentElem.tagName === "TH";
|
|
57
|
+
const boxShadowWidth = currentElemIsTh ? "-1.5px" : "-0.5px";
|
|
58
|
+
const boxShadow = `#c9c9c9 0px ${lastRow ? "0px" : boxShadowWidth} 0px inset`;
|
|
59
|
+
currentElem.style.position = "sticky";
|
|
60
|
+
currentElem.style.left = `${beforeElemWidth + beforeElemLeft}px`;
|
|
61
|
+
currentElem.style.boxShadow = boxShadow;
|
|
62
|
+
if (lastColumnFixed) {
|
|
63
|
+
currentElem.setAttribute("data-separator-fixed", "true");
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}, [isLoading]);
|
|
69
|
+
const onScroll = (e) => {
|
|
70
|
+
const target = e.target;
|
|
71
|
+
const elemSeparator = document.querySelectorAll("[data-separator-fixed]");
|
|
72
|
+
const countSeparator = elemSeparator.length - 1;
|
|
73
|
+
if (target.scrollLeft > 0) {
|
|
74
|
+
elemSeparator.forEach((elem, i) => {
|
|
75
|
+
const separator = elem;
|
|
76
|
+
if (countSeparator === i) {
|
|
77
|
+
separator.style.boxShadow = "#c9c9c9 -0.5px 0px 0px inset";
|
|
78
|
+
} else {
|
|
79
|
+
separator.style.boxShadow = `#c9c9c9 -0.5px ${i === 0 ? "-1.5px" : "-0.5px"} 0px inset`;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
} else {
|
|
83
|
+
elemSeparator.forEach((elem, i) => {
|
|
84
|
+
const separator = elem;
|
|
85
|
+
if (i === 0) {
|
|
86
|
+
separator.style.boxShadow = "#c9c9c9 0px -1.5px 0px inset";
|
|
87
|
+
} else {
|
|
88
|
+
separator.style.boxShadow = `#c9c9c9 0px ${countSeparator === i ? "0px" : "-0.5px"} 0px inset`;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
React.useEffect(() => {
|
|
94
|
+
document.querySelector("[data-radix-scroll-area-viewport]")?.addEventListener("scroll", onScroll);
|
|
95
|
+
return () => document.querySelector("[data-radix-scroll-area-viewport]")?.removeEventListener("scroll", onScroll);
|
|
96
|
+
}, []);
|
|
97
|
+
const renderTable = () => /* @__PURE__ */ React.createElement(
|
|
98
|
+
Table,
|
|
99
|
+
{
|
|
71
100
|
table,
|
|
72
101
|
columns,
|
|
73
102
|
noResults,
|
|
74
103
|
onIsSelected,
|
|
75
104
|
isLoading,
|
|
76
105
|
size,
|
|
77
|
-
skeleton
|
|
78
|
-
|
|
79
|
-
]
|
|
106
|
+
skeleton
|
|
107
|
+
}
|
|
80
108
|
);
|
|
81
109
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
|
|
82
110
|
"div",
|
|
@@ -85,18 +113,18 @@ const DataTable = React.memo(function DataTable2({
|
|
|
85
113
|
"bg-white rounded-[8px] p-2 transition-all duration-500",
|
|
86
114
|
className
|
|
87
115
|
),
|
|
88
|
-
style: noScroll ? void 0 : { width:
|
|
116
|
+
style: noScroll ? void 0 : { width: styleDataTableContainer().width }
|
|
89
117
|
},
|
|
90
|
-
noScroll ?
|
|
118
|
+
noScroll ? renderTable() : /* @__PURE__ */ React.createElement(ScrollArea, { type: "always", className: "p-2" }, /* @__PURE__ */ React.createElement(
|
|
91
119
|
"div",
|
|
92
120
|
{
|
|
93
121
|
className: "transition-all duration-500",
|
|
94
|
-
style: { maxHeight:
|
|
122
|
+
style: { maxHeight: styleDataTableContainer().height }
|
|
95
123
|
},
|
|
96
|
-
|
|
124
|
+
renderTable()
|
|
97
125
|
), /* @__PURE__ */ React.createElement(ScrollBar, { orientation: "horizontal" }))
|
|
98
|
-
),
|
|
99
|
-
}
|
|
126
|
+
), hasPagination());
|
|
127
|
+
}
|
|
100
128
|
DataTable.displayName = "DataTable";
|
|
101
129
|
|
|
102
130
|
export { DataTable };
|
|
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { useTranslation } from 'react-i18next';
|
|
3
3
|
import { Button } from '../Button/Button.js';
|
|
4
4
|
import { cn } from '../../lib/utils.js';
|
|
5
|
-
import {
|
|
5
|
+
import { MoreHorizontal, ChevronRight, ChevronLeft, ChevronFirst, ChevronLast, ChevronDown } from 'lucide-react';
|
|
6
6
|
import { initializeI18n } from '../../i18n/index.js';
|
|
7
7
|
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem } from '../DropdownMenu/DropdownMenu.js';
|
|
8
8
|
import { Typography } from '../Typography/Typography.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -529,7 +529,10 @@ interface TableProps<TData, TValue> {
|
|
|
529
529
|
onIsSelected?: (row: Row$1<TData>) => boolean;
|
|
530
530
|
}
|
|
531
531
|
|
|
532
|
-
declare
|
|
532
|
+
declare function DataTable<TData, TValue>({ isLoading, columns, data, noResults, pagination, vwDiff, vhDiff, className, noScroll, size, skeleton, onIsSelected, }: DataTableProps<TData, TValue>): React$1.JSX.Element;
|
|
533
|
+
declare namespace DataTable {
|
|
534
|
+
var displayName: string;
|
|
535
|
+
}
|
|
533
536
|
|
|
534
537
|
interface DialogContentProps extends React$1.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> {
|
|
535
538
|
noClose?: boolean;
|
|
@@ -875,7 +878,7 @@ declare const RadioGroup: React$1.ForwardRefExoticComponent<Omit<RadioGroupPrimi
|
|
|
875
878
|
declare const RadioGroupItem: React$1.ForwardRefExoticComponent<Omit<RadioGroupPrimitive.RadioGroupItemProps & React$1.RefAttributes<HTMLButtonElement>, "ref"> & React$1.RefAttributes<HTMLButtonElement>>;
|
|
876
879
|
|
|
877
880
|
declare const ResizablePanelGroup: ({ className, ...props }: React$1.ComponentProps<typeof ResizablePrimitive.PanelGroup>) => React$1.JSX.Element;
|
|
878
|
-
declare const ResizablePanel: React$1.ForwardRefExoticComponent<Omit<React$1.HTMLAttributes<HTMLDivElement | HTMLElement | HTMLButtonElement | HTMLOListElement | HTMLLIElement | HTMLAnchorElement | HTMLSpanElement |
|
|
881
|
+
declare const ResizablePanel: React$1.ForwardRefExoticComponent<Omit<React$1.HTMLAttributes<HTMLDivElement | HTMLElement | HTMLButtonElement | HTMLOListElement | HTMLLIElement | HTMLAnchorElement | HTMLSpanElement | HTMLHeadingElement | HTMLParagraphElement | HTMLLabelElement | HTMLInputElement | HTMLUListElement | HTMLObjectElement | HTMLAreaElement | HTMLAudioElement | HTMLBaseElement | HTMLQuoteElement | HTMLBodyElement | HTMLBRElement | HTMLCanvasElement | HTMLTableCaptionElement | HTMLTableColElement | HTMLDataElement | HTMLDataListElement | HTMLModElement | HTMLDetailsElement | HTMLDialogElement | HTMLDListElement | HTMLEmbedElement | HTMLFieldSetElement | HTMLFormElement | HTMLHeadElement | HTMLHRElement | HTMLHtmlElement | HTMLIFrameElement | HTMLImageElement | HTMLLegendElement | HTMLLinkElement | HTMLMapElement | HTMLMenuElement | HTMLMetaElement | HTMLMeterElement | HTMLOptGroupElement | HTMLOptionElement | HTMLOutputElement | HTMLPictureElement | HTMLPreElement | HTMLProgressElement | HTMLScriptElement | HTMLSelectElement | HTMLSlotElement | HTMLSourceElement | HTMLStyleElement | HTMLTableElement | HTMLTableSectionElement | HTMLTableCellElement | HTMLTemplateElement | HTMLTextAreaElement | HTMLTimeElement | HTMLTitleElement | HTMLTableRowElement | HTMLTrackElement | HTMLVideoElement>, "id" | "onResize"> & {
|
|
879
882
|
className?: string;
|
|
880
883
|
collapsedSize?: number | undefined;
|
|
881
884
|
collapsible?: boolean | undefined;
|