rez-table-listing-mui 0.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.
Files changed (65) hide show
  1. package/.eslintrc.cjs +18 -0
  2. package/README.md +164 -0
  3. package/dist/index.d.ts +90 -0
  4. package/dist/index.js +1 -0
  5. package/dist/index.mjs +1 -0
  6. package/index.html +13 -0
  7. package/package.json +64 -0
  8. package/public/vite.svg +1 -0
  9. package/rollup.config.js +42 -0
  10. package/src/App.tsx +153 -0
  11. package/src/assets/svg.tsx +833 -0
  12. package/src/components/columm-visibility-modal/column-list-item.tsx +44 -0
  13. package/src/components/columm-visibility-modal/index.scss +72 -0
  14. package/src/components/columm-visibility-modal/index.tsx +175 -0
  15. package/src/components/common/index.scss +11 -0
  16. package/src/components/common/index.tsx +11 -0
  17. package/src/components/dropdown/index.scss +17 -0
  18. package/src/components/dropdown/index.tsx +27 -0
  19. package/src/components/index-table.tsx +266 -0
  20. package/src/components/index.scss +176 -0
  21. package/src/components/inputs/checkbox/index.tsx +58 -0
  22. package/src/components/inputs/index.scss +63 -0
  23. package/src/components/inputs/switch.tsx +14 -0
  24. package/src/components/nestedcomponent/index.scss +14 -0
  25. package/src/components/nestedcomponent/index.tsx +53 -0
  26. package/src/components/pagination/default/index.scss +76 -0
  27. package/src/components/pagination/default/index.tsx +168 -0
  28. package/src/components/sorting-modal.tsx/index.tsx +200 -0
  29. package/src/components/sorting-modal.tsx/sorting-item.tsx +35 -0
  30. package/src/components/table-body-dnd-cell.tsx +50 -0
  31. package/src/components/table-body.tsx +109 -0
  32. package/src/components/table-change-layout.tsx +106 -0
  33. package/src/components/table-dnd.tsx +62 -0
  34. package/src/components/table-head-dnd-cell.tsx +144 -0
  35. package/src/components/table-head-pin.tsx +16 -0
  36. package/src/components/table-head-popover.tsx +85 -0
  37. package/src/components/table-head.tsx +156 -0
  38. package/src/components/table.tsx +38 -0
  39. package/src/components/tabs/index.scss +41 -0
  40. package/src/components/tabs/index.tsx +132 -0
  41. package/src/components/topbar/index.scss +84 -0
  42. package/src/components/topbar/index.tsx +226 -0
  43. package/src/components/viewmore/index.scss +0 -0
  44. package/src/components/viewmore/index.tsx +171 -0
  45. package/src/index.ts +4 -0
  46. package/src/libs/hooks/useCraftTable.tsx +37 -0
  47. package/src/libs/hooks/useDefaultColumns.tsx +96 -0
  48. package/src/libs/hooks/useFullScreen.tsx +25 -0
  49. package/src/libs/hooks/useOutsideClick.tsx +24 -0
  50. package/src/libs/utils/Data-format.ts +18 -0
  51. package/src/libs/utils/amount-format.ts +70 -0
  52. package/src/libs/utils/common.ts +62 -0
  53. package/src/libs/utils/date-format.ts +6 -0
  54. package/src/libs/utils/make-data.ts +79 -0
  55. package/src/libs/utils/make-hierar-data.ts +51 -0
  56. package/src/libs/utils/make-nested-data.ts +86 -0
  57. package/src/libs/utils/rows-data.ts +251 -0
  58. package/src/main.tsx +9 -0
  59. package/src/types/common.ts +30 -0
  60. package/src/types/table-options.ts +38 -0
  61. package/src/types/table.ts +65 -0
  62. package/src/vite-env.d.ts +1 -0
  63. package/tsconfig.json +25 -0
  64. package/tsconfig.node.json +11 -0
  65. package/vite.config.ts +7 -0
