@agilant/toga-blox 1.0.200 → 1.0.201

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.
@@ -1,17 +1,3 @@
1
- import { DataWithUUID } from "./types";
2
- export interface TableCellProps<T extends DataWithUUID> {
3
- cell: any;
4
- isLastCell: boolean;
5
- hasInfiniteScroll: boolean;
6
- rowUuid?: string;
7
- expanded: boolean;
8
- onToggle: () => void;
9
- linkText?: string;
10
- cellExpandable?: boolean;
11
- maxCharacters?: number;
12
- cellMaxWidthWhenExpanded?: number;
13
- cellColor: string;
14
- additionalCellClassNames: string;
15
- }
16
- declare const TableCell: <T extends DataWithUUID>({ cell, isLastCell, hasInfiniteScroll, expanded, onToggle, linkText, cellExpandable, maxCharacters, cellMaxWidthWhenExpanded, cellColor, additionalCellClassNames, }: TableCellProps<T>) => import("react/jsx-runtime").JSX.Element;
1
+ import { TableCellProps } from "./types";
2
+ declare const TableCell: ({ cell, isLastCell, hasInfiniteScroll, expanded, onToggle, maxCharacters, cellMaxWidthWhenExpanded, cellColor, additionalCellClassNames, toggleComponent: ToggleComponent, cellExpandable, linkTextClassNames, }: TableCellProps) => import("react/jsx-runtime").JSX.Element;
17
3
  export default TableCell;
