UNPKG

@cuvp1225/tango-mail

Version:
24 lines (23 loc) 2.21 kB
import { __rest } from "tslib"; import { defineComponent } from '@music163/tango-boot'; import React from 'react'; import cx from 'classnames'; function TableView(_a) { var { caption, columns, dataSource, primaryKey = 'id', tableLayout, style, className, headClassName } = _a, props = __rest(_a, ["caption", "columns", "dataSource", "primaryKey", "tableLayout", "style", "className", "headClassName"]); return (React.createElement("table", Object.assign({ className: cx('w-full text-sm text-left text-gray-500', className), style: Object.assign({ tableLayout, borderCollapse: 'collapse' }, style) }, props), caption ? (React.createElement("caption", { className: "py-2 text-[16px] font-semibold text-left text-gray-900 bg-white caption-top" }, caption)) : null, React.createElement("thead", { className: cx('text-xs text-gray-700 uppercase bg-gray-100', headClassName) }, React.createElement("tr", null, columns === null || columns === void 0 ? void 0 : columns.map((column) => (React.createElement("th", { key: column.key || column.dataIndex, scope: "col", className: "px-4 py-2", style: { width: column.width } }, column.title))))), React.createElement("tbody", null, dataSource === null || dataSource === void 0 ? void 0 : dataSource.map((data, rowIndex) => { var _a; const key = data[primaryKey]; const _b = ((_a = props.getRowProps) === null || _a === void 0 ? void 0 : _a.call(props, data, rowIndex)) || {}, { className: rowClassName, style: rowStyle } = _b, rowProps = __rest(_b, ["className", "style"]); return (React.createElement("tr", Object.assign({}, rowProps, { key: key, style: Object.assign({ borderBottomStyle: 'solid' }, rowStyle), className: cx('bg-white border-b border-gray-200', rowClassName) }), columns === null || columns === void 0 ? void 0 : columns.map(({ key, dataIndex, render = renderCell }) => (React.createElement("td", { key: key || dataIndex, className: "px-4 py-3" }, render(data[dataIndex], data, rowIndex)))))); })))); } function renderCell(cellData, rowData, rowIndex) { return cellData; } export const Table = defineComponent(TableView, { name: 'Table', });