@intuitionrobotics/thunderstorm
Version:
102 lines • 5.85 kB
JavaScript
"use strict";
/*
* Thunderstorm is a full web app framework!
*
* Typescript & Express backend infrastructure that natively runs on firebase function
* Typescript & React frontend infrastructure
*
* Copyright (C) 2020 Intuition Robotics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.TS_Table = void 0;
const React = require("react");
class TS_Table extends React.Component {
constructor(p) {
super(p);
}
render() {
var _a, _b;
return React.createElement("table", { className: this.props.className, style: this.props.style },
React.createElement("tbody", { className: (_a = this.props.body) === null || _a === void 0 ? void 0 : _a.className, style: (_b = this.props.body) === null || _b === void 0 ? void 0 : _b.style },
this.renderTableHeader(),
this.renderTableBody()));
}
renderTableHeader() {
var _a, _b, _c, _d, _e;
let renderers;
if (typeof this.props.headerRenderer === "object")
renderers = this.props.headerRenderer;
else
renderers = this.props.header.reduce((toRet, headerProp) => {
toRet[headerProp] = this.props.headerRenderer;
return toRet;
}, {});
const trClassName = typeof this.props.tr === 'object' ? (_a = this.props.tr) === null || _a === void 0 ? void 0 : _a.className : '';
const trStyle = (typeof this.props.tr === 'object' ? (_b = this.props.tr) === null || _b === void 0 ? void 0 : _b.style : {});
const tdClassName = typeof this.props.td === 'object' ? (_c = this.props.td) === null || _c === void 0 ? void 0 : _c.className : '';
const tdStyle = (typeof this.props.td === 'object' ? (_d = this.props.td) === null || _d === void 0 ? void 0 : _d.style : {});
return (React.createElement("tr", { key: `${this.props.id}-0`, className: trClassName, style: trStyle },
this.props.header.map((header, index) => React.createElement("td", { key: `${this.props.id}-${index}`, className: tdClassName, style: tdStyle }, renderers[header](header))), (_e = this.props.actions) === null || _e === void 0 ? void 0 :
_e.map((action, index) => React.createElement("td", { key: `${this.props.id}-${this.props.header.length + index}` }))));
}
renderTableBody() {
var _a;
let renderers;
if (typeof this.props.cellRenderer === "object")
renderers = this.props.cellRenderer;
else
renderers = this.props.header.reduce((toRet, headerProp) => {
toRet[headerProp] = this.props.cellRenderer;
return toRet;
}, {});
let actionsRenderers;
if (typeof this.props.actionsRenderer === "object")
actionsRenderers = this.props.actionsRenderer;
else
actionsRenderers = (_a = this.props.actions) === null || _a === void 0 ? void 0 : _a.reduce((toRet, actionKey) => {
toRet[actionKey] = this.props.actionsRenderer;
return toRet;
}, {});
return this.props.rows.map((row, rowIndex) => {
var _a;
const trStyleable = this.resolveTRStyleable(row, rowIndex);
return React.createElement("tr", { key: `${this.props.id}-${rowIndex}`, className: trStyleable === null || trStyleable === void 0 ? void 0 : trStyleable.className, style: trStyleable === null || trStyleable === void 0 ? void 0 : trStyleable.style },
this.props.header.map((header, columnIndex) => {
const tdStyleable = this.resolveTDStyleable(row, rowIndex, row[header], header);
return React.createElement("td", { key: `${this.props.id}-${columnIndex}`, className: tdStyleable === null || tdStyleable === void 0 ? void 0 : tdStyleable.className, style: tdStyleable === null || tdStyleable === void 0 ? void 0 : tdStyleable.style }, renderers[header](row[header], rowIndex, this.props.header[columnIndex], row));
}), (_a = this.props.actions) === null || _a === void 0 ? void 0 :
_a.map((actionKey, index) => {
const actionStyleable = this.resolveTDStyleable(row, rowIndex);
return React.createElement("td", { key: `${this.props.id}-${this.props.header.length + index}`, className: actionStyleable === null || actionStyleable === void 0 ? void 0 : actionStyleable.className, style: actionStyleable === null || actionStyleable === void 0 ? void 0 : actionStyleable.style }, actionsRenderers === null || actionsRenderers === void 0 ? void 0 : actionsRenderers[actionKey](rowIndex, actionKey));
}));
});
}
resolveTDStyleable(rowObject, rowIndex, cellValue, columnKey) {
if (!this.props.td)
return;
if (typeof this.props.td === 'function')
return this.props.td(rowObject, rowIndex, cellValue, columnKey);
return this.props.td;
}
resolveTRStyleable(row, rowIndex) {
if (!this.props.tr)
return;
if (typeof this.props.tr === 'function')
return this.props.tr(row, rowIndex);
return this.props.tr;
}
}
exports.TS_Table = TS_Table;
//# sourceMappingURL=TS_Table.js.map