UNPKG

@bigfishtv/cockpit

Version:

61 lines (46 loc) 2.81 kB
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } 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; } import React, { Component } from 'react'; import { Cell } from 'fixed-data-table'; import * as SortTypes from '../../../constants/SortTypes'; import { reverseSortDirection } from '../../../utils/tableUtils'; import Icon from '../../Icon'; /** * Table header cell used for orderable columns */ var FixedDataTableHeaderCellSort = function (_Component) { _inherits(FixedDataTableHeaderCellSort, _Component); function FixedDataTableHeaderCellSort() { var _temp, _this, _ret; _classCallCheck(this, FixedDataTableHeaderCellSort); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.onSortChange = function (e) { e.preventDefault(); if (_this.props.onSortChange) { _this.props.onSortChange(_this.props.columnKey, _this.props.sortDir ? reverseSortDirection(_this.props.sortDir) : SortTypes.ASC); } }, _temp), _possibleConstructorReturn(_this, _ret); } FixedDataTableHeaderCellSort.prototype.render = function render() { var _props = this.props, sortDir = _props.sortDir, children = _props.children, props = _objectWithoutProperties(_props, ['sortDir', 'children']); return React.createElement( Cell, props, React.createElement( 'a', { onClick: this.onSortChange }, children, sortDir && React.createElement(Icon, { name: 'chevron-' + (sortDir === SortTypes.DESC ? 'down' : 'up'), size: 16 }) ) ); }; return FixedDataTableHeaderCellSort; }(Component); export { FixedDataTableHeaderCellSort as default };