simple-table-core 0.1.2 → 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.2",
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,19 +1,35 @@
1
1
  import SimpleTable from "./components/SimpleTable/SimpleTable";
2
- import { sampleData } from "./consts/SampleData";
2
+ import { inventoryData } from "./consts/SampleData";
3
3
  import HeaderObject from "./types/HeaderObject";
4
4
 
5
5
  const HEADERS: HeaderObject[] = [
6
- { label: "id", accessor: "id", width: 100 },
7
- { label: "name", accessor: "name", width: 100 },
8
- { label: "age", accessor: "age", width: 100 },
9
- { label: "email", accessor: "email", width: 100 },
10
- { label: "address", accessor: "address", width: 100 },
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 },
11
21
  ];
12
22
 
13
23
  const App = () => {
14
24
  return (
15
25
  <div className="app" style={{ padding: "2rem" }}>
16
- <SimpleTable defaultHeaders={HEADERS} rows={sampleData} />
26
+ <SimpleTable
27
+ defaultHeaders={HEADERS}
28
+ height="auto"
29
+ // height="calc(100dvh - 4rem)"
30
+ rows={inventoryData}
31
+ // shouldPaginate={false}
32
+ />
17
33
  </div>
18
34
  );
19
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
8
  pause?: boolean;
8
9
  }
9
10
 
10
- const Animate = ({ children, pause }: 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);
@@ -33,9 +38,14 @@ const Animate = ({ children, pause }: AnimateProps) => {
33
38
  const lastBox = boundingBox[child.key];
34
39
 
35
40
  const changeInX = firstBox.left - lastBox.left;
36
- const changeInY = firstBox.top - lastBox.top;
41
+ const changeInY = !allowHorizontalAnimate
42
+ ? firstBox.top - lastBox.top
43
+ : 0;
37
44
 
38
- if (changeInX || changeInY) {
45
+ const absoluteChangeInX = Math.abs(changeInX);
46
+ const absoluteChangeInY = Math.abs(changeInY);
47
+
48
+ if (absoluteChangeInX > 10 || absoluteChangeInY > 10) {
39
49
  requestAnimationFrame(() => {
40
50
  // Before the DOM paints, invert child to old position
41
51
  domNode.style.transform = `translate(${changeInX}px, ${changeInY}px)`;
@@ -51,7 +61,7 @@ const Animate = ({ children, pause }: AnimateProps) => {
51
61
  }
52
62
  });
53
63
  }
54
- }, [boundingBox, prevBoundingBox, children, pause]);
64
+ }, [boundingBox, prevBoundingBox, children, pause, allowHorizontalAnimate]);
55
65
 
56
66
  return children;
57
67
  };
@@ -1,25 +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 "./TableBody";
7
- import HeaderObject from "../../types/HeaderObject";
8
12
  import TableBody from "./TableBody";
13
+ import HeaderObject from "../../types/HeaderObject";
14
+ import TableFooter from "./TableFooter";
15
+ import AngleLeftIcon from "../../icons/AngleLeftIcon";
16
+ import AngleRightIcon from "../../icons/AngleRightIcon";
9
17
 
10
18
  interface SpreadsheetProps {
11
19
  defaultHeaders: HeaderObject[];
12
- rows: { [key: string]: any }[];
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;
13
28
  }
14
29
 
15
- const SimpleTable = ({ defaultHeaders, rows }: SpreadsheetProps) => {
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) => {
16
41
  const [isWidthDragging, setIsWidthDragging] = useState(false);
17
- const [headers, setHeaders] = useState(defaultHeaders);
42
+ const headersRef = useRef(defaultHeaders);
18
43
  const [sortedRows, setSortedRows] = useState(rows);
19
44
  const [sortConfig, setSortConfig] = useState<{
20
45
  key: HeaderObject;
21
46
  direction: string;
22
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]);
23
63
 
24
64
  const {
25
65
  handleMouseDown,
@@ -28,11 +68,12 @@ const SimpleTable = ({ defaultHeaders, rows }: SpreadsheetProps) => {
28
68
  isSelected,
29
69
  getBorderClass,
30
70
  isTopLeftCell,
31
- } = useSelection(sortedRows, headers);
71
+ setSelectedCells,
72
+ } = useSelection(sortedRows, headersRef.current);
32
73
 
