UNPKG

@vectara/vectara-ui

Version:

Vectara's design system, codified as a React and Sass component library

44 lines (43 loc) 3.52 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import classNames from "classnames"; import { BiChevronDown, BiChevronRight } from "react-icons/bi"; import { VuiIcon } from "../icon/Icon"; import { VuiIconButton } from "../button/IconButton"; import { VuiSpansCell } from "./SpansCell"; // Cap visual indentation at this depth so the first column doesn't overflow // for very deep traces. `aria-level` continues to reflect the true depth. const MAX_VISUAL_DEPTH = 12; export const VuiSpansRow = ({ row, rowIndex, columns, id, depth, indentSize, posInSet, setSize, hasChildren, isExpanded, onToggle, rowDecorator }) => { var _a; const decoratorAttrs = (_a = rowDecorator === null || rowDecorator === void 0 ? void 0 : rowDecorator(row, depth)) !== null && _a !== void 0 ? _a : {}; const { className: decoratorClassName } = decoratorAttrs, restDecoratorAttrs = __rest(decoratorAttrs, ["className"]); const rowClassName = classNames("vuiSpansRow", decoratorClassName, { "vuiSpansRow-isExpanded": hasChildren && isExpanded, "vuiSpansRow--leaf": !hasChildren }); const visualDepth = Math.min(depth, MAX_VISUAL_DEPTH); const indentStyle = { paddingLeft: visualDepth * indentSize }; return (_jsx("tr", Object.assign({ role: "row", "aria-level": depth + 1, "aria-posinset": posInSet, "aria-setsize": setSize, "aria-expanded": hasChildren ? isExpanded : undefined, "data-row-id": id, className: rowClassName }, restDecoratorAttrs, { children: columns.map((column, columnIndex) => { const { name, render, className: columnClassName, testId } = column; const cellClasses = classNames("vuiSpansCellWrapper", columnClassName, { "vuiSpansCellWrapper--first": columnIndex === 0, "vuiSpansCellWrapper--truncate": column.truncate }); const cellContent = render ? render(row, rowIndex) : row[name]; if (columnIndex === 0) { return (_jsx("td", Object.assign({ role: "gridcell", className: cellClasses, "data-testid": typeof testId === "function" ? testId(row) : testId }, { children: _jsxs("div", Object.assign({ className: "vuiSpansCell__indent", style: indentStyle }, { children: [_jsx("div", Object.assign({ className: "vuiSpansCell__chevron" }, { children: hasChildren ? (_jsx(VuiIconButton, { icon: _jsx(VuiIcon, { children: isExpanded ? _jsx(BiChevronDown, {}) : _jsx(BiChevronRight, {}) }), size: "xs", color: "neutral", "aria-label": isExpanded ? "Collapse span" : "Expand span", onClick: onToggle, "data-testid": `spanExpandToggle-${id}` })) : (_jsx("span", { className: "vuiSpansCell__chevronPlaceholder", "aria-hidden": "true" })) })), _jsx(VuiSpansCell, { children: cellContent })] })) }), name)); } return (_jsx("td", Object.assign({ role: "gridcell", className: cellClasses, "data-testid": typeof testId === "function" ? testId(row) : testId }, { children: _jsx(VuiSpansCell, { children: cellContent }) }), name)); }) }))); };