UNPKG

@intuitionrobotics/thunderstorm

Version:
97 lines 4.91 kB
/* * 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. */ import {} from "@intuitionrobotics/ts-common"; import {} from "react"; import {} from "../tools/Stylable.js"; import * as React from "react"; export class TS_Table extends React.Component { constructor(p) { super(p); } render() { return React.createElement("table", { className: this.props.className, style: this.props.style }, React.createElement("tbody", { className: this.props.body?.className, style: this.props.body?.style }, this.renderTableHeader(), this.renderTableBody())); } renderTableHeader() { 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' ? this.props.tr?.className : ''; const trStyle = (typeof this.props.tr === 'object' ? this.props.tr?.style : {}); const tdClassName = typeof this.props.td === 'object' ? this.props.td?.className : ''; const tdStyle = (typeof this.props.td === 'object' ? this.props.td?.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))), this.props.actions?.map((action, index) => React.createElement("td", { key: `${this.props.id}-${this.props.header.length + index}` })))); } renderTableBody() { 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 = this.props.actions?.reduce((toRet, actionKey) => { toRet[actionKey] = this.props.actionsRenderer; return toRet; }, {}); return this.props.rows.map((row, rowIndex) => { const trStyleable = this.resolveTRStyleable(row, rowIndex); return React.createElement("tr", { key: `${this.props.id}-${rowIndex}`, className: trStyleable?.className, style: 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?.className, style: tdStyleable?.style }, renderers[header](row[header], rowIndex, this.props.header[columnIndex], row)); }), this.props.actions?.map((actionKey, index) => { const actionStyleable = this.resolveTDStyleable(row, rowIndex); return React.createElement("td", { key: `${this.props.id}-${this.props.header.length + index}`, className: actionStyleable?.className, style: actionStyleable?.style }, 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; } } //# sourceMappingURL=TS_Table.js.map