33
74
  const handleSort = (columnIndex: number) => {
34
75
  const { sortedData, newSortConfig } = onSort(
35
- headers,
76
+ headersRef.current,
36
77
  sortedRows,
37
78
  sortConfig,
38
79
  columnIndex
@@ -40,41 +81,83 @@ const SimpleTable = ({ defaultHeaders, rows }: SpreadsheetProps) => {
40
81
  setSortedRows(sortedData);
41
82
  setSortConfig(newSortConfig);
42
83
  };
84
+
43
85
  const onTableHeaderDragEnd = (newHeaders: HeaderObject[]) => {
44
- setHeaders(newHeaders);
86
+ headersRef.current = newHeaders;
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="st-table-wrapper">
112
+ <div
113
+ ref={tableRef}
114
+ className="st-table-wrapper"
115
+ style={height ? { height } : {}}
116
+ >
49
117
  <div
50
118
  className="st-table"
51
119
  onMouseUp={handleMouseUp}
52
120
  onMouseLeave={handleMouseUp}
53
121
  style={{
54
- gridTemplateColumns: headers
122
+ gridTemplateColumns: `${headersRef.current
55
123
  ?.map((header) => `${header.width}px`)
56
- .join(" "),
124
+ .join(" ")} 1fr`,
57
125
  }}
58
126
  >
59
127
  <TableHeader
60
- headers={headers}
128
+ enableColumnResizing={enableColumnResizing}
129
+ forceUpdate={forceUpdate}
130
+ headersRef={headersRef}
131
+ isWidthDragging={isWidthDragging}
61
132
  onSort={handleSort}
62
133
  onTableHeaderDragEnd={onTableHeaderDragEnd}
63
- setHeaders={setHeaders}
64
134
  setIsWidthDragging={setIsWidthDragging}
65
- isWidthDragging={isWidthDragging}
135
+ shouldDisplayLastColumnCell={shouldDisplayLastColumnCell}
66
136
  />
67
137
  <TableBody
68
138
  getBorderClass={getBorderClass}
69
139
  handleMouseDown={handleMouseDown}
70
140
  handleMouseOver={handleMouseOver}
71
- headers={headers}
141
+ headers={headersRef.current}
72
142
  isSelected={isSelected}
73
143
  isTopLeftCell={isTopLeftCell}
74
- sortedRows={sortedRows}
75
144
  isWidthDragging={isWidthDragging}
145
+ shouldDisplayLastColumnCell={shouldDisplayLastColumnCell}
146
+ shouldPaginate={shouldPaginate}
147
+ sortedRows={currentRows}
76
148
  />
77
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}
159
+ />
160
+ )}
78
161
  </div>
79
162
  );
80
163
  };
@@ -1,51 +1,79 @@
1
- import { createRef, forwardRef, LegacyRef } from "react";
1
+ import { createRef, Fragment } from "react";
2
2
  import TableCell from "./TableCell";
3
3
  import Animate from "../Animate";
4
4
  import HeaderObject from "../../types/HeaderObject";
5
+ import TableLastColumnCell from "./TableLastColumnCell";
6
+ import TableRowSeparator from "./TableRowSeparator";
5
7
 
