@agilant/toga-blox 1.0.217 → 1.0.219
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.
|
@@ -40,7 +40,9 @@ const TableCell = ({ cell, isLastCell, expanded, onToggle, maxCharacters = DEFAU
|
|
|
40
40
|
}, [needsToggle, onCellOverflow]);
|
|
41
41
|
return (_jsx("td", { ...safeCellProps, className: isStickyColumn ? undefined : isLastCell ? "" : baseTd, children: _jsx("div", { className: wrapper, style: { maxWidth: `${cellMaxWidthWhenExpanded}ch` }, children: needsToggle ? (!expanded ? (_jsx(ToggleComponent, { expanded: expanded, onToggle: onToggle, truncated: truncated, fullText: fullText, className: additionalCellClassNames, linkTextClassNames: linkTextClassNames })) : (_jsxs("div", { className: "flex flex-col min-w-full", style: {
|
|
42
42
|
maxWidth: `${cellMaxWidthWhenExpanded}ch`,
|
|
43
|
-
}, children: [_jsx("span", { className: `text-left pr-5 ${cellTextClassNames}`, children: fullText }), _jsx("span", { children: expandedCellActionButton
|
|
43
|
+
}, children: [_jsx("span", { className: `text-left pr-5 ${cellTextClassNames}`, children: fullText }), _jsx("span", { children: typeof expandedCellActionButton === "function"
|
|
44
|
+
? expandedCellActionButton(fullText)
|
|
45
|
+
: expandedCellActionButton }), _jsx("span", { onClick: (e) => {
|
|
44
46
|
e.stopPropagation();
|
|
45
47
|
onToggle();
|
|
46
48
|
}, className: linkTextClassNames, children: "Show less" })] }))) : (cell.render("Cell")) }) }, cellKey));
|
|
@@ -37,5 +37,5 @@ export interface TableCellProps {
|
|
|
37
37
|
linkTextClassNames?: string;
|
|
38
38
|
cellTextClassNames: string;
|
|
39
39
|
onCellOverflow?: (isOverflowing: boolean) => void;
|
|
40
|
-
expandedCellActionButton?: ReactNode;
|
|
40
|
+
expandedCellActionButton?: ReactNode | ((fullText: string) => ReactNode);
|
|
41
41
|
}
|
|
@@ -4,35 +4,33 @@ import { DataWithUUID, ToggleProps } from "../TableCell";
|
|
|
4
4
|
export interface TableRowProps<T extends DataWithUUID> extends HTMLAttributes<HTMLTableRowElement> {
|
|
5
5
|
row: Row<T>;
|
|
6
6
|
prepareRow: (row: Row<T>) => void;
|
|
7
|
-
rowUuid?: string;
|
|
8
7
|
activeIndex?: number;
|
|
9
8
|
activeRowColor?: string;
|
|
10
9
|
rowHoverClasses?: string;
|
|
11
10
|
hasInfiniteScroll: boolean;
|
|
11
|
+
rowUuid?: string;
|
|
12
|
+
cellTextClassNames?: string;
|
|
13
|
+
onRowClick: (index: number, rowUuid: string, event: React.MouseEvent<HTMLTableRowElement, MouseEvent>) => void;
|
|
12
14
|
cellExpandable?: boolean;
|
|
13
15
|
expandedCells: Record<string, boolean>;
|
|
14
16
|
toggleCell: (key: string) => void;
|
|
15
17
|
ToggleComponent?: React.ComponentType<ToggleProps>;
|
|
16
18
|
hasDropDown?: boolean;
|
|
17
|
-
expandedRowUuid?: string | null;
|
|
18
|
-
onToggleRow?: (uuid: string) => void;
|
|
19
19
|
onFetchRowData?: (uuid: string) => Promise<void> | void;
|
|
20
20
|
loadingIndicator?: ReactNode;
|
|
21
21
|
errorIndicator?: (error: Error) => ReactNode;
|
|
22
22
|
expandedContent?: ReactNode;
|
|
23
23
|
linkTextClassNames?: string;
|
|
24
24
|
rowClassNames?: string;
|
|
25
|
-
cellTextClassNames?: string;
|
|
26
25
|
maxCharacters: number;
|
|
26
|
+
expandedRowUuid?: string | null;
|
|
27
|
+
onToggleRow?: (uuid: string) => void;
|
|
27
28
|
cellColor: string;
|
|
28
29
|
cellMaxWidthWhenExpanded: number;
|
|
29
30
|
additionalCellClassNames: string;
|
|
30
|
-
|
|
31
|
+
toggleComponent?: React.ComponentType<ToggleProps>;
|
|
31
32
|
onRowOverflow?: (rowUuid: string, hasOverflow: boolean) => void;
|
|
32
|
-
/**
|
|
33
|
-
* Element to render in each expanded cell and in the row-level dropdown
|
|
34
|
-
*/
|
|
35
33
|
expandedCellActionButton?: ReactNode;
|
|
36
34
|
}
|
|
37
|
-
declare const TableRow: <T extends DataWithUUID>({ row, prepareRow, activeIndex, activeRowColor, rowHoverClasses, rowClassNames, hasInfiniteScroll,
|
|
35
|
+
declare const TableRow: <T extends DataWithUUID>({ row, prepareRow, activeIndex, activeRowColor, rowHoverClasses, rowClassNames, hasInfiniteScroll, rowUuid, onRowClick, expandedCells, toggleCell, hasDropDown, onFetchRowData, loadingIndicator, errorIndicator, expandedContent, expandedRowUuid, cellExpandable, onToggleRow, maxCharacters, cellColor, cellMaxWidthWhenExpanded, additionalCellClassNames, toggleComponent, linkTextClassNames, cellTextClassNames, onRowOverflow, expandedCellActionButton, }: TableRowProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
38
36
|
export default TableRow;
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// src/components/TableRow/TableRow.tsx
|
|
2
3
|
import { Fragment, useState, useCallback, } from "react";
|
|
3
4
|
import { motion, AnimatePresence } from "framer-motion";
|
|
4
5
|
import TableCell from "../TableCell";
|
|
5
|
-
const TableRow = ({ row, prepareRow, activeIndex, activeRowColor = "bg-pink-100", rowHoverClasses = "hover:bg-navy-100 hover:cursor-pointer", rowClassNames = "", hasInfiniteScroll,
|
|
6
|
-
// ensure we always have an actionable element even if null was passed
|
|
7
|
-
const actionButton = expandedCellActionButton ?? (_jsx("span", { className: "text-blue-500", children: "Action button here" }));
|
|
6
|
+
const TableRow = ({ row, prepareRow, activeIndex, activeRowColor = "bg-pink-100", rowHoverClasses = "hover:bg-navy-100 hover:cursor-pointer", rowClassNames = "", hasInfiniteScroll, rowUuid, onRowClick, expandedCells, toggleCell, hasDropDown = false, onFetchRowData, loadingIndicator, errorIndicator, expandedContent, expandedRowUuid = null, cellExpandable = false, onToggleRow, maxCharacters = 30, cellColor = "bg-blue-50", cellMaxWidthWhenExpanded = 50, additionalCellClassNames = "", toggleComponent = undefined, linkTextClassNames = "", cellTextClassNames = "", onRowOverflow = () => { }, expandedCellActionButton = (_jsx("span", { className: "text-blue-500", children: "Action button here" })), }) => {
|
|
8
7
|
prepareRow(row);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
extraRowClasses;
|
|
8
|
+
prepareRow(row);
|
|
9
|
+
const rowClasses = `border-primary${activeIndex === row.index ? ` activeRow ${activeRowColor}` : ""}`;
|
|
12
10
|
const [overflowMap, setOverflowMap] = useState({});
|
|
11
|
+
/* keep fetch/loading local */
|
|
13
12
|
const [isLoading, setIsLoading] = useState(false);
|
|
14
13
|
const [error, setError] = useState(null);
|
|
14
|
+
/* determine if *this* row is open */
|
|
15
15
|
const isExpanded = hasDropDown && rowUuid === expandedRowUuid;
|
|
16
16
|
const handleRowClick = async (e) => {
|
|
17
17
|
onRowClick(row.index, rowUuid ?? "", e);
|
|
18
18
|
if (hasDropDown && rowUuid && onToggleRow) {
|
|
19
19
|
onToggleRow(rowUuid);
|
|
20
20
|
if (!isExpanded && onFetchRowData) {
|
|
21
|
-
setIsLoading(true);
|
|
22
|
-
setError(null);
|
|
23
21
|
try {
|
|
22
|
+
setIsLoading(true);
|
|
23
|
+
setError(null);
|
|
24
24
|
await onFetchRowData(rowUuid);
|
|
25
25
|
}
|
|
26
26
|
catch (err) {
|
|
@@ -37,16 +37,22 @@ const TableRow = ({ row, prepareRow, activeIndex, activeRowColor = "bg-pink-100"
|
|
|
37
37
|
setOverflowMap((m) => {
|
|
38
38
|
const next = { ...m, [cellKey]: isOverflowing };
|
|
39
39
|
const anyOverflow = Object.values(next).some(Boolean);
|
|
40
|
+
// notify parent of overall row overflow
|
|
40
41
|
onRowOverflow?.(rowUuid, anyOverflow);
|
|
41
42
|
return next;
|
|
42
43
|
});
|
|
43
44
|
}, [onRowOverflow, rowUuid]);
|
|
45
|
+
// Fix: Key is discarded from the spread obj, react still gets key just not from spread i.e. key={rowUuid}
|
|
46
|
+
// Pull props ahead of time and separate out 'key'
|
|
47
|
+
// If row.getRowProps exists, call function, else use empty
|
|
48
|
+
// _ignoredKey extracts the key prop and stores it, it will be discarded
|
|
49
|
+
// ...safeRowProps gathers remaining props except key into obj using '...'
|
|
44
50
|
const { key: _ignoredKey, ...safeRowProps } = row.getRowProps
|
|
45
51
|
? row.getRowProps()
|
|
46
52
|
: {};
|
|
47
|
-
return (_jsxs(Fragment, { children: [_jsx("tr", { "data-testid": "table-row", className: rowClasses
|
|
53
|
+
return (_jsxs(Fragment, { children: [_jsx("tr", { "data-testid": "table-row", className: `border-b border-b-navy-200 ${rowHoverClasses} ${rowClasses} ${rowClassNames}`, onClick: handleRowClick, ...safeRowProps, children: row.cells.map((cell, idx) => {
|
|
48
54
|
const cellKey = `${rowUuid ?? "no-uuid"}-${cell.column.id}`;
|
|
49
|
-
return (_jsx(TableCell, { cell: cell, isLastCell: idx === row.cells.length - 1, hasInfiniteScroll: hasInfiniteScroll, cellExpandable: cellExpandable, expanded: expandedCells[cellKey] ?? false, onToggle: () => toggleCell(cellKey), linkTextClassNames: linkTextClassNames, maxCharacters: maxCharacters, cellColor: cellColor, cellMaxWidthWhenExpanded: cellMaxWidthWhenExpanded, additionalCellClassNames: additionalCellClassNames, toggleComponent:
|
|
50
|
-
}) }, rowUuid), hasDropDown && (_jsx(AnimatePresence, { children: isExpanded && (_jsx("tr", { "data-testid": "expanded-row", children: _jsx("td", { colSpan: row.cells.length, className: "p-0", children: _jsx(motion.div, { initial: { height: 0, opacity: 0 }, animate: { height: "auto", opacity: 1 }, exit: { height: 0, opacity: 0 }, transition: { duration: 0.3 }, className: "overflow-hidden w-full
|
|
55
|
+
return (_jsx(TableCell, { cell: cell, isLastCell: idx === row.cells.length - 1, hasInfiniteScroll: hasInfiniteScroll, cellExpandable: cellExpandable, expanded: expandedCells[cellKey] ?? false, onToggle: () => toggleCell(cellKey), linkTextClassNames: linkTextClassNames, maxCharacters: maxCharacters, cellColor: cellColor, cellMaxWidthWhenExpanded: cellMaxWidthWhenExpanded, additionalCellClassNames: additionalCellClassNames, toggleComponent: toggleComponent, cellTextClassNames: cellTextClassNames, onCellOverflow: (isOverflowing) => handleOverflow(cellKey, isOverflowing), expandedCellActionButton: expandedCellActionButton }, cellKey));
|
|
56
|
+
}) }, rowUuid), hasDropDown && (_jsx(AnimatePresence, { children: isExpanded && (_jsx("tr", { "data-testid": "expanded-row", children: _jsx("td", { colSpan: row.cells.length, className: "p-0", children: _jsx(motion.div, { initial: { height: 0, opacity: 0 }, animate: { height: "auto", opacity: 1 }, exit: { height: 0, opacity: 0 }, transition: { duration: 0.3 }, className: "overflow-hidden w-full", children: isLoading ? (loadingIndicator ?? (_jsx("span", { children: "Loading..." }))) : error ? (errorIndicator ? (errorIndicator(error)) : (_jsxs("span", { className: "text-red-700", children: ["Error: ", error.message] }))) : (expandedContent ?? (_jsxs("span", { children: ["drop down \u2013 ", rowUuid] }))) }, "expanded-dropdown-content") }) })) }))] }));
|
|
51
57
|
};
|
|
52
58
|
export default TableRow;
|
|
@@ -102,7 +102,7 @@ const Template = (args) => {
|
|
|
102
102
|
// ── **new** single-row expansion state ──
|
|
103
103
|
const [expandedRowUuid, setExpandedRowUuid] = React.useState(null);
|
|
104
104
|
const onToggleRow = React.useCallback((uuid) => setExpandedRowUuid((prev) => (prev === uuid ? null : uuid)), []);
|
|
105
|
-
return (_jsxs(_Fragment, { children: [_jsxs("div", { style: { marginBottom: 12 }, children: ["\uD83D\uDEA8 Row overflow?", " ", _jsx("strong", { children: rowHasOverflow ? "YES" : "no" })] }), _jsx("table", { className: "min-w-[700px]", children: _jsx("tbody", { children: _jsx(TableRow, { additionalCellClassNames: "", cellColor: "", cellMaxWidthWhenExpanded: 0, row: undefined, prepareRow: function (row) {
|
|
105
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { style: { marginBottom: 12 }, children: ["\uD83D\uDEA8 Row overflow?", " ", _jsx("strong", { children: rowHasOverflow ? "YES" : "no" })] }), _jsx("table", { className: "min-w-[700px]", children: _jsx("tbody", { children: _jsx(TableRow, { expandedCellActionButton: _jsx(_Fragment, { children: "test" }), additionalCellClassNames: "", cellColor: "", cellMaxWidthWhenExpanded: 0, row: undefined, prepareRow: function (row) {
|
|
106
106
|
throw new Error("Function not implemented.");
|
|
107
107
|
}, ...args, expandedCells: expandedCells, toggleCell: toggleCell, hasInfiniteScroll: args.hasInfiniteScroll ?? true, onRowClick: args.onRowClick ?? (() => alert("from row")), expandedRowUuid: expandedRowUuid, onToggleRow: onToggleRow, maxCharacters: 30, onRowOverflow: (_uuid, anyOverflow) => {
|
|
108
108
|
console.log("onRowOverflow:", anyOverflow);
|