@@ -1,28 +1,26 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- const MAX_CHARS = 30;
3
- const TableCell = ({ cell, isLastCell, hasInfiniteScroll, expanded, onToggle, linkText = "text-purple-500 ml-1 underline", cellExpandable = false, maxCharacters, cellMaxWidthWhenExpanded = 50, cellColor = "bg-blue-500", additionalCellClassNames = "", }) => {
4
- /* decide if this cell even needs a toggle */
2
+ const DEFAULT_MAX_CHARS = 30;
3
+ // Default only implements the **collapsed** “Show more” UI.
4
+ // We’ll never use its expanded branch, since expanded is handled below.
5
+ const DefaultCollapsedToggle = ({ onToggle, truncated, className = "", linkTextClassNames = "text-purple-500 ml-1 underline", }) => (_jsx("div", { className: `flex items-center group ${className}`, onClick: (e) => {
6
+ e.stopPropagation();
7
+ onToggle();
8
+ }, children: _jsxs("span", { children: [truncated, "\u2026", _jsx("span", { className: "hidden group-hover:inline text-purple-500 ml-1 underline", children: "Show more" })] }) }));
9
+ const TableCell = ({ cell, isLastCell, hasInfiniteScroll, expanded, onToggle, maxCharacters = DEFAULT_MAX_CHARS, cellMaxWidthWhenExpanded = 50, cellColor = "bg-blue-500", additionalCellClassNames = "", toggleComponent: ToggleComponent = DefaultCollapsedToggle, cellExpandable = false, linkTextClassNames = "text-purple-500 ml-1 underline", }) => {
10
+ // --- truncation logic ---
5
11
  const isString = typeof cell.value === "string";
6
12
  const fullText = isString ? cell.value : "";
7
13
  const isLong = isString && fullText.length > maxCharacters;
8
- const hasToggle = cellExpandable && isLong;
9
14
  const truncated = fullText.slice(0, maxCharacters);
10
- /* stop row click when toggling */
11
- const handleToggle = (e) => {
12
- e.stopPropagation(); // ← prevents bubbling to the <tr>
13
- onToggle();
14
- };
15
+ const needsToggle = cellExpandable && isLong;
16
+ // --- sticky support ---
15
17
  const isStickyColumn = cell?.column?.sticky === "left";
16
- const stickyLeft = isStickyColumn && cell.column?.style
17
- ? cell.column.style.left ?? 0
18
- : 0;
19
- const stickyClass = isStickyColumn ? cell.column?.className || "" : "";
20
- const baseTd = `relative overflow-hidden font-light text-sm text-left px-5 ${cellColor}`;
21
- const wrapper = ` min-h-[40px] flex select-none ${cellColor} ${hasToggle ? " cursor-pointer" : ""}`;
22
- // FIX: extract key before spreading props into <td>
18
+ const baseTd = `relative overflow-hidden font-light text-sm text-left px-5 ${cellColor}`;
19
+ const wrapper = `min-h-[40px] flex select-none ${cellColor} ${needsToggle ? "cursor-pointer" : ""}`;
20
+ // extract key before spreading
23
21
  const rawCellProps = cell.getCellProps({
24
22
  className: isLastCell ? "" : baseTd,
25
- style: cell.column?.sticky === "left"
23
+ style: isStickyColumn
26
24
  ? {
27
25
  position: "sticky",
28
26
  left: cell.column.style?.left || 0,
@@ -30,19 +28,18 @@ const TableCell = ({ cell, isLastCell, hasInfiniteScroll, expanded, onToggle, li
30
28
  }
31
29
  : {},
32
30
  });
33
- const { key: cellKey, ...safeCellProps } = Object.assign({}, rawCellProps);
34
- return (_jsx("td", { ...safeCellProps, className: isStickyColumn ? undefined : isLastCell ? "" : baseTd, children: _jsx("div", { className: wrapper, children: hasToggle ? (!expanded ? (
35
- /* collapsed view */
36
- _jsx("div", { className: `flex items-center group ${additionalCellClassNames}`, children: _jsxs("span", { children: [truncated, "\u2026", _jsx("span", { ...(hasToggle
37
- ? { onClick: handleToggle }
38
- : {}), className: `hidden group-hover:inline ${linkText}`, children: "Show more" })] }) })) : (
39
- /* expanded view */
40
- _jsxs("div", { className: `flex flex-col `, style: {
31
+ const { key: cellKey, ...safeCellProps } = rawCellProps;
32
+ return (_jsx("td", { ...safeCellProps, className: isStickyColumn ? undefined : isLastCell ? "" : baseTd, children: _jsx("div", { className: wrapper, style: { maxWidth: `${cellMaxWidthWhenExpanded}ch` }, children: needsToggle ? (!expanded ? (
33
+ // **collapsed**: use your ToggleComponent (portal-friendly)
34
+ _jsx(ToggleComponent, { expanded: expanded, onToggle: onToggle, truncated: truncated, fullText: fullText, className: additionalCellClassNames, linkTextClassNames: linkTextClassNames })) : (
35
+ // **expanded**: always use this constant layout
36
+ _jsxs("div", { className: "flex flex-col", style: {
41
37
  maxWidth: `${cellMaxWidthWhenExpanded}ch`,
42
- }, children: [_jsx("span", { className: "text-left pr-5", children: fullText }), _jsx("span", { ...(hasToggle
43
- ? { onClick: handleToggle }
44
- : {}), className: linkText, children: "Show less" })] }))) : (
45
- /* no toggle required */
38
+ }, children: [_jsx("span", { className: "text-left pr-5", children: fullText }), _jsx("span", { onClick: (e) => {
39
+ e.stopPropagation();
40
+ onToggle();
41
+ }, className: linkTextClassNames, children: "Show less" })] }))) : (
42
+ // no truncation needed
46
43
  cell.render("Cell")) }) }, cellKey));
47
44
  };
48
45
  export default TableCell;
@@ -6,3 +6,4 @@ export declare const Default: any;
6
6
  export declare const CollapsedByDefault: any;
7
7
  export declare const NoExpand: any;
8
8
  export declare const LastCell: any;
9
+ export declare const WithCustomToggle: any;
@@ -1,9 +1,13 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  // src/components/TableCell/TableCell.stories.tsx
3
3
  import { useState } from "react";
4
4
  import TableCell from ".";
5
+ // ----- Custom Toggle component -----
6
+ const CustomToggle = ({ expanded, onToggle, truncated, fullText, className = "", linkTextClassNames = "text-purple-500 ml-1 underline", }) => (_jsx("button", { onClick: (e) => {
7
+ e.stopPropagation();
8
+ onToggle();
9
+ }, className: `px-2 py-1 border rounded ${className}`, children: expanded ? (_jsxs(_Fragment, { children: [fullText, " ", _jsx("span", { className: linkTextClassNames, children: "\u25B2 Less" })] })) : (_jsxs(_Fragment, { children: [truncated, "\u2026 ", _jsx("span", { className: linkTextClassNames, children: "\u25BC More" })] })) }));
5
10
  const sampleData = {
6
- uuid: "12345",
7
11
  address: "123 Main St, Springfield, IL, 62701, United States of America — this is a very long address so we can show the expand behavior.",
8
12
  };
9
13
  /* ---------- story config ---------- */
@@ -62,3 +66,11 @@ LastCell.args = {
62
66
  isLastCell: true,
63
67
  cellExpandable: true,
64
68
  };
69
+ export const WithCustomToggle = Template.bind({});
70
+ WithCustomToggle.args = {
71
+ isLastCell: false,
72
+ cellExpandable: true,
73
+ maxCharacters: 20,
74
+ toggleComponent: CustomToggle,
75
+ hasInfiniteScroll: true,
76
+ };
@@ -9,6 +9,7 @@ const sampleData = {
9
9
  age: 30,
10
10
  address: "123 Main St, Springfield, IL, 62701, United States of America",
11
11
  };
12
+ //FIXME: THIS SHOULD NOT BE ANY
12
13
  const defaultProps = {
13
14
  globalTrimActive: true,
14
15
  rowUuid: sampleData.uuid,
@@ -1,14 +1,37 @@
1
- import { Cell } from "react-table";
2
1
  export interface DataWithUUID {
3
2
  uuid?: string;
4
3
  }
5
- export interface TableCellProps<T extends object> {
6
- cell: Cell<T>;
4
+ export interface ToggleProps {
5
+ expanded: boolean;
6
+ onToggle: () => void;
7
+ truncated: string;
8
+ fullText: string;
9
+ className?: string;
10
+ linkTextClassNames?: string;
11
+ }
12
+ export interface TableCellProps {
13
+ /** the react-table cell object */
14
+ cell: any;
15
+ /** is this the last column? */
7
16
  isLastCell: boolean;
17
+ /** do we want truncation/expand behavior? */
18
+ cellExpandable?: boolean;
19
+ /** current collapsed/expanded state */
20
+ expanded: boolean;
21
+ /** toggle callback */
22
+ onToggle: () => void;
23
+ /** text-slice length (default 30) */
24
+ maxCharacters?: number;
25
+ /** width in `ch` when expanded (default 50) */
26
+ cellMaxWidthWhenExpanded?: number;
27
+ /** background color utility (e.g. “bg-blue-50”) */
28
+ cellColor?: string;
29
+ /** extra wrapper classes */
30
+ additionalCellClassNames?: string;
31
+ /** if true, will show “Show more / Show less” */
8
32
  hasInfiniteScroll: boolean;
9
- globalTrimActive?: boolean;
10
- rowUuid?: string;
11
- columnInputs?: string[];
12
- rowHoverClasses?: string;
13
- linkText?: string;
33
+ /** override the collapsed UI */
34
+ toggleComponent?: React.ComponentType<ToggleProps>;
35
+ /** classes for both “more” & “less” links */
36
+ linkTextClassNames?: string;
14
37
  }
@@ -1,6 +1,6 @@
1
1
  import React, { ReactNode } from "react";
2
2
  import { Row } from "react-table";
3
- import { DataWithUUID } from "../TableCell";
3
+ import { DataWithUUID, ToggleProps } from "../TableCell";
4
4
  export interface TableRowProps<T extends DataWithUUID> {
5
5
  row: Row<T>;
6
6
  prepareRow: (row: Row<T>) => void;
@@ -13,12 +13,13 @@ export interface TableRowProps<T extends DataWithUUID> {
13
13
  cellExpandable?: boolean;
14
14
  expandedCells: Record<string, boolean>;
15
15
  toggleCell: (key: string) => void;
16
+ ToggleComponent?: React.ComponentType<ToggleProps>;
16
17
  hasDropDown?: boolean;
17
18
  onFetchRowData?: (uuid: string) => Promise<void> | void;
18
19
  loadingIndicator?: ReactNode;
19
20
  errorIndicator?: (error: Error) => ReactNode;
20
21
  expandedContent?: ReactNode;
21
- linkText?: string;
22
+ linkTextClassNames?: string;
22
23
  rowClassNames?: string;
23
24
  maxCharacters: number;
24
25
  expandedRowUuid?: string | null;
@@ -26,6 +27,7 @@ export interface TableRowProps<T extends DataWithUUID> {
26
27
  cellColor: string;
27
28
  cellMaxWidthWhenExpanded: number;
28
29
  additionalCellClassNames: string;
30
+ toggleComponent?: React.ComponentType<ToggleProps>;
29
31
  }
30
- declare const TableRow: <T extends DataWithUUID>({ row, prepareRow, activeIndex, activeRowColor, rowHoverClasses, rowClassNames, hasInfiniteScroll, rowUuid, onRowClick, expandedCells, toggleCell, hasDropDown, onFetchRowData, loadingIndicator, errorIndicator, expandedContent, linkText, expandedRowUuid, cellExpandable, onToggleRow, maxCharacters, cellColor, cellMaxWidthWhenExpanded, additionalCellClassNames, }: TableRowProps<T>) => import("react/jsx-runtime").JSX.Element;
32
+ 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, }: TableRowProps<T>) => import("react/jsx-runtime").JSX.Element;
31
33
  export default TableRow;
@@ -3,7 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { Fragment, useState } from "react";
4
4
  import { motion, AnimatePresence } from "framer-motion";
5
5
  import TableCell from "../TableCell";
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, linkText = "text-blue-500", expandedRowUuid = null, cellExpandable = false, onToggleRow, maxCharacters = 30, cellColor = "bg-blue-50", cellMaxWidthWhenExpanded = 50, additionalCellClassNames = "", }) => {
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 = "text-purple-500 ml-1 underline", }) => {
7
7
  prepareRow(row);
8
8
  const rowClasses = `border-primary${activeIndex === row.index ? ` activeRow ${activeRowColor}` : ""}`;
9
9
  /* keep fetch/loading local */
@@ -41,7 +41,7 @@ const TableRow = ({ row, prepareRow, activeIndex, activeRowColor = "bg-pink-100"
41
41
  : {};
42
42
  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) => {
43
43
  const cellKey = `${rowUuid ?? "no-uuid"}-${cell.column.id}`;
44
- return (_jsx(TableCell, { cell: cell, isLastCell: idx === row.cells.length - 1, hasInfiniteScroll: hasInfiniteScroll, cellExpandable: cellExpandable, rowUuid: rowUuid, expanded: expandedCells[cellKey] ?? false, onToggle: () => toggleCell(cellKey), linkText: linkText, maxCharacters: maxCharacters, cellColor: cellColor, cellMaxWidthWhenExpanded: cellMaxWidthWhenExpanded, additionalCellClassNames: additionalCellClassNames }, cellKey));
44
+ 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 }, cellKey));
45
45
  }) }, 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") }) })) }))] }));
46
46
  };
47
47
  export default TableRow;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agilant/toga-blox",
3
3
  "private": false,
4
- "version": "1.0.200",
4
+ "version": "1.0.201",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",