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.

37 lines 1.29 kB
import _omit from "lodash/omit"; import _get from "lodash/get"; import * as React from 'react'; import Table from '../../table'; const table = props => { 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 titles = columnsFiber.map(item => { var _a; return ((_a = item === null || item === void 0 ? void 0 : item.props) === null || _a === void 0 ? void 0 : _a.children) || ""; }); const tableDataSource = []; for (let i = 0; i < dataFiber.length; i++) { let item = { key: String(i) }; dataFiber[i].props.children.forEach((child, index) => { var _a, _b; item[titles[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: titles.map(title => { return { title, dataIndex: title }; }) }, _omit(props, 'children'))); }; export default table;