UNPKG

infinity-forge

Version:
45 lines 3.59 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TR = TR; var jsx_runtime_1 = require("react/jsx-runtime"); var react_1 = require("react"); var actions_1 = require("../actions/index.js"); var children_tr_1 = require("./children-tr/index.js"); var formik_1 = require("formik"); function TR(_a) { var _b; var columnsConfiguration = _a.columnsConfiguration, table = _a.table, index = _a.index, tableRef = _a.tableRef, loadingTable = _a.loadingTable, tableItems = _a.tableItems; var _c = (0, react_1.useState)(false), open = _c[0], setOpen = _c[1]; var childrenConfigurations = columnsConfiguration === null || columnsConfiguration === void 0 ? void 0 : columnsConfiguration.childrens; function handleToggle() { setOpen(function (prev) { return !prev; }); } var childrenItems = (0, formik_1.getIn)(table, childrenConfigurations === null || childrenConfigurations === void 0 ? void 0 : childrenConfigurations.childrenKey); var oneItemTableHasChildrenKey = !!(tableItems === null || tableItems === void 0 ? void 0 : tableItems.filter(function (item) { return (0, formik_1.getIn)(item, childrenConfigurations === null || childrenConfigurations === void 0 ? void 0 : childrenConfigurations.childrenKey); })); return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("tr", { children: [(columnsConfiguration.actions || (childrenItems && (childrenConfigurations === null || childrenConfigurations === void 0 ? void 0 : childrenConfigurations.childrens))) && ((0, jsx_runtime_1.jsx)(actions_1.Actions, { oneItemTableHasChildrenKey: oneItemTableHasChildrenKey, handleToggle: handleToggle, childrenItems: childrenItems, childrenConfigurations: childrenConfigurations, actions: columnsConfiguration.actions, table: table })), (_b = columnsConfiguration.columns) === null || _b === void 0 ? void 0 : _b.map(function (e, i) { var _a; if (e.enabled === false) { return (0, jsx_runtime_1.jsx)(react_1.Fragment, {}, e.id + index); } var componentProps = ((_a = e.Component) === null || _a === void 0 ? void 0 : _a.props) || {}; var props = __assign(__assign(__assign({}, table), componentProps), { tableItems: tableItems, index: index }); var widthTable = tableRef.current; var widthPercentage = (e.width * 100) / ((widthTable === null || widthTable === void 0 ? void 0 : widthTable.offsetWidth) || 0); var value = (0, formik_1.getIn)(table, e.id); return ((0, jsx_runtime_1.jsx)("td", { className: 'font-14-regular', style: { width: widthPercentage.toFixed(2) + '%' }, children: e.Component ? (0, jsx_runtime_1.jsx)(e.Component.Element, __assign({}, props)) : value }, String(index) + String(i))); })] }), open && childrenConfigurations && ((0, jsx_runtime_1.jsx)(children_tr_1.ChildrenTr, { tableItems: tableItems, childrens: childrenConfigurations, table: table, loadingTable: loadingTable }))] })); } //# sourceMappingURL=index.js.map