UNPKG

react-virtualized

Version:

React components for efficiently rendering large, scrollable lists and tabular data

158 lines (124 loc) 5.32 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.defaultCellRenderer = defaultCellRenderer; exports.defaultCellDataGetter = defaultCellDataGetter; exports.defaultHeaderRenderer = defaultHeaderRenderer; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _SortIndicator = require('./SortIndicator'); var _SortIndicator2 = _interopRequireDefault(_SortIndicator); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** * Default cell renderer that displays an attribute as a simple string * You should override the column's cellRenderer if your data is some other type of object. */ function defaultCellRenderer(cellData, cellDataKey, rowData, rowIndex, columnData) { if (cellData === null || cellData === undefined) { return ''; } else { return String(cellData); } } /** * Default accessor for returning a cell value for a given attribute. * This function expects to operate on either a vanilla Object or an Immutable Map. * You should override the column's cellDataGetter if your data is some other type of object. */ function defaultCellDataGetter(dataKey, rowData, columnData) { if (rowData.get instanceof Function) { return rowData.get(dataKey); } else { return rowData[dataKey]; } } /** * Default table header renderer. */ function defaultHeaderRenderer(_ref) { var columnData = _ref.columnData; var dataKey = _ref.dataKey; var disableSort = _ref.disableSort; var label = _ref.label; var sortBy = _ref.sortBy; var sortDirection = _ref.sortDirection; var showSortIndicator = sortBy === dataKey; var children = [_react2.default.createElement( 'div', { className: 'FlexTable__headerTruncatedText', key: 'label', title: label }, label )]; if (showSortIndicator) { children.push(_react2.default.createElement(_SortIndicator2.default, { key: 'SortIndicator', sortDirection: sortDirection })); } return children; } /** * Describes the header and cell contents of a table column. */ var Column = function (_Component) { _inherits(Column, _Component); function Column() { _classCallCheck(this, Column); return _possibleConstructorReturn(this, Object.getPrototypeOf(Column).apply(this, arguments)); } return Column; }(_react.Component); Column.defaultProps = { cellDataGetter: defaultCellDataGetter, cellRenderer: defaultCellRenderer, flexGrow: 0, flexShrink: 1, headerRenderer: defaultHeaderRenderer }; Column.propTypes = { /** Optional CSS class to apply to cell */ cellClassName: _react.PropTypes.string, /** * Callback responsible for returning a cell's data, given its :dataKey * (dataKey: string, rowData: any): any */ cellDataGetter: _react.PropTypes.func, /** * Callback responsible for rendering a cell's contents. * (cellData: any, cellDataKey: string, rowData: any, rowIndex: number, columnData: any): element */ cellRenderer: _react.PropTypes.func, /** Optional additional data passed to this column's :cellDataGetter */ columnData: _react.PropTypes.object, /** Uniquely identifies the row-data attribute correspnding to this cell */ dataKey: _react.PropTypes.any.isRequired, /** If sort is enabled for the table at large, disable it for this column */ disableSort: _react.PropTypes.bool, /** Flex grow style; defaults to 0 */ flexGrow: _react.PropTypes.number, /** Flex shrink style; defaults to 1 */ flexShrink: _react.PropTypes.number, /** Optional CSS class to apply to this column's header */ headerClassName: _react.PropTypes.string, /** * Optional callback responsible for rendering a column header contents. * ({ columnData: object, dataKey: string, disableSort: boolean, label: string, sortBy: string, sortDirection: string }): PropTypes.node */ headerRenderer: _react.PropTypes.func.isRequired, /** Header label for this column */ label: _react.PropTypes.string, /** Maximum width of column; this property will only be used if :flexGrow is > 0. */ maxWidth: _react.PropTypes.number, /** Minimum width of column. */ minWidth: _react.PropTypes.number, /** Flex basis (width) for this column; This value can grow or shrink based on :flexGrow and :flexShrink properties. */ width: _react.PropTypes.number.isRequired }; exports.default = Column;