UNPKG

@lobehub/ui

Version:

Lobe UI is an open-source UI component library for building AIGC web apps

59 lines (58 loc) • 2.36 kB
"use client"; import Spin from "../Spin/Spin.mjs"; import Empty from "../../Empty/Empty.mjs"; import { styles } from "./style.mjs"; import { getCellValue } from "./toColumnDefs.mjs"; import { createElement } from "react"; import { jsx } from "react/jsx-runtime"; import { cx } from "antd-style"; //#region src/base-ui/Table/TableBody.tsx const TableBody = ({ classNames, columnIds, columns, emptyText, fixedOffsets, loading, onRow, rowClassName, rows, styles: customStyles }) => { if (rows.length === 0) return /* @__PURE__ */ jsx("tbody", { className: classNames?.body, style: customStyles?.body, children: /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", { className: styles.empty, colSpan: columns.length, children: loading ? /* @__PURE__ */ jsx(Spin, {}) : emptyText ?? /* @__PURE__ */ jsx(Empty, { description: "No data" }) }) }) }); return /* @__PURE__ */ jsx("tbody", { className: classNames?.body, style: customStyles?.body, children: rows.map((row, rowIndex) => { const record = row.original; const rowProps = onRow?.(record, rowIndex) ?? {}; const extraClassName = typeof rowClassName === "function" ? rowClassName(record, rowIndex) : rowClassName; return /* @__PURE__ */ createElement("tr", { ...rowProps, key: row.id, style: { ...customStyles?.row, ...rowProps.style }, className: cx(styles.row, rowProps.onClick && styles.clickable, extraClassName, classNames?.row, rowProps.className) }, columns.map((column, columnIndex) => { const value = getCellValue(record, column); const cellProps = column.onCell?.(record, rowIndex) ?? {}; const content = column.render ? column.render(value, record, rowIndex) : value; return /* @__PURE__ */ createElement("td", { ...cellProps, key: columnIds[columnIndex], title: column.ellipsis && typeof content === "string" ? content : cellProps.title, className: cx(styles.cell, column.ellipsis && styles.ellipsis, column.fixed && styles.fixed, column.className, classNames?.cell, cellProps.className), style: { textAlign: column.align, width: column.width, ...fixedOffsets[columnIndex], ...customStyles?.cell, ...cellProps.style } }, content); })); }) }); }; //#endregion export { TableBody as default }; //# sourceMappingURL=TableBody.mjs.map