ehscan-react-table 0.0.20 → 0.0.22

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.
@@ -8,5 +8,5 @@ export const TableCellDueDate = ({ content, id, col, clickRow }) => {
8
8
  ? '-'
9
9
  : _jsx("span", { className: `${styles.dateTag} ${styles[calcDateDiff(valDate)]}`, children: formatToDDMMYYYY(valDate) });
10
10
  };
11
- return (_jsx("div", { onClick: () => clickRow({ id, col, type: 'default' }), children: _jsx(DateContent, { value: content }) }));
11
+ return (_jsx("div", { onClick: () => clickRow({ id, col, type: 'default' }), style: { width: "100%", textAlign: "center" }, children: _jsx(DateContent, { value: content }) }));
12
12
  };
@@ -32,16 +32,14 @@ export const Table = ({ columns, rows, sortOrder, setSortOrder, cellComponents,
32
32
  const calculateHeight = () => {
33
33
  if (headerRef.current) {
34
34
  const { bottom } = headerRef.current.getBoundingClientRect();
35
- setWrapperBottom(bottom);
35
+ console.log(bottom);
36
+ setWrapperBottom(bottom + 20);
36
37
  }
37
38
  };
38
39
  calculateHeight();
39
40
  window.addEventListener("resize", calculateHeight);
40
41
  return () => window.removeEventListener("resize", calculateHeight);
41
42
  }, []);
42
- useEffect(() => {
43
- console.log(wrapperBottom);
44
- }, [wrapperBottom]);
45
43
  const checkHead = (entry) => {
46
44
  if (entry === undefined)
47
45
  return;
@@ -98,12 +96,32 @@ export const Table = ({ columns, rows, sortOrder, setSortOrder, cellComponents,
98
96
  const HeadColSort = ({ tag }) => {
99
97
  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, {})] }) }));
100
98
  };
99
+ const colRefs = useRef({});
101
100
  const HeadColMain = ({ col }) => {
102
101
  const { tag, search, title, width } = col;
102
+ const shouldMeasure = ['duedate'].includes(tag);
103
103
  const colTitle = title !== undefined ? title : tag;
104
104
  const thWidth = width !== undefined ? `${width}px` : "30px";
105
- return (_jsx("th", { style: { "--custom-width": thWidth }, children: _jsxs("div", { className: styles.headcolcell, children: [_jsx(HeadColSort, { tag: tag }), _jsx("div", { className: styles.headcolcellmain, children: search ? _jsx(HeadSearchBar, { content: colTitle, tag: tag }) : _jsx("div", { onClick: () => setOpenCol(tag), children: colTitle }) })] }) }));
105
+ 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
106
+ ? _jsx(HeadSearchBar, { content: colTitle, tag: tag })
107
+ : _jsx("div", { onClick: () => setOpenCol(tag), children: colTitle }) })] }) }));
106
108
  };
109
+ useEffect(() => {
110
+ const observer = new ResizeObserver((entries) => {
111
+ entries.forEach((entry) => {
112
+ const tag = Object.keys(colRefs.current).find(k => colRefs.current[k] === entry.target);
113
+ if (tag) {
114
+ const width = entry.contentRect.width;
115
+ console.log(`Column "${tag}" resized to:`, width);
116
+ }
117
+ });
118
+ });
119
+ Object.values(colRefs.current).forEach((el) => {
120
+ if (el)
121
+ observer.observe(el);
122
+ });
123
+ return () => observer.disconnect();
124
+ }, []);
107
125
  const HeadCols = () => {
108
126
  return (_jsxs(_Fragment, { children: [columns.map((col, i) => {
109
127
  const { tag, type, width } = col;
@@ -212,7 +212,7 @@ svg.removesearchsvg{
212
212
  .focused {
213
213
  border: var(--ext-search-wrapper-focused-border, 1px dashed white);
214
214
  color: white;
215
- --input-padding: 1px 5px 3px 5px;
215
+ --input-padding: 1px 5px 3px 10px;
216
216
  }
217
217
 
218
218
  input.headsearch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ehscan-react-table",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
4
4
  "description": "components",
5
5
  "main": "dist/Components.js",
6
6
  "types": "dist/Components.d.ts",