UNPKG

@bigfishtv/cockpit

Version:

61 lines (50 loc) 2.96 kB
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 React, { Component, Children } from 'react'; import Icon from '../Icon'; import Button from '../button/Button'; import DropdownButton from '../button/dropdown/DropdownButton'; import DropdownItemDivider from '../button/dropdown/DropdownItemDivider'; import DropdownItem from '../button/dropdown/DropdownItem'; var CellControl = (_temp = _class = function (_Component) { _inherits(CellControl, _Component); function CellControl() { _classCallCheck(this, CellControl); return _possibleConstructorReturn(this, _Component.apply(this, arguments)); } CellControl.prototype.render = function render() { var _props = this.props, children = _props.children, editable = _props.editable, removable = _props.removable, duplicable = _props.duplicable, onEdit = _props.onEdit, onRemove = _props.onRemove, onDuplicate = _props.onDuplicate; var hasChildren = Children.toArray(children).filter(Boolean).length > 0; if (!duplicable && !editable && !hasChildren && !removable) return React.createElement('div', { className: 'button button-icon' }); if (!duplicable && !editable && !hasChildren && removable) return React.createElement( Button, { size: 'icon', onClick: onRemove }, React.createElement(Icon, { name: 'close', size: '18' }) ); return React.createElement( DropdownButton, { style: 'icon', caret: false, pullRight: true, text: React.createElement(Icon, { name: 'kebab' }) }, editable && React.createElement(DropdownItem, { text: 'Edit', onClick: onEdit }), duplicable && React.createElement(DropdownItem, { text: 'Duplicate', onClick: onDuplicate }), hasChildren && React.createElement(DropdownItemDivider, null), children, editable && removable && React.createElement(DropdownItemDivider, null), removable && React.createElement(DropdownItem, { text: 'Remove', onClick: onRemove }) ); }; return CellControl; }(Component), _class.defaultProps = { editable: true, removable: true, duplicable: false }, _temp); export { CellControl as default };