@agilant/toga-blox 1.0.163 → 1.0.164
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,26 +1,29 @@
|
|
|
1
|
-
import { jsx as _jsx,
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
// src/components/TableCell/TableCell.tsx
|
|
3
3
|
import { useState } from "react";
|
|
4
4
|
const MAX_CHARS = 30;
|
|
5
5
|
const TableCell = ({ cell, isLastCell, hasInfiniteScroll, linkText = "text-purple-500 ml-1 underline", }) => {
|
|
6
6
|
const [expanded, setExpanded] = useState(false);
|
|
7
|
-
|
|
7
|
+
/* ---------- compute toggle state ---------- */
|
|
8
8
|
const isString = typeof cell.value === "string";
|
|
9
9
|
const fullText = isString ? cell.value : "";
|
|
10
10
|
const isLong = isString && fullText.length > MAX_CHARS;
|
|
11
11
|
const hasToggle = hasInfiniteScroll && isLong;
|
|
12
12
|
const truncated = fullText.slice(0, MAX_CHARS);
|
|
13
|
-
|
|
13
|
+
/* ---------- click only when toggling ---------- */
|
|
14
14
|
const handleToggle = (e) => {
|
|
15
15
|
e.stopPropagation();
|
|
16
|
-
setExpanded((
|
|
16
|
+
setExpanded((p) => !p);
|
|
17
17
|
};
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
/* ---------- classes ---------- */
|
|
19
|
+
const baseTd = "relative overflow-hidden font-light text-sm text-left px-5";
|
|
20
|
+
const wrapper = "min-h-[40px] flex select-none" + (hasToggle ? " cursor-pointer" : "");
|
|
21
|
+
return (_jsx("td", { ...cell.getCellProps(), className: isLastCell ? "" : baseTd, children: _jsx("div", { ...(hasToggle ? { onClick: handleToggle } : {}), className: wrapper, children: hasToggle ? (!expanded ? (
|
|
22
|
+
/* collapsed: inline with ellipsis + hover‑only link */
|
|
23
|
+
_jsxs("div", { className: "flex items-center group", children: [_jsx("span", { children: truncated }), _jsx("span", { className: "inline group-hover:hidden", children: "\u2026" }), _jsx("span", { className: `hidden group-hover:inline ${linkText}`, children: "Show more" })] })) : (
|
|
24
|
+
/* expanded: vertical stack so "Show less" is below */
|
|
25
|
+
_jsxs("div", { className: "flex flex-col", children: [_jsx("span", { children: fullText }), _jsx("span", { className: linkText, children: "Show less" })] }))) : (
|
|
26
|
+
/* no toggle → let row handle all clicks */
|
|
24
27
|
cell.render("Cell")) }) }));
|
|
25
28
|
};
|
|
26
29
|
export default TableCell;
|