@bigfishtv/cockpit
Version:
93 lines (83 loc) • 3.58 kB
JavaScript
var _class, _temp;
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 PropTypes from 'prop-types';
import React, { Component } from 'react';
import classnames from 'classnames';
import Icon from '../Icon';
/**
* Default cell used by Tree component, typically wrapped by TreeItem for drag-drop functionality
*/
var TreeCell = (_temp = _class = function (_Component) {
_inherits(TreeCell, _Component);
function TreeCell() {
_classCallCheck(this, TreeCell);
return _possibleConstructorReturn(this, _Component.apply(this, arguments));
}
TreeCell.prototype.render = function render() {
var _props = this.props,
isCollapsed = _props.isCollapsed,
selectedDrag = _props.selectedDrag,
showIndicator = _props.showIndicator,
onIndicatorClick = _props.onIndicatorClick,
onIndicatorDoubleClick = _props.onIndicatorDoubleClick,
title = _props.title,
isOver = _props.isOver,
position = _props.position,
onClick = _props.onClick,
onDoubleClick = _props.onDoubleClick,
selected = _props.selected;
return React.createElement(
'div',
{ className: classnames('tree-item', isOver && 'drag-' + position) },
React.createElement(
'div',
{
className: classnames('tree-cell', { dragging: selectedDrag, selected: selected }),
onClick: onClick,
onDoubleClick: onDoubleClick },
showIndicator && React.createElement(
'div',
{
className: classnames('tree-cell-icon', isCollapsed && 'collapsed'),
onClick: onIndicatorClick,
onDoubleClick: onIndicatorDoubleClick },
React.createElement(Icon, { name: 'chevron-' + (isCollapsed ? 'right' : 'down'), size: '18' })
),
React.createElement(
'div',
{ className: 'tree-cell-title' },
title
)
)
);
};
return TreeCell;
}(Component), _class.propTypes = {
/** Main text to display in cell */
title: PropTypes.node,
isCollapsed: PropTypes.bool,
/** another item is being dragged over this one */
isOver: PropTypes.bool,
selected: PropTypes.bool,
dragging: PropTypes.bool,
collapsed: PropTypes.bool,
/** is being dragged */
selectedDrag: PropTypes.bool,
/** show the chevron */
showIndicator: PropTypes.bool,
/** position of other item being dragged over this one */
position: PropTypes.oneOf(['into', 'above', 'below']),
onIndicatorClick: PropTypes.func,
onIndicatorDoubleClick: PropTypes.func,
onClick: PropTypes.func,
onDoubleClick: PropTypes.func
}, _class.defaultProps = {
title: '',
onIndicatorClick: function onIndicatorClick() {},
onIndicatorDoubleClick: function onIndicatorDoubleClick() {},
onClick: function onClick() {},
onDoubleClick: function onDoubleClick() {}
}, _temp);
export { TreeCell as default };