ehscan-react-table 0.0.29 → 0.0.30

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.
@@ -3,6 +3,7 @@ type Props = {
3
3
  content: string;
4
4
  id: string | number;
5
5
  col: string | number;
6
+ small?: boolean;
6
7
  clickRow: (args: {
7
8
  id: string | number;
8
9
  col: string | number;
@@ -1,12 +1,12 @@
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, clickRow }) => {
4
+ export const TableCellDueDate = ({ content, id, col, small, clickRow }) => {
5
5
  const DateContent = ({ value }) => {
6
6
  const valDate = value;
7
7
  return valDate === '-' || !valDate
8
8
  ? '-'
9
- : _jsx("span", { className: `${styles.dateTag} ${styles[calcDateDiff(valDate)]}`, children: formatToDDMMYYYY(valDate) });
9
+ : _jsx("span", { className: `${styles.dateTag} ${styles[calcDateDiff(valDate)]}${small ? ` ${styles.dateTagSmall}` : ''}`, children: small ? '' : formatToDDMMYYYY(valDate) });
10
10
  };
11
11
  return (_jsx("div", { onClick: () => clickRow({ id, col, type: 'default' }), style: { width: "100%", textAlign: "center" }, children: _jsx(DateContent, { value: content }) }));
12
12
  };
@@ -3,6 +3,7 @@ type TableDefCellProps = {
3
3
  content: ReactNode;
4
4
  id: string | number;
5
5
  col: string | number;
6
+ small?: boolean;
6
7
  clickRow: (args: {
7
8
  id: string | number;
8
9
  col: string | number;
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- export const TableDefCell = ({ content, id, col, clickRow }) => {
3
- return (_jsx("div", { onClick: () => clickRow({ id, col, type: 'default' }), children: content }));
1
+ import { jsxs as _jsxs } from "react/jsx-runtime";
2
+ export const TableDefCell = ({ content, id, col, small, clickRow }) => {
3
+ return (_jsxs("div", { onClick: () => clickRow({ id, col, type: 'default' }), children: [small ? 'Small' : '', " ", content] }));
4
4
  };
@@ -4,11 +4,16 @@ type TableColumn = {
4
4
  type?: string;
5
5
  search?: boolean;
6
6
  width?: number;
7
+ small?: boolean;
7
8
  };
8
9
  type SortOrder = {
9
10
  tag: string;
10
11
  dir: "asc" | "desc";
11
12
  };
13
+ type MeasureCol = {
14
+ col: string;
15
+ min: number;
16
+ };
12
17
  type Props = {
13
18
  columns: TableColumn[];
14
19
  rows: any[];
@@ -17,6 +22,7 @@ type Props = {
17
22
  cellComponents: Record<string, React.ComponentType<{
18
23
  row: any;
19
24
  col: string;
25
+ small?: boolean;
20
26
  }>>;
21
27
  setSelectedIds: React.Dispatch<React.SetStateAction<string[]>>;
22
28
  searchTermArraySetter?: (arr: {
@@ -28,6 +34,10 @@ type Props = {
28
34
  term: string;
29
35
  }[]) => void;
30
36
  fallback: () => React.ReactNode;
37
+ nearBottom: boolean;
38
+ setNearBottom: (nearBottom: boolean) => void;
39
+ changeColumns: (args: any) => void;
40
+ measureCols: MeasureCol[];
31
41
  };
32
42
  export declare const Table: React.FC<Props>;
33
43
  export {};
@@ -12,16 +12,19 @@ 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 }) => {
15
+ export const Table = ({ columns, rows, sortOrder, setSortOrder, cellComponents, setSelectedIds, searchTermArraySetter, setSearchTermArraySetter, fallback, nearBottom, setNearBottom, changeColumns, measureCols }) => {
16
16
  const [wrapperBottom, setWrapperBottom] = useState(undefined);
17
17
  const headerRef = useRef(null);
18
+ const scrollRef = useRef(null);
18
19
  const tableSearchTerms = useRef({});
19
20
  const [openCol, setOpenCol] = useState(undefined);
20
21
  const [checkAll, setCheckAll] = useState(false);
22
+ const colRefs = useRef({});
23
+ const measureColElements = measureCols.map(a => a.col);
21
24
  useEffect(() => {
22
25
  if (searchTermArraySetter !== undefined)
23
26
  return;
24
- try { //Reset SearchTerm
27
+ try {
25
28
  tableSearchTerms.current = {};
26
29
  }
27
30
  catch (error) {
@@ -29,19 +32,46 @@ export const Table = ({ columns, rows, sortOrder, setSortOrder, cellComponents,
29
32
  }
30
33
  }, [searchTermArraySetter]);
31
34
  useEffect(() => {
32
- const calculateHeight = () => {
33
- var _a;
34
- if ((_a = colRefs === null || colRefs === void 0 ? void 0 : colRefs.current) === null || _a === void 0 ? void 0 : _a['duedate']) {
35
- console.log(colRefs.current['duedate'].getBoundingClientRect());
35
+ const resizeFn = () => {
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
+ });
36
50
  }
37
51
  if (headerRef.current) {
38
52
  const { bottom } = headerRef.current.getBoundingClientRect();
39
53
  setWrapperBottom(bottom - 20);
40
54
  }
41
55
  };
42
- calculateHeight();
43
- window.addEventListener("resize", calculateHeight);
44
- return () => window.removeEventListener("resize", calculateHeight);
56
+ const handleScroll = () => {
57
+ const el = scrollRef.current;
58
+ if (!el)
59
+ return;
60
+ const reachBottom = el.scrollTop + el.clientHeight >= el.scrollHeight - 100;
61
+ if (reachBottom && !nearBottom)
62
+ setNearBottom(true);
63
+ };
64
+ resizeFn(); //init
65
+ const scrollEl = scrollRef.current;
66
+ if (scrollEl)
67
+ scrollEl.addEventListener("scroll", handleScroll);
68
+ window.addEventListener("resize", resizeFn);
69
+ return () => {
70
+ window.removeEventListener("resize", resizeFn);
71
+ if (scrollEl) {
72
+ scrollEl.removeEventListener("scroll", handleScroll);
73
+ }
74
+ };
45
75
  }, []);
46
76
  const checkHead = (entry) => {
47
77
  if (entry === undefined)
@@ -62,7 +92,7 @@ export const Table = ({ columns, rows, sortOrder, setSortOrder, cellComponents,
62
92
  yield filterRows(entry);
63
93
  }
64
94
  catch (err) {
65
- console.error('Autosave failed:', err);
95
+ console.error('debounce failed:', err);
66
96
  }
67
97
  });
68
98
  doSave();
@@ -99,7 +129,6 @@ export const Table = ({ columns, rows, sortOrder, setSortOrder, cellComponents,
99
129
  const HeadColSort = ({ tag }) => {
100
130
  return (_jsx(_Fragment, { children: _jsxs("div", { className: "sort-col", onClick: () => setSortOrder({ tag, dir: sortOrder.dir === 'desc' ? 'asc' : 'desc' }), children: [sortOrder.tag === tag && _jsx(SortButton, {}), openCol === tag && sortOrder.tag !== tag && _jsx(EmptySort, {})] }) }));
101
131
  };
102
- const colRefs = useRef({});
103
132
  const HeadColMainLit = {
104
133
  def: (tag) => tag !== null && tag !== void 0 ? tag : "",
105
134
  duedate: () => (_jsxs("svg", { width: "40", height: "40", version: "1.1", viewBox: "0 -960 1600 1600", xmlns: "http://www.w3.org/2000/svg", children: [_jsx("path", { className: "table-header-icons", d: "m381.72-908.36c-112.37 0-203.83 90.835-203.83 202.42v157.03h-68.359c-31.606 1.731-56.094 24.21-56.094 51.328 0 27.118 24.487 49.407 56.094 51.484h68.359v577.03h-68.359c-32.304 1.1539-57.891 25.058-57.891 53.906 0 28.964 25.587 52.674 57.891 53.828h68.359v147.27a203.93 202.52 0 0 0 203.83 202.42h224.06l56.719-98.359h-288.28c-53.103 0-96.406-42.893-96.406-95.859v-155.47h58.047c31.723-1.9617 56.328-25.441 56.328-53.828 0-28.502-24.606-51.945-56.328-53.906h-58.047v-577.11h58.047c33.117 0 60.118-22.978 60.234-51.25 1e-4 -28.272-27.001-51.328-60.234-51.328h-57.969v-165.47a96.679 96.009 0 0 1 96.484-95.859v0.15624h977.58a96.795 96.124 0 0 1 96.406 95.781v921.72l100 166.88v-1080.4c-1e-4 -111.59-91.347-202.42-203.83-202.42h-962.81zm251.25 359.61c-30.444 1.5001-54.781 22.239-56.641 48.203a47.294 46.966 0 0 0 15 37.188 64.259 63.814 0 0 0 41.641 17.266h514.06v-0.07813c33.233 0 60.042-22.978 60.391-51.25 0-28.272-27.274-51.328-60.391-51.328h-514.06zm-2.8125 338.28c-29.849 0-53.906 24.057-53.906 53.906s24.057 53.828 53.906 53.828h318.59c29.849 1e-5 53.828-23.979 53.828-53.828s-23.979-53.906-53.828-53.906h-318.59zm0 343.36c-29.849 0-53.906 24.057-53.906 53.906 0 29.849 24.057 53.906 53.906 53.906h139.53c29.849 0 53.828-24.057 53.828-53.906 1e-5 -29.85-23.979-53.906-53.828-53.906h-139.53zm96.016 357.11-56.797 98.359h102.73l59.922-98.359h-105.86z" }), _jsx("path", { className: "table-header-icons-overdue", d: "m1134-177.42c-15.754 0-31.544 7.7956-40.547 23.438l-415.94 720.39c-18.005 31.284 4.5368 70.234 40.547 70.234h831.8c36.01 0 58.552-38.951 40.547-70.234l-415.94-720.39c-9.0026-15.642-24.714-23.438-40.469-23.438zm0 184.53c47.713 0 86.406 44.129 86.406 98.594 0 166.1-38.693 300.7-86.406 300.7-47.714 0-86.484-134.61-86.484-300.7 0-54.465 38.771-98.594 86.484-98.594zm0 451.95a60.542 60.542 0 0 1 60.547 60.547 60.542 60.542 0 0 1-60.547 60.547 60.542 60.542 0 0 1-60.547-60.547 60.542 60.542 0 0 1 60.547-60.547z", fill: "#999" })] })),
@@ -107,10 +136,9 @@ export const Table = ({ columns, rows, sortOrder, setSortOrder, cellComponents,
107
136
  const HeadColMain = ({ col }) => {
108
137
  var _a, _b;
109
138
  const { tag, search, title, width } = col;
110
- const shouldMeasure = ['duedate'].includes(tag);
111
139
  const colTitle = title !== undefined ? title : tag;
112
140
  const thWidth = width !== undefined ? `${width}px` : "30px";
113
- return (_jsx("th", { ref: shouldMeasure ? (el) => { colRefs.current[tag] = el; } : undefined, style: { "--custom-width": thWidth }, children: _jsxs("div", { className: styles.headcolcell, children: [_jsx(HeadColSort, { tag: tag }), _jsx("div", { className: styles.headcolcellmain, children: search
141
+ return (_jsx("th", { ref: measureColElements.includes(tag) ? (el) => { colRefs.current[tag] = el; } : undefined, style: { "--custom-width": thWidth }, children: _jsxs("div", { className: styles.headcolcell, children: [_jsx(HeadColSort, { tag: tag }), _jsx("div", { className: styles.headcolcellmain, children: search
114
142
  ? _jsx(HeadSearchBar, { content: colTitle, tag: tag })
115
143
  : _jsx("div", { onClick: () => setOpenCol(tag), children: (_b = (_a = HeadColMainLit[colTitle]) === null || _a === void 0 ? void 0 : _a.call(HeadColMainLit, colTitle)) !== null && _b !== void 0 ? _b : colTitle }) })] }) }));
116
144
  };
@@ -138,8 +166,8 @@ export const Table = ({ columns, rows, sortOrder, setSortOrder, cellComponents,
138
166
  var _a;
139
167
  const type = (_a = col.type) !== null && _a !== void 0 ? _a : "def";
140
168
  const CellComponent = cellComponents[type];
141
- return (_jsx("td", { children: _jsx("div", { className: styles.exttablediv, children: _jsx(CellComponent, { row: row, col: col.tag }) }) }, ci));
169
+ return (_jsx("td", { children: _jsx("div", { className: styles.exttablediv, children: _jsx(CellComponent, { row: row, col: col.tag, small: col.small }) }) }, ci));
142
170
  }), _jsx(EndCol, {})] }, `row-${rowIndex}`))) }, 'ext-tbody'));
143
171
  };
144
- return (_jsx(_Fragment, { children: _jsxs("div", { className: `${styles.tablewrapper} ${styles['_tbl']}`, style: { height: `calc(100vh - ${wrapperBottom}px)` }, 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()] }) }));
172
+ return (_jsx(_Fragment, { children: _jsxs("div", { className: `${styles.tablewrapper} ${styles['_tbl']}`, style: { height: `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()] }) }));
145
173
  };
@@ -1,43 +1,3 @@
1
- /* --------------------------
2
- General Settings
3
- -------------------------- */
4
- html,
5
- body,
6
- input,
7
- textarea {
8
- height: 100%;
9
- font-family: Arial, sans-serif;
10
- font-family: Inter, sans-serif;
11
- font-style: 400;
12
- font-optical-sizing: auto;
13
- -webkit-font-smoothing: antialiased;
14
- text-rendering: optimizelegibility;
15
- letter-spacing: 0.072px;
16
- overflow: hidden;
17
- color: #222;
18
- }
19
-
20
- html,
21
- body {
22
- margin: 0;
23
- padding: 0;
24
- width: 100%;
25
- height: 100%;
26
- }
27
-
28
- html,
29
- body {
30
- touch-action: none;
31
- overscroll-behavior: none;
32
- }
33
-
34
- * {
35
- margin: 0;
36
- padding: 0;
37
- box-sizing: border-box;
38
- user-select: none;
39
- }
40
-
41
1
  /* --------------------------
42
2
  TableView
43
3
  -------------------------- */
@@ -208,7 +168,6 @@ svg.removesearchsvg{
208
168
  --input-padding: 1px 5px 3px 0;
209
169
  }
210
170
 
211
-
212
171
  .focused {
213
172
  border: var(--ext-search-wrapper-focused-border, 1px dashed white);
214
173
  color: white;
@@ -505,7 +464,7 @@ RIPPLE
505
464
  position: relative;
506
465
  color: var(--ext-table-date-tag-clr, black);
507
466
  padding: 3px 6px;
508
- border-radius: 4px;
467
+ border-radius: var(--ext-table-date-br, 4px);
509
468
  font-size: 0.65rem;
510
469
  font-weight: 600;
511
470
  display: inline-block;
@@ -514,7 +473,10 @@ RIPPLE
514
473
  white-space: nowrap;
515
474
  width: fit-content;
516
475
  z-index: 0;
476
+ min-height: var(--ext-table-min-wh, 15px);
477
+ min-width: var(--ext-table-min-wh, 15px);
517
478
  }
479
+
518
480
  .dateTag::before {
519
481
  content: "";
520
482
  position: absolute;
@@ -522,10 +484,15 @@ RIPPLE
522
484
  background-color: var(--ext-table-date-tag-bck-clr, darkgrey);
523
485
  opacity: 0.7;
524
486
  /* dim background */
525
- border-radius: 4px;
487
+ border-radius: var(--ext-table-date-br, 4px);
526
488
  z-index: -1;
527
489
  }
528
490
 
491
+ .dateTagSmall{
492
+ --ext-table-date-br: 50px;
493
+ --ext-table-min-wh: 20px;
494
+ }
495
+
529
496
  .dateTagUnknown {
530
497
  --ext-table-date-tag-bck-clr: darkgray;
531
498
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ehscan-react-table",
3
- "version": "0.0.29",
3
+ "version": "0.0.30",
4
4
  "description": "components",
5
5
  "main": "dist/Components.js",
6
6
  "types": "dist/Components.d.ts",