UNPKG

gridcellx

Version:

GridCell component for React, written in TypeScript

147 lines (146 loc) 7.32 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var GridCell_css_1 = require("./GridCell.css"); var React = require("react"); var typings_1 = require("./typings"); var getCol = function (span) { switch (span) { case 1: return GridCell_css_1.default.col1; case 2: return GridCell_css_1.default.col2; case 3: return GridCell_css_1.default.col3; case 4: return GridCell_css_1.default.col4; case 5: return GridCell_css_1.default.col5; case 6: return GridCell_css_1.default.col6; case 7: return GridCell_css_1.default.col7; case 8: return GridCell_css_1.default.col8; case 9: return GridCell_css_1.default.col9; case 10: return GridCell_css_1.default.col10; case 11: return GridCell_css_1.default.col11; case 12: return GridCell_css_1.default.col12; case 13: return GridCell_css_1.default.col13; case 14: return GridCell_css_1.default.col14; case 15: return GridCell_css_1.default.col15; case 16: return GridCell_css_1.default.col16; case 17: return GridCell_css_1.default.col17; case 18: return GridCell_css_1.default.col18; case 19: return GridCell_css_1.default.col19; case 20: return GridCell_css_1.default.col20; case 21: return GridCell_css_1.default.col21; case 22: return GridCell_css_1.default.col22; case 23: return GridCell_css_1.default.col23; case 24: return GridCell_css_1.default.col24; default: return GridCell_css_1.default.col; } }; var GridCell = /** @class */ (function (_super) { __extends(GridCell, _super); function GridCell(props) { var _this = _super.call(this, props) || this; _this.buildGrid = function () { return _this.buildCell(_this.props.cell, 0); }; _this.buildCell = function (cell, index) { var _a, _b; if (cell.type === typings_1.CellType.Text || cell.type === undefined) { return (React.createElement("div", { className: getCol(cell.span), key: index }, React.createElement("div", { className: GridCell_css_1.default.cell }, React.createElement("div", { className: cell.className, style: cell.style }, cell.text)))); } if (cell.type === typings_1.CellType.Custom) { return (React.createElement("div", { className: getCol(cell.span), style: cell.dataType === undefined ? {} : { padding: "0px" }, key: index }, React.createElement("div", { className: GridCell_css_1.default.cell, style: cell.dataType === undefined ? {} : { backgroundColor: "transparent" } }, React.createElement("div", { className: cell.className, style: cell.style }, cell.render === undefined ? "" : cell.render())))); } if (cell.type === typings_1.CellType.InnerCell) { return (React.createElement("div", { className: getCol(cell.span), style: { padding: "0px" }, key: index }, React.createElement("div", { className: GridCell_css_1.default.cell, style: { backgroundColor: "transparent" } }, React.createElement("div", { className: cell.className, style: cell.style }, React.createElement(GridCell, { cell: cell.iCell, inner: true, lineColor: _this.props.lineColor }))))); } var childContent; if (cell.type === typings_1.CellType.Group) { if (cell.child !== null && cell.child !== undefined) { childContent = _this.buildGroup(cell); if (cell.dataType === typings_1.DataType.Default || cell.dataType === undefined) { return (React.createElement("div", { key: index, className: getCol(cell.span), style: { padding: "0px" } }, React.createElement("div", { className: GridCell_css_1.default.cell, style: { backgroundColor: "transparent" } }, React.createElement("div", { className: GridCell_css_1.default.row, style: cell.style }, (_a = childContent) === null || _a === void 0 ? void 0 : _a.map(function (ct) { return ct; }))))); } else { return (React.createElement("div", { className: getCol(cell.span), style: { padding: "0px" }, key: index }, React.createElement("div", { className: GridCell_css_1.default.cell, style: { backgroundColor: "transparent" } }, (_b = childContent) === null || _b === void 0 ? void 0 : _b.map(function (ct, index) { return (React.createElement("div", { className: GridCell_css_1.default.row, style: cell.style, key: index }, "ct")); })))); } } else { //显示group名称 return (React.createElement("div", { className: getCol(cell.span), key: index }, React.createElement("div", { className: GridCell_css_1.default.cell }, React.createElement("div", { className: cell.className, style: cell.style }, cell.text)))); } } return React.createElement("div", null, "can't support cell"); }; _this.buildGroup = function (cell) { var content = []; if (cell.child !== undefined) { cell.child.forEach(function (c, index) { var curContent = _this.buildCell(c, index); if (!(curContent instanceof String)) { content.push(curContent); } }); } return content; }; return _this; } GridCell.prototype.render = function () { return (React.createElement("div", { className: GridCell_css_1.default.gridCell, style: { backgroundColor: this.props.lineColor } }, this.buildGrid())); }; return GridCell; }(React.Component)); exports.GridCell = GridCell;