-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtable.tsx
More file actions
43 lines (42 loc) · 1.7 KB
/
Copy pathtable.tsx
File metadata and controls
43 lines (42 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { TableBody } from "@databiosphere/findable-ui/lib/components/Table/components/TableBody/tableBody";
import { TableHead } from "@databiosphere/findable-ui/lib/components/Table/components/TableHead/tableHead";
import { useVirtualization } from "@databiosphere/findable-ui/lib/components/Table/hooks/UseVirtualization/hook";
import { GridTable } from "@databiosphere/findable-ui/lib/components/Table/table.styles";
import { getColumnTrackSizing } from "@databiosphere/findable-ui/lib/components/TableCreator/options/columnTrackSizing/utils";
import { TableContainer } from "@mui/material";
import type { RowData } from "@tanstack/react-table";
import { JSX } from "react";
import { useRowDirection } from "./hooks/UseRowDirection/hook";
import type { Props } from "./types";
/**
* Renders a virtualized table for a TanStack Table instance, with responsive
* row direction (horizontal on default viewports, vertical on small viewports).
* @param props - Component props.
* @param props.table - Table instance.
* @returns Table component.
*/
export const Table = <T extends RowData>({ table }: Props<T>): JSX.Element => {
const { rowDirection } = useRowDirection();
const { rows, scrollElementRef, virtualizer } = useVirtualization({
rowDirection,
table,
});
return (
<TableContainer ref={scrollElementRef}>
<GridTable
gridTemplateColumns={getColumnTrackSizing(
table.getVisibleFlatColumns()
)}
collapsable
>
<TableHead tableInstance={table} />
<TableBody
rowDirection={rowDirection}
rows={rows}
tableInstance={table}
virtualizer={virtualizer}
/>
</GridTable>
</TableContainer>
);
};