ehscan-react-table 0.0.54 → 0.0.56
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,12 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { calcDateDiff, formatToDDMMYYYY } from '../tools/dateFunction';
|
|
3
3
|
import styles from '../elements/table.module.css';
|
|
4
|
-
export const TableCellDueDate = ({ content, id, col, small, clickRow }) => {
|
|
4
|
+
export const TableCellDueDate = ({ content, id, col, checked, small, clickRow }) => {
|
|
5
5
|
const DateContent = ({ value }) => {
|
|
6
6
|
const valDate = value;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
: _jsx("span", { className: `${styles.dateTag} ${styles[
|
|
7
|
+
switch (true) {
|
|
8
|
+
case valDate === '-' || !valDate: return '-';
|
|
9
|
+
case checked === true: return _jsx("span", { className: `${styles.dateTag} ${styles['irrelevant']}${small ? ` ${styles.dateTagSmall}` : ''}`, children: small ? '' : formatToDDMMYYYY(valDate) });
|
|
10
|
+
default: return _jsx("span", { className: `${styles.dateTag} ${styles[calcDateDiff(valDate)]}${small ? ` ${styles.dateTagSmall}` : ''}`, children: small ? '' : formatToDDMMYYYY(valDate) });
|
|
11
|
+
}
|
|
10
12
|
};
|
|
11
13
|
return (_jsx("div", { className: styles.dueDateColWrapper, onClick: (e) => clickRow({ id, col, type: 'duedate', e }), children: _jsx(DateContent, { value: content }) }));
|
|
12
14
|
};
|
package/dist/elements/Table.d.ts
CHANGED
package/dist/elements/Table.js
CHANGED
|
@@ -12,7 +12,7 @@ import { useEffect, useState, useRef } from "react";
|
|
|
12
12
|
import TableCellSelectHeadCol from "./TableCellSelectHeadCol";
|
|
13
13
|
import { debounce } from "./Debounce";
|
|
14
14
|
import styles from './table.module.css';
|
|
15
|
-
export const Table = ({ columns, rows, sortOrder, setSortOrder, cellComponents, setSelectedIds, searchTermArraySetter, setSearchTermArraySetter, fallback, nearBottom, setNearBottom, changeColumns, measureCols, displayImportant }) => {
|
|
15
|
+
export const Table = ({ columns, rows, sortOrder, setSortOrder, cellComponents, setSelectedIds, searchTermArraySetter, setSearchTermArraySetter, fallback, nearBottom, setNearBottom, changeColumns, measureCols, displayImportant, adjustBottom = 20, }) => {
|
|
16
16
|
const [wrapperBottom, setWrapperBottom] = useState(undefined);
|
|
17
17
|
const headerRef = useRef(null);
|
|
18
18
|
const scrollRef = useRef(null);
|
|
@@ -32,20 +32,26 @@ export const Table = ({ columns, rows, sortOrder, setSortOrder, cellComponents,
|
|
|
32
32
|
}
|
|
33
33
|
}, [searchTermArraySetter]);
|
|
34
34
|
useEffect(() => {
|
|
35
|
-
const resizeTimeout = {
|
|
36
|
-
current: null
|
|
37
|
-
};
|
|
38
35
|
const resizeFn = () => {
|
|
39
|
-
if (
|
|
40
|
-
|
|
36
|
+
if (colRefs === null || colRefs === void 0 ? void 0 : colRefs.current) {
|
|
37
|
+
Object.keys(colRefs.current).forEach(key => {
|
|
38
|
+
var _a;
|
|
39
|
+
const el = colRefs.current[key];
|
|
40
|
+
if (!el)
|
|
41
|
+
return;
|
|
42
|
+
const { width } = el.getBoundingClientRect();
|
|
43
|
+
const min = ((_a = measureCols.find(c => c.col === key)) === null || _a === void 0 ? void 0 : _a.min) || 50;
|
|
44
|
+
if (width < min) {
|
|
45
|
+
changeColumns({ col: key, small: true });
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
changeColumns({ col: key, small: false });
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (headerRef.current) {
|
|
52
|
+
const { bottom } = headerRef.current.getBoundingClientRect();
|
|
53
|
+
setWrapperBottom(bottom - adjustBottom);
|
|
41
54
|
}
|
|
42
|
-
resizeTimeout.current = setTimeout(() => {
|
|
43
|
-
if (scrollRef.current) {
|
|
44
|
-
const info = scrollRef.current.getBoundingClientRect();
|
|
45
|
-
console.log(info);
|
|
46
|
-
setWrapperBottom(info.height);
|
|
47
|
-
}
|
|
48
|
-
}, 150); // debounce delay
|
|
49
55
|
};
|
|
50
56
|
const handleScroll = () => {
|
|
51
57
|
const el = scrollRef.current;
|
|
@@ -55,63 +61,18 @@ export const Table = ({ columns, rows, sortOrder, setSortOrder, cellComponents,
|
|
|
55
61
|
if (reachBottom && !nearBottom)
|
|
56
62
|
setNearBottom(true);
|
|
57
63
|
};
|
|
58
|
-
resizeFn(); //
|
|
64
|
+
resizeFn(); //init
|
|
59
65
|
const scrollEl = scrollRef.current;
|
|
60
66
|
if (scrollEl)
|
|
61
67
|
scrollEl.addEventListener("scroll", handleScroll);
|
|
62
68
|
window.addEventListener("resize", resizeFn);
|
|
63
69
|
return () => {
|
|
64
70
|
window.removeEventListener("resize", resizeFn);
|
|
65
|
-
if (scrollEl)
|
|
71
|
+
if (scrollEl) {
|
|
66
72
|
scrollEl.removeEventListener("scroll", handleScroll);
|
|
67
|
-
|
|
68
|
-
clearTimeout(resizeTimeout.current);
|
|
73
|
+
}
|
|
69
74
|
};
|
|
70
75
|
}, []);
|
|
71
|
-
// useEffect(() => {
|
|
72
|
-
// const resizeFn = () => {
|
|
73
|
-
// if (colRefs?.current) {
|
|
74
|
-
// Object.keys(colRefs.current).forEach(key => {
|
|
75
|
-
// const el = colRefs.current[key];
|
|
76
|
-
// if (!el) return;
|
|
77
|
-
// const { width } = el.getBoundingClientRect();
|
|
78
|
-
// const min = measureCols.find(c => c.col === key)?.min || 50;
|
|
79
|
-
// if (width < min) {
|
|
80
|
-
// changeColumns({ col: key, small: true });
|
|
81
|
-
// return;
|
|
82
|
-
// }
|
|
83
|
-
// changeColumns({ col: key, small: false });
|
|
84
|
-
// });
|
|
85
|
-
// }
|
|
86
|
-
// setTimeout(() => {
|
|
87
|
-
// if (scrollRef.current){
|
|
88
|
-
// const info = scrollRef.current.getBoundingClientRect();
|
|
89
|
-
// console.log(info)
|
|
90
|
-
// setWrapperBottom(info.height)
|
|
91
|
-
// }
|
|
92
|
-
// },100)
|
|
93
|
-
// };
|
|
94
|
-
// const handleScroll = () => {
|
|
95
|
-
// const el = scrollRef.current;
|
|
96
|
-
// if (!el) return;
|
|
97
|
-
// const reachBottom = el.scrollTop + el.clientHeight >= el.scrollHeight - 100;
|
|
98
|
-
// if (reachBottom && !nearBottom) setNearBottom(true)
|
|
99
|
-
// };
|
|
100
|
-
// resizeFn(); //init
|
|
101
|
-
// const scrollEl = scrollRef.current;
|
|
102
|
-
// if (scrollEl) scrollEl.addEventListener("scroll", handleScroll);
|
|
103
|
-
// window.addEventListener("resize", resizeFn);
|
|
104
|
-
// return () => {
|
|
105
|
-
// window.removeEventListener("resize", resizeFn);
|
|
106
|
-
// if (scrollEl) {
|
|
107
|
-
// scrollEl.removeEventListener("scroll", handleScroll);
|
|
108
|
-
// }
|
|
109
|
-
// };
|
|
110
|
-
// }, []);
|
|
111
|
-
// if (headerRef.current) {
|
|
112
|
-
// const { bottom } = headerRef.current.getBoundingClientRect();
|
|
113
|
-
// setWrapperBottom(bottom - 20);
|
|
114
|
-
// }
|
|
115
76
|
const checkHead = (entry) => {
|
|
116
77
|
if (entry === undefined)
|
|
117
78
|
return;
|
|
@@ -211,5 +172,5 @@ export const Table = ({ columns, rows, sortOrder, setSortOrder, cellComponents,
|
|
|
211
172
|
return (_jsx("td", { children: _jsx("div", { className: styles.exttablediv, children: _jsx(CellComponent, { row: row, col: col.tag, small: col.small }) }) }, ci));
|
|
212
173
|
}), _jsx(EndCol, {})] }, `row-${rowIndex}`))) }, 'ext-tbody'));
|
|
213
174
|
};
|
|
214
|
-
return (_jsx(_Fragment, { children: _jsxs("div", { className: `${styles.tablewrapper} ${styles['_tbl']}`, style: { maxHeight:
|
|
175
|
+
return (_jsx(_Fragment, { children: _jsxs("div", { className: `${styles.tablewrapper} ${styles['_tbl']}`, style: { maxHeight: `calc(100vh - ${wrapperBottom}px)` }, ref: scrollRef, children: [_jsxs("table", { className: styles.exttable, children: [_jsx("thead", { ref: headerRef, children: _jsx("tr", { className: styles.trstickyhead, children: _jsx(HeadCols, {}) }) }), rows && rows.length > 0 && _jsx(TableBody, {})] }), rows && rows.length === 0 && fallback()] }) }));
|
|
215
176
|
};
|