@harjs/react-ui 1.1.8 → 1.1.9
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.
|
@@ -6,14 +6,17 @@ import Editable from "./Editable";
|
|
|
6
6
|
import TableTR from "../../../../libs/core/application/locales/table/tr";
|
|
7
7
|
import TableEN from "../../../../libs/core/application/locales/table/en";
|
|
8
8
|
import { useTranslation } from "@harjs/translation";
|
|
9
|
-
const SubitemList = ({ items, columns, depth, level = 1, parentKey = "", config, methods, states, renderCell, }) => {
|
|
9
|
+
const SubitemList = ({ parentItem, items, columns, depth, level = 1, parentKey = "", config, methods, states, renderCell, }) => {
|
|
10
10
|
const _subrowSelector = config.subrow?.selector ?? "subitems";
|
|
11
11
|
const _subrowButton = config.subrow?.button ?? true;
|
|
12
12
|
if (config.subrow?.render) {
|
|
13
13
|
return (React.createElement("tr", { className: `subrow-item ${_subrowButton ? "type-b" : "type-a"}`, "data-level": level },
|
|
14
14
|
methods.selections && React.createElement("td", { className: "sticky sticky-left", "data-sticky-position": "left" }),
|
|
15
15
|
_subrowButton && React.createElement("td", { className: "sticky sticky-left", "data-sticky-position": "left" }),
|
|
16
|
-
React.createElement("td", { colSpan: columns.length || 1, style: {
|
|
16
|
+
React.createElement("td", { colSpan: states.columnNumber.get || columns.length || 1, style: {
|
|
17
|
+
...config.subrow.render.styles,
|
|
18
|
+
padding: "var(--space-8)",
|
|
19
|
+
}, ...(states.columnNumber.get > 0 ? { className: "sticky sticky-left", "data-sticky-position": "left" } : {}) }, config.subrow?.render.element(parentItem, items) ?? React.createElement(React.Fragment, null))));
|
|
17
20
|
}
|
|
18
21
|
return (React.createElement(React.Fragment, null, items.map((subitem, subindex) => {
|
|
19
22
|
const id = methods.trackBy?.(subitem) ?? `sub-${subindex}`;
|
|
@@ -40,7 +43,7 @@ const SubitemList = ({ items, columns, depth, level = 1, parentKey = "", config,
|
|
|
40
43
|
height: 0,
|
|
41
44
|
isSubrows: true,
|
|
42
45
|
}))),
|
|
43
|
-
states.showSubitems.get[key] && _subitem && (React.createElement(SubitemList, { items: _subitem, columns: columns, depth: depth + 0.75, level: level + 1, parentKey: key, config: config, methods: methods, states: states, renderCell: renderCell }))));
|
|
46
|
+
states.showSubitems.get[key] && _subitem && (React.createElement(SubitemList, { parentItem: subitem, items: _subitem, columns: columns, depth: depth + 0.75, level: level + 1, parentKey: key, config: config, methods: methods, states: states, renderCell: renderCell }))));
|
|
44
47
|
})));
|
|
45
48
|
};
|
|
46
49
|
function TBody({ data, columns, refs, methods, states, config }) {
|
|
@@ -147,7 +150,7 @@ function TBody({ data, columns, refs, methods, states, config }) {
|
|
|
147
150
|
level: 0,
|
|
148
151
|
height: currentRowHeight,
|
|
149
152
|
}))),
|
|
150
|
-
states.showSubitems.get[key] && _subitem && (React.createElement(SubitemList, { items: _subitem, columns: columns, depth: 1.5, parentKey: key, config: config, methods: methods, states: states, renderCell: renderCell }))));
|
|
153
|
+
states.showSubitems.get[key] && _subitem && (React.createElement(SubitemList, { parentItem: item, items: _subitem, columns: columns, depth: 1.5, parentKey: key, config: config, methods: methods, states: states, renderCell: renderCell }))));
|
|
151
154
|
};
|
|
152
155
|
// useEffects
|
|
153
156
|
useEffect(() => {
|
|
@@ -24,6 +24,7 @@ import TableTR from "../../../libs/core/application/locales/table/tr";
|
|
|
24
24
|
import TableEN from "../../../libs/core/application/locales/table/en";
|
|
25
25
|
const { Row, Column } = Grid;
|
|
26
26
|
const Table = forwardRef(({ children, trackBy, title, description, data, columns, actions, rowBackgroundColor, selections, selectionDisabled, previousSelections, sortedParams, searchedParams, onEditable, onDnD, pagination, config = { isSearchable: false }, }, ref) => {
|
|
27
|
+
// refs
|
|
27
28
|
const _innerRef = useRef(null);
|
|
28
29
|
const _tableWrapper = useRef(null);
|
|
29
30
|
const _tableContent = useRef(null);
|
|
@@ -41,6 +42,8 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
|
|
|
41
42
|
const _subrowSelector = config.subrow?.selector ?? "subitems";
|
|
42
43
|
const _subrowButton = config.subrow?.button ?? false;
|
|
43
44
|
const _tableClassName = ["ar-table", "scroll"];
|
|
45
|
+
// states
|
|
46
|
+
const [columnNumber, setColumnNumber] = useState(0);
|
|
44
47
|
const [selectAll, setSelectAll] = useState(false);
|
|
45
48
|
const [showSubitems, setShowSubitems] = useState({});
|
|
46
49
|
const [createTrigger, setCreateTrigger] = useState(false);
|
|
@@ -323,6 +326,22 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
|
|
|
323
326
|
setTimeout(() => handleScroll(), 0);
|
|
324
327
|
return _data;
|
|
325
328
|
}, [data, searchedText, currentPage, selectedPerPage, sortConfig, config.isServerSide]);
|
|
329
|
+
useEffect(() => {
|
|
330
|
+
if (columns.length === 0 && config.subrow?.render)
|
|
331
|
+
return;
|
|
332
|
+
const _tableW = _tableWrapper.current;
|
|
333
|
+
if (!_tableW)
|
|
334
|
+
return;
|
|
335
|
+
const { right } = _tableW?.getBoundingClientRect();
|
|
336
|
+
const _th = _tableW.querySelectorAll("thead > tr > th");
|
|
337
|
+
let i = 0;
|
|
338
|
+
_th?.forEach((th) => {
|
|
339
|
+
const thRect = th.getBoundingClientRect();
|
|
340
|
+
if (thRect.left < right)
|
|
341
|
+
i++;
|
|
342
|
+
});
|
|
343
|
+
setColumnNumber(i - 1);
|
|
344
|
+
}, [columns]);
|
|
326
345
|
useEffect(() => {
|
|
327
346
|
if (!previousSelections || previousSelections.length === 0) {
|
|
328
347
|
_selectionItems.current = [];
|
|
@@ -604,6 +623,7 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
|
|
|
604
623
|
})))),
|
|
605
624
|
React.createElement("tbody", { ref: _tBody },
|
|
606
625
|
React.createElement(TBody, { data: getData, columns: columns, refs: { _checkboxItems: _checkboxItems, _selectionItems: _selectionItems }, states: {
|
|
626
|
+
columnNumber: { get: columnNumber },
|
|
607
627
|
setSelectAll: { get: selectAll, set: setSelectAll },
|
|
608
628
|
showSubitems: { get: showSubitems, set: setShowSubitems },
|
|
609
629
|
}, methods: {
|