UNPKG

react-bootstrap-table-2

Version:
172 lines (136 loc) 7.12 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _Const = require('./Const'); var _Const2 = _interopRequireDefault(_Const); 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; } var TableColumn = function (_Component) { _inherits(TableColumn, _Component); function TableColumn(props) { _classCallCheck(this, TableColumn); var _this = _possibleConstructorReturn(this, (TableColumn.__proto__ || Object.getPrototypeOf(TableColumn)).call(this, props)); _this.handleCellEdit = function () { return _this.__handleCellEdit__REACT_HOT_LOADER__.apply(_this, arguments); }; _this.handleCellClick = function () { return _this.__handleCellClick__REACT_HOT_LOADER__.apply(_this, arguments); }; return _this; } /* eslint no-unused-vars: [0, { "args": "after-used" }] */ _createClass(TableColumn, [{ key: 'shouldComponentUpdate', value: function shouldComponentUpdate(nextProps, nextState) { var children = this.props.children; var shouldUpdated = this.props.width !== nextProps.width || this.props.className !== nextProps.className || this.props.hidden !== nextProps.hidden || this.props.dataAlign !== nextProps.dataAlign || (typeof children === 'undefined' ? 'undefined' : _typeof(children)) !== _typeof(nextProps.children) || ('' + this.props.onEdit).toString() !== ('' + nextProps.onEdit).toString(); if (shouldUpdated) { return shouldUpdated; } if ((typeof children === 'undefined' ? 'undefined' : _typeof(children)) === 'object' && children !== null && children.props !== null) { if (children.props.type === 'checkbox' || children.props.type === 'radio') { shouldUpdated = shouldUpdated || children.props.type !== nextProps.children.props.type || children.props.checked !== nextProps.children.props.checked || children.props.disabled !== nextProps.children.props.disabled; } else { shouldUpdated = true; } } else { shouldUpdated = shouldUpdated || children !== nextProps.children; } if (shouldUpdated) { return shouldUpdated; } if (!(this.props.cellEdit && nextProps.cellEdit)) { return false; } else { return shouldUpdated || this.props.cellEdit.mode !== nextProps.cellEdit.mode; } } }, { key: '__handleCellEdit__REACT_HOT_LOADER__', value: function __handleCellEdit__REACT_HOT_LOADER__(e) { if (this.props.cellEdit.mode === _Const2.default.CELL_EDIT_DBCLICK) { if (document.selection && document.selection.empty) { document.selection.empty(); } else if (window.getSelection) { var sel = window.getSelection(); sel.removeAllRanges(); } } this.props.onEdit(this.props.rIndex + 1, e.currentTarget.cellIndex, e); } }, { key: '__handleCellClick__REACT_HOT_LOADER__', value: function __handleCellClick__REACT_HOT_LOADER__(e) { this.props.onClick(this.props.rIndex + 1, e.currentTarget.cellIndex, e); } }, { key: 'render', value: function render() { var _props = this.props, children = _props.children, columnTitle = _props.columnTitle, className = _props.className, dataAlign = _props.dataAlign, hidden = _props.hidden, cellEdit = _props.cellEdit, attrs = _props.attrs; var tdStyle = { textAlign: dataAlign, display: hidden ? 'none' : null }; var opts = {}; if (cellEdit) { if (cellEdit.mode === _Const2.default.CELL_EDIT_CLICK) { opts.onClick = this.handleCellEdit; } else if (cellEdit.mode === _Const2.default.CELL_EDIT_DBCLICK) { opts.onDoubleClick = this.handleCellEdit; } else { opts.onClick = this.handleCellClick; } } return _react2.default.createElement( 'td', _extends({ style: tdStyle, title: columnTitle, className: className }, opts, attrs), typeof children === 'boolean' ? children.toString() : children ); } }]); return TableColumn; }(_react.Component); TableColumn.propTypes = { rIndex: _react.PropTypes.number, dataAlign: _react.PropTypes.string, hidden: _react.PropTypes.bool, className: _react.PropTypes.string, columnTitle: _react.PropTypes.string, children: _react.PropTypes.node, onClick: _react.PropTypes.func, attrs: _react.PropTypes.object }; TableColumn.defaultProps = { dataAlign: 'left', hidden: false, className: '' }; var _default = TableColumn; exports.default = _default; ; var _temp = function () { if (typeof __REACT_HOT_LOADER__ === 'undefined') { return; } __REACT_HOT_LOADER__.register(TableColumn, 'TableColumn', '/Users/kkomarov/work/react-bootstrap-table/src/TableColumn.js'); __REACT_HOT_LOADER__.register(_default, 'default', '/Users/kkomarov/work/react-bootstrap-table/src/TableColumn.js'); }(); ;