simple-table-core 0.1.1 → 0.1.3

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/README.md CHANGED
@@ -1,12 +1,80 @@
1
- # Simple React Table Project
1
+ # Simple Table
2
2
 
3
- This project is a simple React table application created for fun
3
+ Simple Table is a React grid package designed to provide a flexible and easy-to-use table component for your React applications. Visit our website at [www.simple-table.com](http://www.simple-table.com) for more information and documentation.
4
4
 
5
- ## Available Scripts
5
+ ![Simple Table Example](assets/table-example.png)
6
6
 
7
- In the project directory, you can run:
7
+ ## Props
8
8
 
9
- ### `npm start`
9
+ The Simple Table component accepts the following props:
10
10
 
11
- Runs the app in the development mode.\
12
- Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11
+ - **defaultHeaders**: An array of `HeaderObject` defining the table headers. Each `HeaderObject` includes:
12
+
13
+ - **label**: A string representing the display name of the column header.
14
+ - **accessor**: A string used to access the corresponding data in each row.
15
+ - **width**: A number specifying the width of the column.
16
+ - **cellRenderer**: An optional function that takes a row object and returns a `ReactNode` for custom cell rendering.
17
+
18
+ - **enableColumnResizing**: A boolean to enable or disable column resizing. Default is `true`.
19
+ - **height**: The height of the table.
20
+ - **hideFooter**: A boolean to hide or show the footer. Default is `false`.
21
+ - **nextIcon**: A React element to display as the next page icon. Default is `<AngleRightIcon />`.
22
+ - **prevIcon**: A React element to display as the previous page icon. Default is `<AngleLeftIcon />`.
23
+ - **rows**: An array of data rows to be displayed in the table.
24
+ - **rowsPerPage**: The number of rows to display per page. Default is `10`.
25
+ - **shouldPaginate**: A boolean to enable or disable pagination. Default is `true`.
26
+
27
+ ## Customizable Styles
28
+
29
+ All styles for the Simple Table are customizable and can be found in the `table.css` file. You can modify these styles to fit the design needs of your application.
30
+
31
+ ### CSS Variables
32
+
33
+ You can override the following CSS variables to customize the appearance of the table:
34
+
35
+ - `--st-border-radius`
36
+ - `--st-table-border-color`
37
+ - `--st-border-width`
38
+ - `--st-resize-handle-color`
39
+ - `--st-separator-border-color`
40
+ - `--st-odd-row-background-color`
41
+ - `--st-dragging-background-color`
42
+ - `--st-selected-cell-background-color`
43
+ - `--st-selected-first-cell-background-color`
44
+ - `--st-border-top-color`
45
+ - `--st-border-bottom-color`
46
+ - `--st-border-left-color`
47
+ - `--st-border-right-color`
48
+ - `--st-border-top-white-color`
49
+ - `--st-footer-background-color`
50
+
51
+ ### CSS Class Names
52
+
53
+ The following CSS class names are used in the table and can be customized:
54
+
55
+ - `.st-table-wrapper`
56
+ - `.st-table`
57
+ - `.st-table-header-cell`
58
+ - `.st-table-cell`
59
+ - `.st-table-header-label`
60
+ - `.st-table-header-resize-handle`
61
+ - `.st-table-row-separator`
62
+ - `.st-table-cell-odd-row`
63
+ - `.st-dragging`
64
+ - `.st-table-cell-selected`
65
+ - `.st-table-cell-selected-first`
66
+ - `.border-top-blue`
67
+ - `.border-bottom-blue`
68
+ - `.border-left-blue`
69
+ - `.border-right-blue`
70
+ - `.border-top-white`
71
+ - `.st-footer`
72
+ - `.st-next-prev-btn`
73
+ - `.st-page-btn`
74
+ - `.st-page-btn.active`
75
+
76
+ For more detailed usage and examples, please refer to our [documentation](http://www.simple-table.com/docs).
77
+
78
+ ## License
79
+
80
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simple-table-core",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "dependencies": {
5
5
  "react": "^18.3.1",
6
6
  "react-dom": "^18.3.1"
package/src/App.tsx CHANGED
@@ -1,18 +1,35 @@
1
1
  import SimpleTable from "./components/SimpleTable/SimpleTable";
2
- import { sampleData } from "./consts/SampleData";
2
+ import { inventoryData } from "./consts/SampleData";
3
+ import HeaderObject from "./types/HeaderObject";
3
4
 
4
- const HEADERS = [
5
- { label: "id", accessor: "id" },
6
- { label: "name", accessor: "name" },
7
- { label: "age", accessor: "age" },
8
- { label: "email", accessor: "email" },
9
- { label: "address", accessor: "address" },
5
+ const HEADERS: HeaderObject[] = [
6
+ { label: "Product ID", accessor: "id", width: 150 },
7
+ { label: "Product Name", accessor: "productName", width: 200 },
8
+ { label: "Category", accessor: "category", width: 150 },
9
+ { label: "Quantity", accessor: "quantity", width: 100 },
10
+ { label: "Price", accessor: "price", width: 100 },
11
+ { label: "Supplier", accessor: "supplier", width: 150 },
12
+ { label: "Location", accessor: "location", width: 150 },
13
+ { label: "Reorder Level", accessor: "reorderLevel", width: 150 },
14
+ { label: "SKU", accessor: "sku", width: 150 },
15
+ { label: "Description", accessor: "description", width: 250 },
16
+ { label: "Weight", accessor: "weight", width: 100 },
17
+ { label: "Dimensions", accessor: "dimensions", width: 150 },
18
+ { label: "Barcode", accessor: "barcode", width: 150 },
19
+ { label: "Expiration Date", accessor: "expirationDate", width: 150 },
20
+ { label: "Manufacturer", accessor: "manufacturer", width: 150 },
10
21
  ];
11
22
 
12
23
  const App = () => {
13
24
  return (
14
25
  <div className="app" style={{ padding: "2rem" }}>
15
- <SimpleTable headers={HEADERS} rows={sampleData} />
26
+ <SimpleTable
27
+ defaultHeaders={HEADERS}
28
+ height="auto"
29
+ // height="calc(100dvh - 4rem)"
30
+ rows={inventoryData}
31
+ // shouldPaginate={false}
32
+ />
16
33
  </div>
17
34
  );
18
35
  };
@@ -3,11 +3,16 @@ import usePrevious from "../hooks/usePrevious";
3
3
  import calculateBoundingBoxes from "../helpers/calculateBoundingBoxes";
4
4
 
5
5
  interface AnimateProps {
6
+ allowHorizontalAnimate?: boolean;
6
7
  children: any;
7
- animateRow?: boolean;
8
+ pause?: boolean;
8
9
  }
9
10
 
10
- const Animate = ({ children, animateRow }: AnimateProps) => {
11
+ const Animate = ({
12
+ allowHorizontalAnimate = true,
13
+ children,
14
+ pause,
15
+ }: AnimateProps) => {
11
16
  const [boundingBox, setBoundingBox] = useState<any>({});
12
17
  const [prevBoundingBox, setPrevBoundingBox] = useState<any>({});
13
18
  const prevChildren = usePrevious(children);
@@ -23,6 +28,7 @@ const Animate = ({ children, animateRow }: AnimateProps) => {
23
28
  }, [prevChildren]);
24
29
 
25
30
  useEffect(() => {
31
+ if (pause) return;
26
32
  const hasPrevBoundingBox = Object.keys(prevBoundingBox).length;
27
33
 
28
34
  if (hasPrevBoundingBox) {
@@ -30,16 +36,19 @@ const Animate = ({ children, animateRow }: AnimateProps) => {
30
36
  const domNode = child.ref.current;
31
37
  const firstBox = prevBoundingBox[child.key];
32
38
  const lastBox = boundingBox[child.key];
33
- const changeInPosition = animateRow
39
+
40
+ const changeInX = firstBox.left - lastBox.left;
41
+ const changeInY = !allowHorizontalAnimate
34
42
  ? firstBox.top - lastBox.top
35
- : firstBox.left - lastBox.left;
43
+ : 0;
44
+
45
+ const absoluteChangeInX = Math.abs(changeInX);
46
+ const absoluteChangeInY = Math.abs(changeInY);
36
47
 
37
- if (changeInPosition) {
48
+ if (absoluteChangeInX > 10 || absoluteChangeInY > 10) {
38
49
  requestAnimationFrame(() => {
39
50
  // Before the DOM paints, invert child to old position
40
- domNode.style.transform = animateRow
41
- ? `translateY(${changeInPosition}px)`
42
- : `translateX(${changeInPosition}px)`;
51
+ domNode.style.transform = `translate(${changeInX}px, ${changeInY}px)`;
43
52
  domNode.style.transition = "transform 0s";
44
53
 
45
54
  requestAnimationFrame(() => {
@@ -52,7 +61,7 @@ const Animate = ({ children, animateRow }: AnimateProps) => {
52
61
  }
53
62
  });
54
63
  }
55
- }, [boundingBox, prevBoundingBox, children, animateRow]);
64
+ }, [boundingBox, prevBoundingBox, children, pause, allowHorizontalAnimate]);
56
65
 
57
66
  return children;
58
67
  };
@@ -1,24 +1,65 @@
1
- import { useState, createRef, useRef, useReducer } from "react";
1
+ import {
2
+ useState,
3
+ useRef,
4
+ useEffect,
5
+ useReducer,
6
+ ReactNode,
7
+ useMemo,
8
+ } from "react";
2
9
  import useSelection from "../../hooks/useSelection";
3
10
  import TableHeader from "./TableHeader";
4
11
  import { onSort } from "../../utils/sortUtils";
5
- import Animate from "../Animate";
6
- import TableRow from "./TableRow";
12
+ import TableBody from "./TableBody";
7
13
  import HeaderObject from "../../types/HeaderObject";
14
+ import TableFooter from "./TableFooter";
15
+ import AngleLeftIcon from "../../icons/AngleLeftIcon";
16
+ import AngleRightIcon from "../../icons/AngleRightIcon";
8
17
 
9
18
  interface SpreadsheetProps {
10
- headers: HeaderObject[];
11
- rows: { [key: string]: any }[];
19
+ defaultHeaders: HeaderObject[];
20
+ enableColumnResizing?: boolean;
21
+ height?: string;
22
+ hideFooter?: boolean;
23
+ nextIcon?: ReactNode;
24
+ prevIcon?: ReactNode;
25
+ rows: { [key: string]: string | number | boolean | undefined | null }[];
26
+ rowsPerPage?: number;
27
+ shouldPaginate?: boolean;
12
28
  }
13
29
 
14
- const SimpleTable = ({ headers, rows }: SpreadsheetProps) => {
15
- const headersRef = useRef(headers);
16
- const [, forceUpdate] = useReducer((x) => x + 1, 0);
30
+ const SimpleTable = ({
31
+ defaultHeaders,
32
+ enableColumnResizing = true,
33
+ height,
34
+ hideFooter = false,
35
+ nextIcon = <AngleRightIcon />,
36
+ prevIcon = <AngleLeftIcon />,
37
+ rows,
38
+ rowsPerPage = 10,
39
+ shouldPaginate = true,
40
+ }: SpreadsheetProps) => {
41
+ const [isWidthDragging, setIsWidthDragging] = useState(false);
42
+ const headersRef = useRef(defaultHeaders);
17
43
  const [sortedRows, setSortedRows] = useState(rows);
18
44
  const [sortConfig, setSortConfig] = useState<{
19
45
  key: HeaderObject;
20
46
  direction: string;
21
47
  } | null>(null);
48
+ const [, forceUpdate] = useReducer((x) => x + 1, 0);
49
+
50
+ const [currentPage, setCurrentPage] = useState(1);
51
+
52
+ const tableRef = useRef<HTMLDivElement>(null);
53
+
54
+ const shouldDisplayLastColumnCell = useMemo(() => {
55
+ if (2 == 2) return false;
56
+ if (!tableRef.current) return false;
57
+ const totalColumnWidth = headersRef.current.reduce(
58
+ (acc, header) => acc + header.width,
59
+ 0
60
+ );
61
+ return totalColumnWidth < tableRef.current.clientWidth;
62
+ }, [headersRef.current]);
22
63
 
23
64
  const {
24
65
  handleMouseDown,
@@ -27,11 +68,12 @@ const SimpleTable = ({ headers, rows }: SpreadsheetProps) => {
27
68
  isSelected,
28
69
  getBorderClass,
29
70
  isTopLeftCell,
30
- } = useSelection(sortedRows, headers);
71
+ setSelectedCells,
72
+ } = useSelection(sortedRows, headersRef.current);
31
73
 
32
74
  const handleSort = (columnIndex: number) => {
33
75
  const { sortedData, newSortConfig } = onSort(
34
- headers,
76
+ headersRef.current,
35
77
  sortedRows,
36
78
  sortConfig,
37
79
  columnIndex
@@ -39,42 +81,83 @@ const SimpleTable = ({ headers, rows }: SpreadsheetProps) => {
39
81
  setSortedRows(sortedData);
40
82
  setSortConfig(newSortConfig);
41
83
  };
42
- const onDragEnd = (newHeaders: HeaderObject[]) => {
84
+
85
+ const onTableHeaderDragEnd = (newHeaders: HeaderObject[]) => {
43
86
  headersRef.current = newHeaders;
44
87
  forceUpdate();
45
88
  };
46
89
 
90
+ useEffect(() => {
91
+ const handleClickOutside = (event: MouseEvent) => {
92
+ const target = event.target as HTMLElement;
93
+ if (!target.closest(".st-table-cell")) {
94
+ setSelectedCells([]);
95
+ }
96
+ };
97
+
98
+ document.addEventListener("mousedown", handleClickOutside);
99
+ return () => {
100
+ document.removeEventListener("mousedown", handleClickOutside);
101
+ };
102
+ }, [setSelectedCells]);
103
+
104
+ const currentRows = shouldPaginate
105
+ ? sortedRows.slice(
106
+ (currentPage - 1) * rowsPerPage,
107
+ currentPage * rowsPerPage
108
+ )
109
+ : sortedRows;
110
+
47
111
  return (
48
- <div className="table-wrapper">
49
- <table
50
- className="simple-table"
112
+ <div
113
+ ref={tableRef}
114
+ className="st-table-wrapper"
115
+ style={height ? { height } : {}}
116
+ >
117
+ <div
118
+ className="st-table"
51
119
  onMouseUp={handleMouseUp}
52
120
  onMouseLeave={handleMouseUp}
121
+ style={{
122
+ gridTemplateColumns: `${headersRef.current
123
+ ?.map((header) => `${header.width}px`)
124
+ .join(" ")} 1fr`,
125
+ }}
53
126
  >
54
127
  <TableHeader
128
+ enableColumnResizing={enableColumnResizing}
129
+ forceUpdate={forceUpdate}
55
130
  headersRef={headersRef}
131
+ isWidthDragging={isWidthDragging}
56
132
  onSort={handleSort}
57
- onDragEnd={onDragEnd}
133
+ onTableHeaderDragEnd={onTableHeaderDragEnd}
134
+ setIsWidthDragging={setIsWidthDragging}
135
+ shouldDisplayLastColumnCell={shouldDisplayLastColumnCell}
136
+ />
137
+ <TableBody
138
+ getBorderClass={getBorderClass}
139
+ handleMouseDown={handleMouseDown}
140
+ handleMouseOver={handleMouseOver}
141
+ headers={headersRef.current}
142
+ isSelected={isSelected}
143
+ isTopLeftCell={isTopLeftCell}
144
+ isWidthDragging={isWidthDragging}
145
+ shouldDisplayLastColumnCell={shouldDisplayLastColumnCell}
146
+ shouldPaginate={shouldPaginate}
147
+ sortedRows={currentRows}
148
+ />
149
+ </div>
150
+ {shouldPaginate && (
151
+ <TableFooter
152
+ currentPage={currentPage}
153
+ hideFooter={hideFooter}
154
+ onPageChange={setCurrentPage}
155
+ rowsPerPage={rowsPerPage}
156
+ totalRows={sortedRows.length}
157
+ nextIcon={nextIcon}
158
+ prevIcon={prevIcon}
58
159
  />
59
- <tbody>
60
- <Animate animateRow={true}>
61
- {sortedRows.map((row, rowIndex) => (
62
- <TableRow
63
- getBorderClass={getBorderClass}
64
- handleMouseDown={handleMouseDown}
65
- handleMouseOver={handleMouseOver}
66
- headers={headersRef.current}
67
- isSelected={isSelected}
68
- isTopLeftCell={isTopLeftCell}
69
- key={row.id}
70
- ref={createRef()}
71
- row={row}
72
- rowIndex={rowIndex}
73
- />
74
- ))}
75
- </Animate>
76
- </tbody>
77
- </table>
160
+ )}
78
161
  </div>
79
162
  );
80
163
  };
@@ -0,0 +1,79 @@
1
+ import { createRef, Fragment } from "react";
2
+ import TableCell from "./TableCell";
3
+ import Animate from "../Animate";
4
+ import HeaderObject from "../../types/HeaderObject";
5
+ import TableLastColumnCell from "./TableLastColumnCell";
6
+ import TableRowSeparator from "./TableRowSeparator";
7
+
8
+ interface TableBodyProps {
9
+ getBorderClass: (rowIndex: number, columnIndex: number) => string;
10
+ handleMouseDown: (rowIndex: number, columnIndex: number) => void;
11
+ handleMouseOver: (rowIndex: number, columnIndex: number) => void;
12
+ headers: HeaderObject[];
13
+ isSelected: (rowIndex: number, columnIndex: number) => boolean;
14
+ isTopLeftCell: (rowIndex: number, columnIndex: number) => boolean;
15
+ isWidthDragging: boolean;
16
+ shouldDisplayLastColumnCell: boolean;
17
+ shouldPaginate: boolean;
18
+ sortedRows: { [key: string]: any }[];
19
+ }
20
+
21
+ const TableBody = ({
22
+ getBorderClass,
23
+ handleMouseDown,
24
+ handleMouseOver,
25
+ headers,
26
+ isSelected,
27
+ isTopLeftCell,
28
+ isWidthDragging,
29
+ shouldDisplayLastColumnCell,
30
+ shouldPaginate,
31
+ sortedRows,
32
+ }: TableBodyProps & { shouldDisplayLastColumnCell: boolean }) => {
33
+ return (
34
+ <>
35
+ {sortedRows.map((row, rowIndex) => {
36
+ return (
37
+ <Fragment key={row.id}>
38
+ <Animate
39
+ allowHorizontalAnimate={shouldPaginate}
40
+ pause={isWidthDragging}
41
+ >
42
+ {headers.map((header, columnIndex) => {
43
+ let content = row[header.accessor];
44
+
45
+ if (header.cellRenderer) {
46
+ content = header.cellRenderer(row);
47
+ }
48
+
49
+ return (
50
+ <TableCell
51
+ borderClass={getBorderClass(rowIndex, columnIndex)}
52
+ colIndex={columnIndex}
53
+ content={content}
54
+ isSelected={isSelected(rowIndex, columnIndex)}
55
+ isTopLeftCell={isTopLeftCell(rowIndex, columnIndex)}
56
+ key={header.accessor}
57
+ onMouseDown={() => handleMouseDown(rowIndex, columnIndex)}
58
+ onMouseOver={() => handleMouseOver(rowIndex, columnIndex)}
59
+ ref={createRef()}
60
+ rowIndex={rowIndex}
61
+ isLastRow={rowIndex === sortedRows.length - 1}
62
+ />
63
+ );
64
+ })}
65
+ <TableLastColumnCell
66
+ isLastRow={rowIndex === sortedRows.length - 1}
67
+ ref={createRef()}
68
+ visible={shouldDisplayLastColumnCell}
69
+ />
70
+ </Animate>
71
+ {rowIndex !== sortedRows.length - 1 && <TableRowSeparator />}
72
+ </Fragment>
73
+ );
74
+ })}
75
+ </>
76
+ );
77
+ };
78
+
79
+ export default TableBody;
@@ -9,6 +9,7 @@ interface TableCellProps {
9
9
  borderClass: string;
10
10
  onMouseDown: (rowIndex: number, colIndex: number) => void;
11
11
  onMouseOver: (rowIndex: number, colIndex: number) => void;
12
+ isLastRow: boolean;
12
13
  }
13
14
 
14
15
  const TableCell = forwardRef(
@@ -22,27 +23,27 @@ const TableCell = forwardRef(
22
23
  borderClass,
23
24
  onMouseDown,
24
25
  onMouseOver,
26
+ isLastRow,
25
27
  }: TableCellProps,
26
28
  ref: LegacyRef<HTMLTableCellElement>
27
29
  ) => {
30
+ const isOddRow = rowIndex % 2 === 0;
28
31
  return (
29
- <td
32
+ <div
30
33
  onMouseDown={() => onMouseDown(rowIndex, colIndex)}
31
34
  onMouseOver={() => onMouseOver(rowIndex, colIndex)}
32
35
  ref={ref}
36
+ className={`st-table-cell ${
37
+ isSelected
38
+ ? isTopLeftCell
39
+ ? `st-table-cell-selected-first-cell ${borderClass}`
40
+ : `st-table-cell-selected ${borderClass}`
41
+ : ""
42
+ } ${isLastRow ? "st-table-cell-last-row" : ""}
43
+ ${isOddRow ? "st-table-cell-odd-row" : ""}`}
33
44
  >
34
- <div
35
- className={`table-cell ${
36
- isSelected
37
- ? isTopLeftCell
38
- ? `selected-first-cell ${borderClass}`
39
- : `selected ${borderClass}`
40
- : ""
41
- }`}
42
- >
43
- {content}
44
- </div>
45
- </td>
45
+ {content}
46
+ </div>
46
47
  );
47
48
  }
48
49
  );
@@ -0,0 +1,63 @@
1
+ import React, { ReactNode } from "react";
2
+ import AngleLeftIcon from "../../icons/AngleLeftIcon";
3
+ import AngleRightIcon from "../../icons/AngleRightIcon";
4
+
5
+ interface TableFooterProps {
6
+ currentPage: number;
7
+ hideFooter?: boolean;
8
+ nextIcon?: ReactNode;
9
+ onPageChange: (page: number) => void;
10
+ prevIcon?: ReactNode;
11
+ rowsPerPage: number;
12
+ totalRows: number;
13
+ }
14
+
15
+ const TableFooter = ({
16
+ currentPage,
17
+ hideFooter,
18
+ nextIcon,
19
+ onPageChange,
20
+ prevIcon,
21
+ rowsPerPage,
22
+ totalRows,
23
+ }: TableFooterProps) => {
24
+ const totalPages = Math.ceil(totalRows / rowsPerPage);
25
+
26
+ const handlePageChange = (page: number) => {
27
+ if (page >= 1 && page <= totalPages) {
28
+ onPageChange(page);
29
+ }
30
+ };
31
+
32
+ if (hideFooter) return null;
33
+
34
+ return (
35
+ <div className="st-footer">
36
+ <button
37
+ className="st-next-prev-btn"
38
+ onClick={() => handlePageChange(currentPage - 1)}
39
+ disabled={currentPage === 1}
40
+ >
41
+ {prevIcon}
42
+ </button>
43
+ <button
44
+ className="st-next-prev-btn"
45
+ onClick={() => handlePageChange(currentPage + 1)}
46
+ disabled={currentPage === totalPages}
47
+ >
48
+ {nextIcon}
49
+ </button>
50
+ {Array.from({ length: totalPages }, (_, index) => (
51
+ <button
52
+ key={index}
53
+ onClick={() => handlePageChange(index + 1)}
54
+ className={`st-page-btn ${currentPage === index + 1 ? "active" : ""}`}
55
+ >
56
+ {index + 1}
57
+ </button>
58
+ ))}
59
+ </div>
60
+ );
61
+ };
62
+
63
+ export default TableFooter;
@@ -1,37 +1,59 @@
1
- import { createRef, useRef } from "react";
1
+ import { createRef, Dispatch, SetStateAction, useRef } from "react";
2
2
  import Animate from "../Animate";
3
3
  import TableHeaderCell from "./TableHeaderCell";
4
4
  import HeaderObject from "../../types/HeaderObject";
5
+ import TableLastColumnCell from "./TableLastColumnCell";
6
+ import TableRowSeparator from "./TableRowSeparator";
5
7
 
6
8
  interface TableHeaderProps {
9
+ enableColumnResizing: boolean;
10
+ forceUpdate: () => void;
7
11
  headersRef: React.RefObject<HeaderObject[]>;
12
+ isWidthDragging: boolean;
8
13
  onSort: (columnIndex: number) => void;
9
- onDragEnd: (newHeaders: HeaderObject[]) => void;
14
+ onTableHeaderDragEnd: (newHeaders: HeaderObject[]) => void;
15
+ setIsWidthDragging: Dispatch<SetStateAction<boolean>>;
16
+ shouldDisplayLastColumnCell: boolean;
10
17
  }
11
18
 
12
- const TableHeader = ({ headersRef, onSort, onDragEnd }: TableHeaderProps) => {
19
+ const TableHeader = ({
20
+ enableColumnResizing,
21
+ forceUpdate,
22
+ headersRef,
23
+ isWidthDragging,
24
+ onSort,
25
+ onTableHeaderDragEnd,
26
+ setIsWidthDragging,
27
+ shouldDisplayLastColumnCell,
28
+ }: TableHeaderProps) => {
13
29
  const draggedHeaderRef = useRef<HeaderObject | null>(null);
14
30
  const hoveredHeaderRef = useRef<HeaderObject | null>(null);
15
31
 
16
32
  return (
17
- <thead className="table-header">
18
- <tr>
19
- <Animate>
20
- {headersRef.current?.map((header, index) => (
21
- <TableHeaderCell
22
- draggedHeaderRef={draggedHeaderRef}
23
- headersRef={headersRef}
24
- hoveredHeaderRef={hoveredHeaderRef}
25
- index={index}
26
- key={header.accessor}
27
- onDragEnd={onDragEnd}
28
- onSort={onSort}
29
- ref={createRef()}
30
- />
31
- ))}
32
- </Animate>
33
- </tr>
34
- </thead>
33
+ <>
34
+ <Animate pause={isWidthDragging}>
35
+ {headersRef.current?.map((header, index) => (
36
+ <TableHeaderCell
37
+ draggedHeaderRef={draggedHeaderRef}
38
+ enableColumnResizing={enableColumnResizing}
39
+ forceUpdate={forceUpdate}
40
+ headersRef={headersRef}
41
+ hoveredHeaderRef={hoveredHeaderRef}
42
+ index={index}
43
+ key={header.accessor}
44
+ onSort={onSort}
45
+ onTableHeaderDragEnd={onTableHeaderDragEnd}
46
+ ref={createRef()}
47
+ setIsWidthDragging={setIsWidthDragging}
48
+ />
49
+ ))}
50
+ <TableLastColumnCell
51
+ ref={createRef()}
52
+ visible={shouldDisplayLastColumnCell}
53
+ />
54
+ </Animate>
55
+ <TableRowSeparator />
56
+ </>
35
57
  );
36
58
  };
37
59