UNPKG

@douyinfe/semi-ui

Version:

A modern, comprehensive, flexible design system and UI library. Connect DesignOps & DevOps. Quickly build beautiful React apps. Maintained by Douyin-fe team.

36 lines 1.45 kB
import _omit from "lodash/omit"; import _get from "lodash/get"; import * as React from 'react'; import Table from '../../table'; const table = props => { var _a, _b, _c; const { children } = props; const toArray = value => Array.isArray(value) ? value : [value]; const columnsFiber = toArray(_get(children[0], 'props.children.props.children')); const dataFiber = toArray(_get(children[1], 'props.children')); const titlesColumns = columnsFiber.map((column, i) => { var _a; return { dataIndex: String(i), title: ((_a = column === null || column === void 0 ? void 0 : column.props) === null || _a === void 0 ? void 0 : _a.children) || "" }; }); const tableDataSource = []; for (let i = 0; i < dataFiber.length; i++) { let item = { key: String(i) }; (_c = (_b = (_a = dataFiber[i]) === null || _a === void 0 ? void 0 : _a.props.children) === null || _b === void 0 ? void 0 : _b.forEach) === null || _c === void 0 ? void 0 : _c.call(_b, (child, index) => { var _a, _b; item[String(index)] = (_b = (_a = child === null || child === void 0 ? void 0 : child.props) === null || _a === void 0 ? void 0 : _a.children) !== null && _b !== void 0 ? _b : ""; }); tableDataSource.push(item); } return /*#__PURE__*/React.createElement(Table, Object.assign({ dataSource: tableDataSource, columns: titlesColumns }, _omit(props, 'children'))); }; export default table;