UNPKG

@trail-ui/react

Version:
63 lines (60 loc) 2.48 kB
import { GroupedRowHeader } from "./chunk-OFWFZZM5.mjs"; import { EditableTableCell } from "./chunk-FPIKPO4Q.mjs"; import { _Spinner } from "./chunk-OJCLZ6LD.mjs"; // src/editable-table/table-body/grouped-table-body.tsx import { Fragment } from "react/jsx-runtime"; import { Fragment as Fragment2, jsx, jsxs } from "react/jsx-runtime"; function GroupedEditableTableBody({ isLoading, columns, table, isCellDisabled }) { var _a; return /* @__PURE__ */ jsx(Fragment2, { children: isLoading ? /* @__PURE__ */ jsx("tbody", { children: /* @__PURE__ */ jsx("tr", { className: "h-[300px]", children: /* @__PURE__ */ jsx("td", { colSpan: columns.length, children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center gap-1", children: [ /* @__PURE__ */ jsx(_Spinner, { className: "h-8 w-8 animate-spin" }), /* @__PURE__ */ jsx("p", { className: "pt-1 text-neutral-700", children: "Loading..." }) ] }) }) }) }) : ((_a = table.getRowModel().rows) == null ? void 0 : _a.length) ? ( // Normal rows Object.values( table.getRowModel().rows.reduce( (acc, item) => { var _a2, _b; ((_b = acc[_a2 = item.original.editableTableGroupId]) != null ? _b : acc[_a2] = []).push( item ); return acc; }, {} ) ).map((row) => { var _a2; const groupId = (_a2 = row[0].original) == null ? void 0 : _a2.editableTableGroupId; return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs("tbody", { children: [ /* @__PURE__ */ jsx(GroupedRowHeader, { groupId }), row.map((item) => /* @__PURE__ */ jsx("tr", { children: item.getVisibleCells().map((cell) => { return /* @__PURE__ */ jsx( EditableTableCell, { cell, isCellDisabled }, `${cell.column.getIndex()}-${cell.row.index}` ); }) }, item.id)) ] }) }, groupId); }) ) : ( // Empty state /* @__PURE__ */ jsx("tbody", { children: /* @__PURE__ */ jsx("tr", { className: "h-[300px]", children: /* @__PURE__ */ jsx("td", { colSpan: columns.length, children: /* @__PURE__ */ jsx("div", { className: "flex flex-col items-center justify-center gap-1", children: /* @__PURE__ */ jsx("p", { role: "alert", "aria-live": "polite", className: "text-neutral-700", children: "No data" }) }) }) }) }) ) }); } export { GroupedEditableTableBody };