infinity-forge
Version:
41 lines • 3.39 kB
JavaScript
;
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 ui_1 = require("../../../../../../../ui/index.js");
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 = table === null || table === void 0 ? void 0 : table[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 && (0, jsx_runtime_1.jsx)(actions_1.Actions, { 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);
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("td", { style: { width: 20 }, children: childrenConfigurations && i === 0 && childrenItems && childrenItems.length > 0 && ((0, jsx_runtime_1.jsx)("button", { onClick: handleToggle, className: 'expand-btn', type: 'button', children: (0, jsx_runtime_1.jsx)(ui_1.Icon, { name: open ? 'IconTopChevron' : 'IconBottomChevron' }) })) }), (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)) : table[e.id] }, 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