UNPKG

@payfit/unity-components

Version:

82 lines (81 loc) 2.5 kB
import { useTableContext as e } from "../Table.context.js"; import t, { Children as n, cloneElement as r, forwardRef as i } from "react"; import { uyTv as a } from "@payfit/unity-themes"; import { jsx as o } from "react/jsx-runtime"; //#region src/components/table/parts/TableBody.tsx var s = a({ base: ["uy:transition-all uy:duration-200 uy:ease-in-out uy:relative"], variants: { isEmpty: { true: ["uy:h-[var(--uy-table-min-rows)]"], false: ["uy:[&_tr:last-child]:border-b", "uy:[&_tr:last-child]:border-b-[length:calc(1px*var(--uy-table-has-remaining-space,0))]"] } } }), c = ({ children: e, hasDataStateContent: i, enableVirtualization: a, virtualizer: s }) => { if (i) return []; if (a && s) { let n = s.getVirtualItems(), r = s.getTotalSize(), i = n[0], a = n[n.length - 1], c = i ? i.start : 0, l = a ? r - a.end : 0, u = []; return c > 0 && u.push(/* @__PURE__ */ o("tr", { "aria-hidden": "true", style: { border: 0, borderBottom: 0 }, children: /* @__PURE__ */ o("td", { colSpan: 1e3, style: { height: c, padding: 0, border: 0 } }) }, "__spacer-top__")), n.forEach((n) => { let r = t.Children.toArray(e)[n.index]; t.isValidElement(r) && u.push(t.cloneElement(r, { key: n.index, rowIndex: n.index, ref: (e) => { e && s.measureElement(e); } })); }), l > 0 && u.push(/* @__PURE__ */ o("tr", { "aria-hidden": "true", style: { border: 0, borderBottom: 0 }, children: /* @__PURE__ */ o("td", { colSpan: 1e3, style: { height: l, padding: 0, border: 0 } }) }, "__spacer-bottom__")), u; } return n.map(e, (e, n) => t.isValidElement(e) ? r(e, { rowIndex: n, ...e.props }) : e); }, l = i(({ children: t, renderEmptyState: n, renderDataState: r, ...i }, a) => { let { virtualizer: l, enableVirtualization: u } = e(), d = r ? r() : void 0, f = d !== void 0, p = c({ children: t, hasDataStateContent: f, enableVirtualization: u, virtualizer: l }), m = !p || p.length === 0 || f, h = m && n ? n() : null, g = null; return f ? g = d : m && h && (g = h), /* @__PURE__ */ o("tbody", { ref: a, className: s({ isEmpty: m }), "data-dd-privacy": "mask", "data-empty": m || f || void 0, ...i, children: g ? /* @__PURE__ */ o("tr", { children: /* @__PURE__ */ o("td", { colSpan: 1e3, className: "uy:p-0", children: g }) }) : p }); }); l.displayName = "TableBody"; //#endregion export { l as TableBody, s as tableBody };