6
- interface TableRowProps {
7
- headers: HeaderObject[];
8
- isSelected: (rowIndex: number, columnIndex: number) => boolean;
9
- isTopLeftCell: (rowIndex: number, columnIndex: number) => boolean;
8
+ interface TableBodyProps {
10
9
  getBorderClass: (rowIndex: number, columnIndex: number) => string;
11
10
  handleMouseDown: (rowIndex: number, columnIndex: number) => void;
12
11
  handleMouseOver: (rowIndex: number, columnIndex: number) => void;
13
- sortedRows: { [key: string]: any }[];
12
+ headers: HeaderObject[];
13
+ isSelected: (rowIndex: number, columnIndex: number) => boolean;
14
+ isTopLeftCell: (rowIndex: number, columnIndex: number) => boolean;
14
15
  isWidthDragging: boolean;
16
+ shouldDisplayLastColumnCell: boolean;
17
+ shouldPaginate: boolean;
18
+ sortedRows: { [key: string]: any }[];
15
19
  }
16
20
 
17
- const TableRow = ({
18
- headers,
19
- isSelected,
20
- isTopLeftCell,
21
+ const TableBody = ({
21
22
  getBorderClass,
22
23
  handleMouseDown,
23
24
  handleMouseOver,
24
- sortedRows,
25
+ headers,
26
+ isSelected,
27
+ isTopLeftCell,
25
28
  isWidthDragging,
26
- }: TableRowProps) => {
29
+ shouldDisplayLastColumnCell,
30
+ shouldPaginate,
31
+ sortedRows,
32
+ }: TableBodyProps & { shouldDisplayLastColumnCell: boolean }) => {
27
33
  return (
28
34
  <>
29
- {sortedRows.map((row, rowIndex) => (
30
- <Animate key={row.id} pause={isWidthDragging}>
31
- {headers.map((header, columnIndex) => (
32
- <TableCell
33
- borderClass={getBorderClass(rowIndex, columnIndex)}
34
- colIndex={columnIndex}
35
- content={row[header.accessor]}
36
- isSelected={isSelected(rowIndex, columnIndex)}
37
- isTopLeftCell={isTopLeftCell(rowIndex, columnIndex)}
38
- key={header.accessor}
39
- onMouseDown={() => handleMouseDown(rowIndex, columnIndex)}
40
- onMouseOver={() => handleMouseOver(rowIndex, columnIndex)}
41
- ref={createRef()}
42
- rowIndex={rowIndex}
43
- />
44
- ))}
45
- </Animate>
46
- ))}
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
+ })}
47
75
  </>
48
76
  );
49
77
  };
50
78
 
51
- export default TableRow;
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,26 +23,26 @@ 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
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={`st-table-cell ${
36
- isSelected
37
- ? isTopLeftCell
38
- ? `st-table-cell-selected-first-cell ${borderClass}`
39
- : `st-table-cell-selected ${borderClass}`
40
- : ""
41
- }`}
42
- >
43
- {content}
44
- </div>
45
+ {content}
45
46
  </div>
46
47
  );
47
48
  }
@@ -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;
@@ -2,44 +2,58 @@ 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 {
7
- headers: HeaderObject[];
9
+ enableColumnResizing: boolean;
10
+ forceUpdate: () => void;
11
+ headersRef: React.RefObject<HeaderObject[]>;
8
12
  isWidthDragging: boolean;
9
13
  onSort: (columnIndex: number) => void;
10
14
  onTableHeaderDragEnd: (newHeaders: HeaderObject[]) => void;
11
- setHeaders: Dispatch<SetStateAction<HeaderObject[]>>;
12
15
  setIsWidthDragging: Dispatch<SetStateAction<boolean>>;
16
+ shouldDisplayLastColumnCell: boolean;
13
17
  }
14
18
 
15
- const TableHeader: React.FC<TableHeaderProps> = ({
16
- headers,
19
+ const TableHeader = ({
20
+ enableColumnResizing,
21
+ forceUpdate,
22
+ headersRef,
17
23
  isWidthDragging,
18
24
  onSort,
19
25
  onTableHeaderDragEnd,
20
- setHeaders,
21
26
  setIsWidthDragging,
22
- }) => {
27
+ shouldDisplayLastColumnCell,
28
+ }: TableHeaderProps) => {
23
29
  const draggedHeaderRef = useRef<HeaderObject | null>(null);
24
30
  const hoveredHeaderRef = useRef<HeaderObject | null>(null);
25
31
 
26
32
  return (
27
- <Animate pause={isWidthDragging}>
28
- {headers?.map((header, index) => (
29
- <TableHeaderCell
30
- draggedHeaderRef={draggedHeaderRef}
31
- headers={headers}
32
- hoveredHeaderRef={hoveredHeaderRef}
33
- index={index}
34
- key={header.accessor}
35
- onSort={onSort}
36
- onTableHeaderDragEnd={onTableHeaderDragEnd}
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
37
51
  ref={createRef()}
38
- setHeaders={setHeaders}
39
- setIsWidthDragging={setIsWidthDragging}
52
+ visible={shouldDisplayLastColumnCell}
40
53
  />
41
- ))}
42
- </Animate>
54
+ </Animate>
55
+ <TableRowSeparator />
56
+ </>
43
57
  );
44
58
  };
45
59