UNPKG

@bigfishtv/cockpit

Version:

76 lines (62 loc) 3.27 kB
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 _class, _temp2; 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 TreeModal from './TreeModal'; import Cell from '../cell/Cell'; import Icon from '../Icon'; import Button from '../button/Button'; import { modalHandler } from '../modal/ModalHost'; var TreeSelectModal = (_temp2 = _class = function (_Component) { _inherits(TreeSelectModal, _Component); function TreeSelectModal() { var _temp, _this, _ret; _classCallCheck(this, TreeSelectModal); 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.handleItemSelected = function (item) { _this.props.onChange(item); }, _this.launchModal = function () { modalHandler.add({ Component: TreeModal, props: _extends({}, _this.props.modalProps, { onSave: _this.handleItemSelected, onClose: function onClose() {}, filterData: _this.props.filterData }) }); }, _temp), _possibleConstructorReturn(_this, _ret); } TreeSelectModal.prototype.render = function render() { var _this2 = this; return this.props.value ? React.createElement(Cell, { Icon: React.createElement(Icon, { name: 'link' }), title: this.props.cellLabel(this.props.value), CellControl: this.props.readOnly ? null : function () { return React.createElement( Button, { size: 'icon', onClick: function onClick() { return _this2.handleItemSelected(null); } }, React.createElement(Icon, { name: 'close', size: '18' }) ); } }) : React.createElement(Button, { text: this.props.buttonText, size: 'medium', onClick: this.launchModal, disabled: this.props.readOnly }); }; return TreeSelectModal; }(Component), _class.defaultProps = { modalProps: {}, buttonText: 'Select Parent', filterData: function filterData(value) { return value; }, cellLabel: function cellLabel(_ref) { var title = _ref.title; return title; }, readOnly: false }, _temp2); export { TreeSelectModal as default };