@agilant/toga-blox 1.0.39 → 1.0.41
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.
- package/dist/components/SortArrows/SortArrows.d.ts +1 -1
- package/dist/components/SortArrows/SortArrows.js +2 -2
- package/dist/components/SortArrows/SortArrows.stories.js +1 -1
- package/dist/components/SortArrows/types.d.ts +1 -0
- package/dist/components/TableRow/TableRow.d.ts +27 -6
- package/dist/components/TableRow/TableRow.js +1 -3
- package/dist/components/TableRow/TableRow.test.js +12 -5
- package/dist/components/TableRow/types.d.ts +1 -0
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SortArrowsProps } from "./types";
|
|
2
|
-
declare const SortArrows: <T extends object>({ column, setSortColumn, slug, isNested, parentIndex, onSortChange, renderPortalOverlay, onRequestClose, counterIcon, }: SortArrowsProps<T> & {
|
|
2
|
+
declare const SortArrows: <T extends object>({ column, setSortColumn, slug, isNested, parentIndex, onSortChange, renderPortalOverlay, onRequestClose, counterIcon, directionContainerClassNames, }: SortArrowsProps<T> & {
|
|
3
3
|
getFontAwesomeIconFn?: (iconName: string, iconStyle: string) => React.ReactElement | null;
|
|
4
4
|
}) => JSX.Element | null;
|
|
5
5
|
export default SortArrows;
|
|
@@ -10,7 +10,7 @@ const SortArrows = ({ column, setSortColumn, slug, isNested, parentIndex, onSort
|
|
|
10
10
|
numberClassNames: "absolute text-xs top-1.5 right-0 left-0",
|
|
11
11
|
iconClassNames: "text-lg text-blue-400 relative hover:text-red-400",
|
|
12
12
|
numberSize: "text-xl",
|
|
13
|
-
}, }) => {
|
|
13
|
+
}, directionContainerClassNames = "z-[9989] bg-white rounded flex flex-col border-1 absolute top-6 w-32", }) => {
|
|
14
14
|
const containerRef = useRef(null);
|
|
15
15
|
const { showArrowContainer, handleParentClick, handleResetSort, handleClick, isActive, activeDirection, sortOrderNumber, setShowArrowContainer, } = useSortArrowsViewModel({
|
|
16
16
|
columnId: String(column.accessor),
|
|
@@ -26,7 +26,7 @@ const SortArrows = ({ column, setSortColumn, slug, isNested, parentIndex, onSort
|
|
|
26
26
|
setShowArrowContainer(false);
|
|
27
27
|
onRequestClose?.();
|
|
28
28
|
};
|
|
29
|
-
return (_jsxs("div", { "data-testid": `sort-arrows-${slug}`, ref: containerRef, className: arrowContainerClassNames, onClick: handleParentClick, children: [isActive && (_jsxs("div", { className: "relative", children: [_jsx("div", { className: `${counterIcon.iconClassNames} ${activeDirection === "desc" ? "rotate-180" : ""}`, children: _jsx("span", { className: `${counterIcon?.numberSize}`, children: getFontAwesomeIcon(counterIcon.icon, counterIcon.weight) }) }), _jsx("span", { className: `${counterIcon.numberClassNames} ${activeDirection === "desc" && " pb-0.5"}`, children: sortOrderNumber })] })), !isActive && (_jsxs(_Fragment, { children: [_jsx(SortArrowIcon, { slug: slug, parentIndex: parentIndex, columnName: String(column.render("Header")), direction: "up", setColumn: () => { }, isActive: false }), _jsx(SortArrowIcon, { slug: slug, parentIndex: parentIndex, columnName: String(column.render("Header")), direction: "down", setColumn: () => { }, isActive: false })] })), showArrowContainer && (_jsxs(motion.div, { className:
|
|
29
|
+
return (_jsxs("div", { "data-testid": `sort-arrows-${slug}`, ref: containerRef, className: arrowContainerClassNames, onClick: handleParentClick, children: [isActive && (_jsxs("div", { className: "relative", children: [_jsx("div", { className: `${counterIcon.iconClassNames} ${activeDirection === "desc" ? "rotate-180" : ""}`, children: _jsx("span", { className: `${counterIcon?.numberSize}`, children: getFontAwesomeIcon(counterIcon.icon, counterIcon.weight) }) }), _jsx("span", { className: `${counterIcon.numberClassNames} ${activeDirection === "desc" && " pb-0.5"}`, children: sortOrderNumber })] })), !isActive && (_jsxs(_Fragment, { children: [_jsx(SortArrowIcon, { slug: slug, parentIndex: parentIndex, columnName: String(column.render("Header")), direction: "up", setColumn: () => { }, isActive: false }), _jsx(SortArrowIcon, { slug: slug, parentIndex: parentIndex, columnName: String(column.render("Header")), direction: "down", setColumn: () => { }, isActive: false })] })), showArrowContainer && (_jsxs(motion.div, { className: `${directionContainerClassNames} ${column.id === "col1" ? "left-[5px]" : ""}`, initial: "initial", animate: "animate", exit: "exit", children: [activeDirection !== "asc" && (_jsxs("div", { className: "flex border-b-1 p-1 hover:bg-blue-50", onClick: () => handleClick("up"), children: [_jsx("span", { className: "pl-1 text-primary", children: getFontAwesomeIcon("arrowUp", "regular") }), _jsx("span", { className: "flex-1 text-left pl-4", children: "Ascending" })] })), activeDirection !== "desc" && (_jsxs("div", { className: "flex p-1 hover:bg-blue-50 border-b-1", onClick: () => handleClick("down"), children: [_jsx("span", { className: "pl-1 text-primary", children: getFontAwesomeIcon("arrowDown", "regular") }), _jsx("span", { className: "flex-1 text-left pl-4", children: "Descending" })] })), isActive && (_jsxs("div", { className: "flex border-b-1 p-1 hover:bg-blue-50", onClick: handleResetSort, children: [_jsx("span", { className: "pl-1 text-primary", children: getFontAwesomeIcon("rotateLeft", "solid") }), _jsx("span", { className: "flex-1 text-left pl-3", children: "Reset" })] }))] })), showArrowContainer &&
|
|
30
30
|
renderPortalOverlay &&
|
|
31
31
|
renderPortalOverlay(handleClose)] }));
|
|
32
32
|
};
|
|
@@ -36,6 +36,6 @@ export const WithOverlayAndIndexCount = {
|
|
|
36
36
|
numberClassNames: " absolute bottom-1.5 left-[10px] text-xs",
|
|
37
37
|
iconClassNames: "text-green-500 hover:text-red-400 text-2xl",
|
|
38
38
|
numberSize: " text-red-500 top-0",
|
|
39
|
-
}, column: column, setSortColumn: setSortColumn, slug: "products", renderPortalOverlay: (onClose) => (_jsx("div", { className: "absolute top-0 left-0 w-[300px] h-[300px] bg-black bg-opacity-50 flex items-center justify-center", onClick: onClose })) }) }));
|
|
39
|
+
}, column: column, setSortColumn: setSortColumn, slug: "products", renderPortalOverlay: (onClose) => (_jsx("div", { className: "absolute top-0 left-0 w-[300px] h-[300px] bg-black bg-opacity-50 flex items-center justify-center", onClick: onClose })), directionContainerClassNames: "absolute top-6 w-32 bg-white rounded flex flex-col border-1 z-[9989]" }) }));
|
|
40
40
|
},
|
|
41
41
|
};
|
|
@@ -15,6 +15,7 @@ export interface SortArrowsProps<T extends object> {
|
|
|
15
15
|
iconClassNames?: string;
|
|
16
16
|
numberSize?: string;
|
|
17
17
|
};
|
|
18
|
+
directionContainerClassNames?: string;
|
|
18
19
|
}
|
|
19
20
|
export interface CustomColumnInstance<T extends object> extends ColumnInstance<T> {
|
|
20
21
|
accessor: string | number | symbol | ((row: T) => any);
|
|
@@ -1,15 +1,36 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Row } from "react-table";
|
|
1
3
|
import { DataWithUUID } from "../TableCell";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The props for your reusable TableRow component.
|
|
6
|
+
*
|
|
7
|
+
* @template T - extends DataWithUUID
|
|
8
|
+
*/
|
|
9
|
+
export interface TableRowProps<T extends DataWithUUID> {
|
|
10
|
+
/** The row object from react-table */
|
|
11
|
+
row: Row<T>;
|
|
12
|
+
/** Function from react-table to prepare the row. */
|
|
13
|
+
prepareRow: (row: Row<T>) => void;
|
|
14
|
+
/** Optionally mark this row as active, comparing row.index to activeIndex. */
|
|
6
15
|
activeIndex?: number;
|
|
16
|
+
/** Class to apply if the row is active. */
|
|
7
17
|
activeRowColor?: string;
|
|
18
|
+
/** Globally enable/disable "trim" on cells. */
|
|
8
19
|
globalTrimActive?: boolean;
|
|
20
|
+
/** A UUID for this row. */
|
|
9
21
|
rowUuid?: string;
|
|
22
|
+
/** Column "inputs" or config array, if relevant to your TableCell. */
|
|
10
23
|
columnInputs?: string[];
|
|
24
|
+
/** Classes for row hover styling. Defaults to "hover:bg-red-100 hover:cursor-pointer" */
|
|
11
25
|
rowHoverClasses?: string;
|
|
12
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Called when the row is clicked.
|
|
28
|
+
*
|
|
29
|
+
* @param index - the row.index from react-table
|
|
30
|
+
* @param rowUuid - the row's UUID
|
|
31
|
+
* @param event - the click event on the <tr>
|
|
32
|
+
*/
|
|
33
|
+
onRowClick?: (index: number, rowUuid: string, event: React.MouseEvent<HTMLTableRowElement, MouseEvent>) => void;
|
|
13
34
|
}
|
|
14
|
-
declare const TableRow: <T extends DataWithUUID>({ row, prepareRow, activeIndex, globalTrimActive, rowUuid, columnInputs, activeRowColor, rowHoverClasses, onRowClick, }: TableRowProps) => import("react/jsx-runtime").JSX.Element;
|
|
35
|
+
declare const TableRow: <T extends DataWithUUID>({ row, prepareRow, activeIndex, globalTrimActive, rowUuid, columnInputs, activeRowColor, rowHoverClasses, onRowClick, }: TableRowProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
15
36
|
export default TableRow;
|
|
@@ -9,9 +9,7 @@ const TableRow = ({ row, prepareRow, activeIndex, globalTrimActive, rowUuid, col
|
|
|
9
9
|
rowClasses += ` activeRow ${activeRowColor}`;
|
|
10
10
|
}
|
|
11
11
|
return (_jsx("tr", { "data-testid": "table-row", className: `border-b border-b-navy-200 ${rowHoverClasses} ${rowClasses}`, ...(row.getRowProps ? row.getRowProps() : {}), onClick: (event) => {
|
|
12
|
-
|
|
13
|
-
onRowClick(row.index, rowUuid || "", event);
|
|
14
|
-
}
|
|
12
|
+
onRowClick?.(row.index, rowUuid || "", event);
|
|
15
13
|
}, children: row.cells.map((cell, index) => {
|
|
16
14
|
const isLastCell = index === row.cells.length - 1;
|
|
17
15
|
const cellProps = cell.getCellProps();
|
|
@@ -4,16 +4,21 @@ import { render, screen, fireEvent } from "@testing-library/react";
|
|
|
4
4
|
import TableRow from "./TableRow";
|
|
5
5
|
describe("TableRow - Branch Coverage Tests", () => {
|
|
6
6
|
const mockPrepareRow = vi.fn();
|
|
7
|
-
// Basic row object
|
|
8
7
|
const baseMockRow = {
|
|
8
|
+
// REQUIRED BY Row<T>:
|
|
9
|
+
id: "mock-row-id",
|
|
9
10
|
index: 0,
|
|
10
|
-
|
|
11
|
+
original: { uuid: "mock-uuid" },
|
|
12
|
+
subRows: [],
|
|
11
13
|
cells: [
|
|
12
14
|
{
|
|
13
15
|
getCellProps: vi.fn(() => ({ key: "cell-0" })),
|
|
14
16
|
render: vi.fn(() => "Cell 0"),
|
|
15
17
|
},
|
|
16
18
|
],
|
|
19
|
+
allCells: [],
|
|
20
|
+
values: {},
|
|
21
|
+
getRowProps: vi.fn(() => ({ key: "row-props-0" })),
|
|
17
22
|
};
|
|
18
23
|
it("covers isActive = true (row is active)", () => {
|
|
19
24
|
render(_jsx("table", { children: _jsx("tbody", { children: _jsx(TableRow, { row: { ...baseMockRow, index: 5 }, prepareRow: mockPrepareRow, activeIndex: 5 }) }) }));
|
|
@@ -27,18 +32,20 @@ describe("TableRow - Branch Coverage Tests", () => {
|
|
|
27
32
|
const mockOnRowClick = vi.fn();
|
|
28
33
|
render(_jsx("table", { children: _jsx("tbody", { children: _jsx(TableRow, { row: baseMockRow, prepareRow: mockPrepareRow, onRowClick: mockOnRowClick, rowUuid: "some-uuid" }) }) }));
|
|
29
34
|
fireEvent.click(screen.getByTestId("table-row"));
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
expect(mockOnRowClick).toHaveBeenCalledWith(baseMockRow.index, // 0
|
|
36
|
+
"some-uuid", expect.anything() // Synthetic event
|
|
32
37
|
);
|
|
33
38
|
});
|
|
34
39
|
it("covers onRowClick = defined + rowUuid = undefined (so calls empty string)", () => {
|
|
35
40
|
const mockOnRowClick = vi.fn();
|
|
36
41
|
render(_jsx("table", { children: _jsx("tbody", { children: _jsx(TableRow, { row: baseMockRow, prepareRow: mockPrepareRow, onRowClick: mockOnRowClick }) }) }));
|
|
37
42
|
fireEvent.click(screen.getByTestId("table-row"));
|
|
38
|
-
expect(mockOnRowClick).toHaveBeenCalledWith(baseMockRow.index,
|
|
43
|
+
expect(mockOnRowClick).toHaveBeenCalledWith(baseMockRow.index, // 0
|
|
44
|
+
"", expect.anything());
|
|
39
45
|
});
|
|
40
46
|
it("covers onRowClick = NOT defined", () => {
|
|
41
47
|
render(_jsx("table", { children: _jsx("tbody", { children: _jsx(TableRow, { row: baseMockRow, prepareRow: mockPrepareRow }) }) }));
|
|
48
|
+
// onRowClick not provided; just ensure no crash
|
|
42
49
|
fireEvent.click(screen.getByTestId("table-row"));
|
|
43
50
|
});
|
|
44
51
|
});
|
|
@@ -8,4 +8,5 @@ export interface TableRowProps<T extends object> {
|
|
|
8
8
|
columnInputs?: string[];
|
|
9
9
|
rowHoverClasses?: string;
|
|
10
10
|
addRowToClickedRows?: (rowUuid: string) => void;
|
|
11
|
+
onRowClick?: (index: number, rowUuid: string, event: React.MouseEvent<HTMLTableRowElement, MouseEvent>) => void;
|
|
11
12
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agilant/toga-blox",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.41",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -40,7 +40,6 @@
|
|
|
40
40
|
"react-select": "^5.10.0",
|
|
41
41
|
"react-table": "^7.8.0",
|
|
42
42
|
"react-table-sticky": "^1.1.3",
|
|
43
|
-
"sass": "^1.83.4",
|
|
44
43
|
"storybook-addon-react-router-v6": "^2.0.15",
|
|
45
44
|
"tslib": "^2.3.0"
|
|
46
45
|
},
|
|
@@ -70,6 +69,7 @@
|
|
|
70
69
|
"postcss": "^8.4.32",
|
|
71
70
|
"react-hook-form": "^7.43.9",
|
|
72
71
|
"react-router-dom": "^6.16.0",
|
|
72
|
+
"sass": "^1.84.0",
|
|
73
73
|
"storybook": "^7.6.6",
|
|
74
74
|
"tailwindcss": "^3.4.0",
|
|
75
75
|
"typescript": "^5.7.3",
|