UNPKG

@cuvp1225/tango-mail

Version:
27 lines (26 loc) 2.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Table = void 0; const tslib_1 = require("tslib"); const tango_boot_1 = require("@music163/tango-boot"); const react_1 = tslib_1.__importDefault(require("react")); const classnames_1 = tslib_1.__importDefault(require("classnames")); function TableView(_a) { var { caption, columns, dataSource, primaryKey = 'id', tableLayout, style, className, headClassName } = _a, props = tslib_1.__rest(_a, ["caption", "columns", "dataSource", "primaryKey", "tableLayout", "style", "className", "headClassName"]); return (react_1.default.createElement("table", Object.assign({ className: (0, classnames_1.default)('w-full text-sm text-left text-gray-500', className), style: Object.assign({ tableLayout, borderCollapse: 'collapse' }, style) }, props), caption ? (react_1.default.createElement("caption", { className: "py-2 text-[16px] font-semibold text-left text-gray-900 bg-white caption-top" }, caption)) : null, react_1.default.createElement("thead", { className: (0, classnames_1.default)('text-xs text-gray-700 uppercase bg-gray-100', headClassName) }, react_1.default.createElement("tr", null, columns === null || columns === void 0 ? void 0 : columns.map((column) => (react_1.default.createElement("th", { key: column.key || column.dataIndex, scope: "col", className: "px-4 py-2", style: { width: column.width } }, column.title))))), react_1.default.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 = tslib_1.__rest(_b, ["className", "style"]); return (react_1.default.createElement("tr", Object.assign({}, rowProps, { key: key, style: Object.assign({ borderBottomStyle: 'solid' }, rowStyle), className: (0, classnames_1.default)('bg-white border-b border-gray-200', rowClassName) }), columns === null || columns === void 0 ? void 0 : columns.map(({ key, dataIndex, render = renderCell }) => (react_1.default.createElement("td", { key: key || dataIndex, className: "px-4 py-3" }, render(data[dataIndex], data, rowIndex)))))); })))); } function renderCell(cellData, rowData, rowIndex) { return cellData; } exports.Table = (0, tango_boot_1.defineComponent)(TableView, { name: 'Table', });