@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.
45 lines (44 loc) • 2.6 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _omit2 = _interopRequireDefault(require("lodash/omit"));
var _get2 = _interopRequireDefault(require("lodash/get"));
var React = _interopRequireWildcard(require("react"));
var _table = _interopRequireDefault(require("../../table"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const table = props => {
var _a, _b, _c;
const {
children
} = props;
const toArray = value => Array.isArray(value) ? value : [value];
const columnsFiber = toArray((0, _get2.default)(children[0], 'props.children.props.children'));
const dataFiber = toArray((0, _get2.default)(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.default, Object.assign({
dataSource: tableDataSource,
columns: titlesColumns
}, (0, _omit2.default)(props, 'children')));
};
var _default = exports.default = table;
;