@@ -0,0 +1,200 @@
1
+ import { useState } from "react";
2
+ import {
3
+ Popover,
4
+ Box,
5
+ IconButton,
6
+ MenuItem,
7
+ Select,
8
+ Typography,
9
+ Button,
10
+ } from "@mui/material";
11
+ import {
12
+ DndContext,
13
+ closestCenter,
14
+ useSensor,
15
+ useSensors,
16
+ MouseSensor,
17
+ TouchSensor,
18
+ KeyboardSensor,
19
+ } from "@dnd-kit/core";
20
+ import {
21
+ arrayMove,
22
+ SortableContext,
23
+ verticalListSortingStrategy,
24
+ } from "@dnd-kit/sortable";
25
+ import SortableItem from "./sorting-item";
26
+ import { AddIcon, CloseIcon } from "../../assets/svg";
27
+
28
+ interface SortItem {
29
+ id: string;
30
+ field: string;
31
+ direction: "asc" | "desc";
32
+ }
33
+
34
+ type SortPopoverProps = {
35
+ anchorEl: HTMLElement | null;
36
+ onClose: () => void;
37
+ columns: { id: string; label: string }[];
38
+ onChange: (sorting: { id: string; desc: boolean }[]) => void;
39
+ };
40
+
41
+ const SortPopover = ({
42
+ anchorEl,
43
+ onClose,
44
+ columns,
45
+ onChange,
46
+ }: SortPopoverProps) => {
47
+ const [sorts, setSorts] = useState<SortItem[]>([]);
48
+
49
+ const sensors = useSensors(
50
+ useSensor(MouseSensor),
51
+ useSensor(TouchSensor),
52
+ useSensor(KeyboardSensor)
53
+ );
54
+
55
+ const handleDragEnd = (event: any) => {
56
+ const { active, over } = event;
57
+ if (active.id !== over.id) {
58
+ const oldIndex = sorts.findIndex((item) => item.id === active.id);
59
+ const newIndex = sorts.findIndex((item) => item.id === over.id);
60
+ const updated = arrayMove(sorts, oldIndex, newIndex);
61
+ setSorts(updated);
62
+ triggerTableSortUpdate(updated);
63
+ }
64
+ };
65
+
66
+ const handleChange = (id: string, field: keyof SortItem, value: any) => {
67
+ const updated = sorts.map((item) =>
68
+ item.id === id ? { ...item, [field]: value } : item
69
+ );
70
+ setSorts(updated);
71
+ triggerTableSortUpdate(updated);
72
+ };
73
+
74
+ const handleAddSort = () => {
75
+ const newSort: SortItem = {
76
+ id: Date.now().toString(),
77
+ field: columns[0]?.id ?? "",
78
+ direction: "asc",
79
+ };
80
+ const updated = [...sorts, newSort];
81
+ setSorts(updated);
82
+ triggerTableSortUpdate(updated);
83
+ };
84
+
85
+ const handleRemove = (id: string) => {
86
+ const updated = sorts.filter((item) => item.id !== id);
87
+ setSorts(updated);
88
+ triggerTableSortUpdate(updated);
89
+ };
90
+
91
+ const triggerTableSortUpdate = (sortItems: SortItem[]) => {
92
+ const sortingPayload = sortItems.map((item) => ({
93
+ id: item.field,
94
+ desc: item.direction === "desc",
95
+ }));
96
+ onChange(sortingPayload);
97
+ };
98
+
99
+ return (
100
+ <Popover
101
+ open={Boolean(anchorEl)}
102
+ anchorEl={anchorEl}
103
+ onClose={onClose}
104
+ anchorOrigin={{ vertical: "bottom", horizontal: "left" }}
105
+ >
106
+ <Box p={2} minWidth={300}>
107
+ <Box
108
+ display="flex"
109
+ justifyContent="space-between"
110
+ alignItems="center"
111
+ px={2}
112
+ py={1}
113
+ sx={{
114
+ backgroundColor: "#F9FAFB",
115
+ // borderBottom: "1px solid #E0E0E0",
116
+ margin: "-16px -16px 16px -16px",
117
+ }}
118
+ >
119
+ <Typography fontSize="18px" fontWeight={600} color="#0C2033">
120
+ Sort By
121
+ </Typography>
122
+ <IconButton size="small" onClick={onClose}>
123
+ <CloseIcon />
124
+ </IconButton>
125
+ </Box>
126
+
127
+ {sorts.length > 0 && (
128
+ <DndContext
129
+ sensors={sensors}
130
+ collisionDetection={closestCenter}
131
+ onDragEnd={handleDragEnd}
132
+ >
133
+ <SortableContext
134
+ items={sorts.map((s) => s.id)}
135
+ strategy={verticalListSortingStrategy}
136
+ >
137
+ {sorts.map((sort) => (
138
+ <SortableItem key={sort.id} id={sort.id}>
139
+ <Box display="flex" gap={1} alignItems="center" mb={1}>
140
+ <Select
141
+ value={sort.field}
142
+ onChange={(e) =>
143
+ handleChange(sort.id, "field", e.target.value)
144
+ }
145
+ size="small"
146
+ fullWidth
147
+ sx={{ fontWeight: 400, fontSize: 14, color: "#000" }}
148
+ >
149
+ {columns.map((col) => (
150
+ <MenuItem key={col.id} value={col.id}>
151
+ {col.label}
152
+ </MenuItem>
153
+ ))}
154
+ </Select>
155
+ <Select
156
+ value={sort.direction}
157
+ onChange={(e) =>
158
+ handleChange(sort.id, "direction", e.target.value)
159
+ }
160
+ size="small"
161
+ sx={{ fontWeight: 400, fontSize: 14, color: "#000" }}
162
+ >
163
+ <MenuItem value="asc">Ascending</MenuItem>
164
+ <MenuItem value="desc">Descending</MenuItem>
165
+ </Select>
166
+ <IconButton
167
+ size="small"
168
+ onClick={() => handleRemove(sort.id)}
169
+ >
170
+ <CloseIcon />
171
+ </IconButton>
172
+ </Box>
173
+ </SortableItem>
174
+ ))}
175
+ </SortableContext>
176
+ </DndContext>
177
+ )}
178
+
179
+ <Button
180
+ onClick={handleAddSort}
181
+ startIcon={
182
+ <span>
183
+ <AddIcon />
184
+ </span>
185
+ }
186
+ size="small"
187
+ sx={{
188
+ fontWeight: 400,
189
+ fontSize: 12,
190
+ color: "#888888",
191
+ }}
192
+ >
193
+ Add Sort
194
+ </Button>
195
+ </Box>
196
+ </Popover>
197
+ );
198
+ };
199
+
200
+ export default SortPopover;
@@ -0,0 +1,35 @@
1
+ import React from "react";
2
+ import { useSortable } from "@dnd-kit/sortable";
3
+ import { CSS } from "@dnd-kit/utilities";
4
+ import { DragHandleIcon } from "../../assets/svg";
5
+
6
+ const SortableItem = ({
7
+ id,
8
+ children,
9
+ }: {
10
+ id: string;
11
+ children: React.ReactNode;
12
+ }) => {
13
+ const { attributes, listeners, setNodeRef, transform, transition } =
14
+ useSortable({ id });
15
+
16
+ return (
17
+ <div
18
+ ref={setNodeRef}
19
+ style={{
20
+ transform: CSS.Transform.toString(transform),
21
+ transition,
22
+ display: "flex",
23
+ alignItems: "center",
24
+ gap: 8,
25
+ }}
26
+ >
27
+ <span {...attributes} {...listeners} style={{ cursor: "grab" }}>
28
+ <DragHandleIcon />
29
+ </span>
30
+ <div style={{ flexGrow: 1 }}>{children}</div>
31
+ </div>
32
+ );
33
+ };
34
+
35
+ export default SortableItem;
@@ -0,0 +1,50 @@
1
+ import { useSortable } from "@dnd-kit/sortable";
2
+ import { CSS } from "@dnd-kit/utilities";
3
+ import { Cell, flexRender } from "@tanstack/react-table";
4
+ import { CSSProperties } from "react";
5
+ import { align } from "../types/common";
6
+ import { getColumnPinningStylesBody } from "../libs/utils/common";
7
+ import { CraftTableFeatureProps } from "../types/table-options";
8
+
9
+ interface DragAlongCellProps<T> {
10
+ cell: Cell<T, unknown>;
11
+ featureOptions: CraftTableFeatureProps;
12
+ }
13
+
14
+ function DragAlongCell<T>({ cell, featureOptions }: DragAlongCellProps<T>) {
15
+ const { isDragging, setNodeRef, transform } = useSortable({
16
+ id: cell.column.id,
17
+ });
18
+ const { enableWordBreakAll } = featureOptions;
19
+
20
+ const isPinned = cell.column.getIsPinned();
21
+
22
+ const style: CSSProperties = {
23
+ opacity: isDragging ? 0.8 : 1,
24
+ transform: CSS.Translate.toString(transform),
25
+ transition: "width transform 0.2s ease-in-out",
26
+ width: cell.column.getSize(),
27
+ ...getColumnPinningStylesBody(cell.column),
28
+ ...(enableWordBreakAll && { wordBreak: "break-all" }),
29
+ };
30
+
31
+ return (
32
+ <td
33
+ ref={setNodeRef}
34
+ {...{
35
+ style: {
36
+ ...style,
37
+ zIndex: isPinned ? 2 : isDragging ? 1 : 0,
38
+ },
39
+ align: (cell.column.columnDef.meta as align)?.align || "left",
40
+ className: "ts__body__td",
41
+ }}
42
+ >
43
+ {cell.getIsPlaceholder()
44
+ ? null
45
+ : flexRender(cell.column.columnDef.cell, cell.getContext())}
46
+ </td>
47
+ );
48
+ }
49
+
50
+ export default DragAlongCell;
@@ -0,0 +1,109 @@
1
+ import React from "react";
2
+ import {
3
+ ColumnOrderState,
4
+ flexRender,
5
+ Row,
6
+ Table,
7
+ } from "@tanstack/react-table";
8
+ import { CraftTableFeatureProps } from "../types/table-options";
9
+ import { align } from "../types/common";
10
+ import DragAlongCell from "./table-body-dnd-cell";
11
+ import {
12
+ horizontalListSortingStrategy,
13
+ SortableContext,
14
+ } from "@dnd-kit/sortable";
15
+ import { getColumnPinningStylesBody } from "../libs/utils/common";
16
+ import Checkbox from "./inputs/checkbox";
17
+
18
+ interface TableBodyProps<T> {
19
+ table: Table<T>;
20
+ featureOptions: CraftTableFeatureProps;
21
+ NestedComponent?: React.ComponentType<{ row: Row<T> }>;
22
+ columnOrder: ColumnOrderState;
23
+ }
24
+
25
+ function TableBody<T>({
26
+ table,
27
+ featureOptions,
28
+ NestedComponent,
29
+ columnOrder,
30
+ }: TableBodyProps<T>) {
31
+ const { enableWordBreakAll, enableColumnReordering, enableRowSelection } =
32
+ featureOptions;
33
+
34
+ const renderRow = (row: Row<T>) => {
35
+ const renderedRow = (
36
+ <tr key={row.id} className="ts__body__tr">
37
+ {enableRowSelection && (
38
+ <td
39
+ className="ts__body__td ts__body__checkbox"
40
+ style={{
41
+ position: "sticky",
42
+ left: 0,
43
+ width: "50px",
44
+ }}
45
+ >
46
+ <Checkbox
47
+ checked={row.getIsSelected()}
48
+ indeterminate={row.getIsSomeSelected()}
49
+ onChange={row.getToggleSelectedHandler()}
50
+ className="checkbox__input"
51
+ />
52
+ </td>
53
+ )}
54
+
55
+ {row?.getVisibleCells()?.map((cell) => {
56
+ const tdProps = {
57
+ className: "ts__body__td",
58
+ style: {
59
+ ...getColumnPinningStylesBody(cell.column),
60
+ width: cell.column.getSize(),
61
+ ...(enableWordBreakAll && { wordBreak: "break-all" }),
62
+ } as React.CSSProperties,
63
+ align: (cell.column.columnDef.meta as align)?.align || "left",
64
+ };
65
+
66
+ return enableColumnReordering ? (
67
+ <SortableContext
68
+ key={cell.id}
69
+ items={columnOrder}
70
+ strategy={horizontalListSortingStrategy}
71
+ >
72
+ <DragAlongCell cell={cell} featureOptions={featureOptions} />
73
+ </SortableContext>
74
+ ) : (
75
+ <td key={cell?.id} {...tdProps}>
76
+ {flexRender(cell?.column?.columnDef?.cell, cell?.getContext())}
77
+ </td>
78
+ );
79
+ })}
80
+ </tr>
81
+ );
82
+
83
+ if (row.getIsExpanded()) {
84
+ return (
85
+ console.log("row.getIsExpanded() in table-head", row.getIsExpanded()),
86
+ (
87
+ <React.Fragment key={row.id}>
88
+ {renderedRow}
89
+ <tr>
90
+ <td colSpan={table.getAllLeafColumns().length}>
91
+ {NestedComponent && <NestedComponent {...{ row }} />}
92
+ </td>
93
+ </tr>
94
+ </React.Fragment>
95
+ )
96
+ );
97
+ } else {
98
+ return renderedRow;
99
+ }
100
+ };
101
+
102
+ return (
103
+ <tbody className="ts__body">
104
+ {table?.getRowModel()?.rows?.map((row) => renderRow(row))}
105
+ </tbody>
106
+ );
107
+ }
108
+
109
+ export default TableBody;
@@ -0,0 +1,106 @@
1
+ import {
2
+ BoardIcon,
3
+ CalendarIcon,
4
+ ChartsIcon,
5
+ CloseIcon,
6
+ GalleryIcon,
7
+ ListIcon,
8
+ TableIcon,
9
+ TimeLineIcon,
10
+ } from "../assets/svg";
11
+ import { Box, Typography, ButtonBase, Grid, IconButton } from "@mui/material";
12
+
13
+ interface LayoutSelectorProps {
14
+ onSelect: (layout: string) => void;
15
+ selectedLayout?: string;
16
+ }
17
+
18
+ const layoutIcons: Record<string, JSX.Element> = {
19
+ Board: <BoardIcon />,
20
+ Table: <TableIcon />,
21
+ Timeline: <TimeLineIcon />,
22
+ List: <ListIcon />,
23
+ Calendar: <CalendarIcon />,
24
+ Gallery: <GalleryIcon />,
25
+ Charts: <ChartsIcon />,
26
+ };
27
+
28
+ const LayoutSelector = ({ onSelect, selectedLayout }: LayoutSelectorProps) => {
29
+ return (
30
+ <Box
31
+ sx={{
32
+ width: "100%",
33
+ maxWidth: "500px",
34
+ height: "330px",
35
+ // backgroundColor: "#fff",
36
+ // borderRadius: 2,
37
+ // overflow: "hidden",
38
+ }}
39
+ >
40
+ <Box
41
+ sx={{
42
+ display: "flex",
43
+ justifyContent: "space-between",
44
+ alignItems: "center",
45
+ px: 3,
46
+ py: 2,
47
+ // borderBottom: "1px solid #eee",
48
+ backgroundColor: "#FBFBFC",
49
+ }}
50
+ >
51
+ <Typography
52
+ variant="h5"
53
+ sx={{ fontWeight: 400, fontSize: 18, color: "#0C2033" }}
54
+ >
55
+ Layouts
56
+ </Typography>
57
+ <IconButton onClick={() => onSelect("close")}>
58
+ <CloseIcon />
59
+ </IconButton>
60
+ </Box>
61
+
62
+ {/* Layout Grid */}
63
+ <Grid container spacing={2} sx={{ p: 3 }}>
64
+ {Object.keys(layoutIcons).map((layout) => {
65
+ const isSelected = layout === selectedLayout;
66
+ return (
67
+ <Grid size={3} key={layout}>
68
+ <ButtonBase
69
+ onClick={() => onSelect(layout)}
70
+ sx={{
71
+ border: isSelected
72
+ ? "1.5px solid #1E1E1E"
73
+ : "1.5px solid #E5E7EB",
74
+ borderRadius: 2,
75
+ p: 2,
76
+ width: "100%",
77
+ height: "100%",
78
+ flexDirection: "column",
79
+ backgroundColor: isSelected ? "#fff" : "",
80
+ transition: "0.3s",
81
+ boxShadow: isSelected
82
+ ? "0px 2px 6px rgba(0,0,0,0.06)"
83
+ : "none",
84
+ }}
85
+ >
86
+ <Box mb={1}>{layoutIcons[layout]}</Box>
87
+ <Typography
88
+ variant="subtitle1"
89
+ sx={{
90
+ color: "#1E1E1E",
91
+ fontWeight: isSelected ? 400 : 200,
92
+ opacity: isSelected ? 1 : 0.5,
93
+ }}
94
+ >
95
+ {layout}
96
+ </Typography>
97
+ </ButtonBase>
98
+ </Grid>
99
+ );
100
+ })}
101
+ </Grid>
102
+ </Box>
103
+ );
104
+ };
105
+
106
+ export default LayoutSelector;
@@ -0,0 +1,62 @@
1
+ import {
2
+ closestCenter,
3
+ DndContext,
4
+ DragEndEvent,
5
+ KeyboardSensor,
6
+ MouseSensor,
7
+ SensorDescriptor,
8
+ SensorOptions,
9
+ TouchSensor,
10
+ useSensor,
11
+ useSensors,
12
+ } from "@dnd-kit/core";
13
+ import { CraftTableComponentProps } from "../types/table";
14
+ import Table from "./table";
15
+ import { restrictToHorizontalAxis } from "@dnd-kit/modifiers";
16
+ import { arrayMove } from "@dnd-kit/sortable";
17
+
18
+ function TableDND<T>({
19
+ table,
20
+ featureOptions,
21
+ NestedComponent,
22
+ columnOrder,
23
+ setColumnOrder,
24
+ isCompactTable,
25
+ }: CraftTableComponentProps<T>) {
26
+ const sensors: SensorDescriptor<SensorOptions>[] = useSensors(
27
+ useSensor(MouseSensor, {}),
28
+ useSensor(TouchSensor, {}),
29
+ useSensor(KeyboardSensor, {})
30
+ );
31
+
32
+ const handleDragEnd = (event: DragEndEvent) => {
33
+ const { active, over } = event;
34
+ if (active && over && active.id !== over.id) {
35
+ setColumnOrder((columnOrder) => {
36
+ const oldIndex = columnOrder.indexOf(active.id as string);
37
+ const newIndex = columnOrder.indexOf(over.id as string);
38
+ return arrayMove(columnOrder, oldIndex, newIndex);
39
+ });
40
+ }
41
+ };
42
+
43
+ return (
44
+ <DndContext
45
+ collisionDetection={closestCenter}
46
+ modifiers={[restrictToHorizontalAxis]}
47
+ onDragEnd={handleDragEnd}
48
+ sensors={sensors}
49
+ >
50
+ <Table
51
+ table={table}
52
+ featureOptions={featureOptions}
53
+ NestedComponent={NestedComponent}
54
+ columnOrder={columnOrder}
55
+ setColumnOrder={setColumnOrder}
56
+ isCompactTable={isCompactTable}
57
+ />
58
+ </DndContext>
59
+ );
60
+ }
61
+
62
+ export default TableDND;
@@ -0,0 +1,144 @@
1
+ import { flexRender } from "@tanstack/react-table";
2
+ import { useSortable } from "@dnd-kit/sortable";
3
+ import { CSSProperties, useState } from "react";
4
+ import { CSS } from "@dnd-kit/utilities";
5
+ import { DownArrow, DragHandleIcon, UpArrow } from "../assets/svg";
6
+ import {
7
+ getColumnAlignment,
8
+ getColumnPinningStyles,
9
+ } from "../libs/utils/common";
10
+ import { align } from "../types/common";
11
+ import { TableHeaderProps } from "../types/table";
12
+ import TableHeadPin from "./table-head-pin";
13
+ import TableHeadPopover from "./table-head-popover";
14
+
15
+ function DraggableTableHeader<T>({
16
+ header,
17
+ featureOptions,
18
+ }: TableHeaderProps<T>) {
19
+ const { enableColumnPinning } = featureOptions;
20
+
21
+ // Popover
22
+ const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
23
+ const [wrap, setWrap] = useState(false);
24
+
25
+ const handleHover = (event: React.MouseEvent<HTMLElement>) => {
26
+ setAnchorEl((prev) => (prev ? null : event.currentTarget));
27
+ };
28
+
29
+ const handleClose = () => {
30
+ setAnchorEl(null);
31
+ };
32
+
33
+ const toggleWrap = () => {
34
+ setWrap((prev) => !prev);
35
+ };
36
+
37
+ const { isDragging, transform, attributes, listeners } = useSortable({
38
+ id: header.column.id,
39
+ });
40
+
41
+ const isPinned = header.column.getIsPinned();
42
+
43
+ const styles: CSSProperties = {
44
+ opacity: isDragging ? 0.8 : 1,
45
+ position: "relative",
46
+ transform: CSS.Translate.toString(transform),
47
+ transition: "width transform 0.2s ease-in-out",
48
+ width: header.column.getSize(),
49
+ minWidth: `${header.column.columnDef.minSize ?? 180}px`,
50
+ maxWidth: `${header.column.columnDef.maxSize}px`,
51
+ };
52
+
53
+ let sortProps: {
54
+ className: string;
55
+ title?: string;
56
+ style?: CSSProperties;
57
+ } = {
58
+ className: "ts__content",
59
+ style: {
60
+ justifyContent: getColumnAlignment(
61
+ (header?.column?.columnDef?.meta as align)?.align
62
+ ),
63
+ },
64
+ };
65
+
66
+ // if (header.column.getCanSort()) {
67
+ // sortProps = {
68
+ // ...sortProps,
69
+ // title:
70
+ // header.column.getNextSortingOrder() === "asc"
71
+ // ? "Sort ascending"
72
+ // : header.column.getNextSortingOrder() === "desc"
73
+ // ? "Sort descending"
74
+ // : "Clear sort",
75
+ // };
76
+ // }
77
+
78
+ return (
79
+ <th
80
+ onMouseLeave={handleClose}
81
+ key={header?.id}
82
+ className="ts__head__th"
83
+ colSpan={header.colSpan}
84
+ onClick={handleHover}
85
+ style={{
86
+ width: `${header.column.getSize()}px `,
87
+ minWidth: `${header.column.columnDef.minSize}px`,
88
+ maxWidth: `${header.column.columnDef.maxSize}px`,
89
+ ...styles,
90
+ ...getColumnPinningStyles(header.column),
91
+ zIndex: isPinned ? 3 : isDragging ? 1 : 0,
92
+ }}
93
+ >
94
+ {header.isPlaceholder ? null : (
95
+ <div {...sortProps}>
96
+ <div
97
+ className={`${
98
+ header.column.getCanSort() ? "ts__content__sort" : ""
99
+ }`.trim()}
100
+ // onClick={header.column.getToggleSortingHandler()}
101
+ >
102
+ {flexRender(header.column.columnDef.header, header.getContext())}
103
+
104
+ {{
105
+ asc: <UpArrow />,
106
+ desc: <DownArrow />,
107
+ }[header.column.getIsSorted() as "asc" | "desc"] ?? null}
108
+ </div>
109
+
110
+ {enableColumnPinning && (
111
+ <TableHeadPin header={header} featureOptions={featureOptions} />
112
+ )}
113
+
114
+ <div {...attributes} {...listeners} className="ts__dnd__button">
115
+ <DragHandleIcon />
116
+ </div>
117
+ </div>
118
+ )}
119
+
120
+ {/* column resizing */}
121
+ {header.column.getCanResize() ? (
122
+ <div
123
+ onDoubleClick={() => header.column.resetSize()}
124
+ onMouseDown={header.getResizeHandler()}
125
+ onTouchStart={header.getResizeHandler()}
126
+ className={`column__resize ${
127
+ header.column.getIsResizing() ? "is__resizing" : ""
128
+ }`}
129
+ />
130
+ ) : null}
131
+
132
+ {/* Popover */}
133
+ <TableHeadPopover
134
+ anchorEl={anchorEl}
135
+ onClose={handleClose}
136
+ header={header}
137
+ wrap={wrap}
138
+ onToggleWrap={toggleWrap}
139
+ />
140
+ </th>
141
+ );
142
+ }
143
+
144
+ export default DraggableTableHeader;