UNPKG

@blueprintjs/table

Version:

Scalable interactive table component

73 lines 3.9 kB
"use strict"; /* * Copyright 2016 Palantir Technologies, Inc. All rights reserved. * 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.Cell = exports.emptyCellRenderer = void 0; const tslib_1 = require("tslib"); const classnames_1 = tslib_1.__importDefault(require("classnames")); const React = tslib_1.__importStar(require("react")); const core_1 = require("@blueprintjs/core"); const Classes = tslib_1.__importStar(require("../common/classes")); const loadableContent_1 = require("../common/loadableContent"); const jsonFormat_1 = require("./formats/jsonFormat"); const truncatedFormat_1 = require("./formats/truncatedFormat"); const emptyCellRenderer = () => React.createElement(Cell, null); exports.emptyCellRenderer = emptyCellRenderer; /** * Cell component. * * @see https://blueprintjs.com/docs/#table/api.cell */ class Cell extends React.Component { shouldComponentUpdate(nextProps) { // deeply compare "style," because a new but identical object might have been provided. return (!core_1.Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !core_1.Utils.deepCompareKeys(this.props.style, nextProps.style)); } render() { const { cellRef, tabIndex, onKeyDown, onKeyUp, onKeyPress, style, intent, interactive, loading, tooltip, truncated, className, wrapText, } = this.props; const classes = (0, classnames_1.default)(Classes.TABLE_CELL, core_1.Classes.intentClass(intent), { [Classes.TABLE_CELL_INTERACTIVE]: interactive, [core_1.Classes.LOADING]: loading, [Classes.TABLE_TRUNCATED_CELL]: truncated, }, className); const textClasses = (0, classnames_1.default)({ [Classes.TABLE_TRUNCATED_TEXT]: truncated, [Classes.TABLE_NO_WRAP_TEXT]: !wrapText, }); // add width and height to the children, for use in shouldComponentUpdate in truncatedFormat // note: these aren't actually used by truncated format, just in shouldComponentUpdate const modifiedChildren = React.Children.map(this.props.children, child => { const isFormatElement = core_1.Utils.isElementOfType(child, truncatedFormat_1.TruncatedFormat) || core_1.Utils.isElementOfType(child, jsonFormat_1.JSONFormat); if (style != null && React.isValidElement(child) && isFormatElement) { return React.cloneElement(child, { parentCellHeight: style.height === undefined ? undefined : parseInt(style.height.toString(), 10), parentCellWidth: style.width === undefined ? undefined : parseInt(style.width.toString(), 10), }); } return child; }); const content = React.createElement("div", { className: textClasses }, modifiedChildren); return (React.createElement("div", { className: classes, title: tooltip, ref: cellRef, onKeyDown, onKeyPress, onKeyUp, style, tabIndex }, React.createElement(loadableContent_1.LoadableContent, { loading: loading !== null && loading !== void 0 ? loading : false, variableLength: true }, content))); } } exports.Cell = Cell; Cell.displayName = `${core_1.DISPLAYNAME_PREFIX}.Cell`; Cell.defaultProps = { truncated: true, wrapText: false, }; //# sourceMappingURL=cell.js.map