UNPKG

hbp-quickfire

Version:

A library of useful user-interface components built with React on top of React Bootstrap and MobX

137 lines (82 loc) 16.8 kB
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 _class, _temp2, _dec, _class2, _dec2, _class4, _dec3, _class6, _dec4, _class8;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;} /* * Copyright (c) Human Brain Project * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import React from "react"; import { inject } from "mobx-react";import Button from "react-bootstrap/lib/Button";import Glyphicon from "react-bootstrap/lib/Glyphicon";import isFunction from "lodash/isFunction";var NestedActionButton = (_temp2 = _class = function (_React$Component) {_inherits(NestedActionButton, _React$Component);function NestedActionButton() {var _ref;var _temp, _this, _ret;_classCallCheck(this, NestedActionButton);for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {args[_key] = arguments[_key];}return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = NestedActionButton.__proto__ || Object.getPrototypeOf(NestedActionButton)).call.apply(_ref, [this].concat(args))), _this), _this. handleClick = function () { if (isFunction(_this.props[_this.actionCbName])) { _this.props[_this.actionCbName](_this.props.nestedFieldIndex); } }, _this. isDisabled = function () { throw "isDisabled Method of NestedActionButton should be redefined by inheritance"; }, _temp), _possibleConstructorReturn(_this, _ret);}_createClass(NestedActionButton, [{ key: "render", value: function render() { if (this.props.formStore.readMode || this.props.nestedField.readMode) { return null; } return ( React.createElement(Button, { disabled: this.isDisabled(), className: this.className + " " + this.props.className, bsStyle: this.props.bsStyle, bsSize: this.props.bsSize, onClick: this.handleClick }, this.props.children || React.createElement(Glyphicon, { glyph: this.defaultIcon }))); } }]);return NestedActionButton;}(React.Component), _class.defaultProps = { bsStyle: "primary", bsSize: "xsmall", className: "" }, _temp2); /** * Action button to remove a nested instance, * has to be called by the app with <Field.Remove/> component * @memberof FormFields.NestedField * @class NestedRemoveButton */export { NestedActionButton as default };var NestedRemoveButton = (_dec = inject("formStore", "nestedField", "nestedFieldIndex", "onRemove"), _dec(_class2 = function (_NestedActionButton) {_inherits(NestedRemoveButton, _NestedActionButton); function NestedRemoveButton(props) {_classCallCheck(this, NestedRemoveButton);var _this2 = _possibleConstructorReturn(this, (NestedRemoveButton.__proto__ || Object.getPrototypeOf(NestedRemoveButton)).call(this, props));_this2. isDisabled = function () { return _this2.props.nestedField.disabled || _this2.props.nestedField.readOnly || _this2.props.nestedField.value.length <= _this2.props.nestedField.min; };_this2.defaultIcon = "remove";_this2.actionCbName = "onRemove";_this2.className = "quickfire-nested-remove";return _this2;}return NestedRemoveButton;}(NestedActionButton)) || _class2); NestedActionButton.Remove = NestedRemoveButton; /** * Action button to move up a nested instance in the list, * has to be called by the app with <Field.MoveUp/> component * @memberof FormFields.NestedField * @class NestedMoveUpButton */var NestedMoveUpButton = (_dec2 = inject("formStore", "nestedField", "nestedFieldIndex", "onMoveUp"), _dec2(_class4 = function (_NestedActionButton2) {_inherits(NestedMoveUpButton, _NestedActionButton2); function NestedMoveUpButton(props) {_classCallCheck(this, NestedMoveUpButton);var _this3 = _possibleConstructorReturn(this, (NestedMoveUpButton.__proto__ || Object.getPrototypeOf(NestedMoveUpButton)).call(this, props));_this3. isDisabled = function () { return _this3.props.nestedField.disabled || _this3.props.nestedField.readOnly || _this3.props.nestedFieldIndex === 0; };_this3.defaultIcon = "arrow-up";_this3.actionCbName = "onMoveUp";_this3.className = "quickfire-nested-moveup";return _this3;}return NestedMoveUpButton;}(NestedActionButton)) || _class4); NestedActionButton.MoveUp = NestedMoveUpButton; /** * Action button to move down a nested instance in the list, * has to be called by the app with <Field.MoveDown/> component * @memberof FormFields.NestedField * @class NestedMoveDownButton */var NestedMoveDownButton = (_dec3 = inject("formStore", "nestedField", "nestedFieldIndex", "onMoveDown"), _dec3(_class6 = function (_NestedActionButton3) {_inherits(NestedMoveDownButton, _NestedActionButton3); function NestedMoveDownButton(props) {_classCallCheck(this, NestedMoveDownButton);var _this4 = _possibleConstructorReturn(this, (NestedMoveDownButton.__proto__ || Object.getPrototypeOf(NestedMoveDownButton)).call(this, props));_this4. isDisabled = function () { return _this4.props.nestedField.disabled || _this4.props.nestedField.readOnly || _this4.props.nestedFieldIndex >= _this4.props.nestedField.value.length - 1; };_this4.defaultIcon = "arrow-down";_this4.actionCbName = "onMoveDown";_this4.className = "quickfire-nested-movedown";return _this4;}return NestedMoveDownButton;}(NestedActionButton)) || _class6); NestedActionButton.MoveDown = NestedMoveDownButton; /** * Action button to duplicate a nested instance in the list, * has to be called by the app with <Field.Duplicate/> component * @memberof FormFields.NestedField * @class NestedDuplicateButton */var NestedDuplicateButton = (_dec4 = inject("formStore", "nestedField", "nestedFieldIndex", "onDuplicate"), _dec4(_class8 = function (_NestedActionButton4) {_inherits(NestedDuplicateButton, _NestedActionButton4); function NestedDuplicateButton(props) {_classCallCheck(this, NestedDuplicateButton);var _this5 = _possibleConstructorReturn(this, (NestedDuplicateButton.__proto__ || Object.getPrototypeOf(NestedDuplicateButton)).call(this, props));_this5. isDisabled = function () { return _this5.props.nestedField.disabled || _this5.props.nestedField.readOnly || _this5.props.nestedField.value.length >= _this5.props.nestedField.max; };_this5.defaultIcon = "duplicate";_this5.actionCbName = "onDuplicate";_this5.className = "quickfire-nested-duplicate";return _this5;}return NestedDuplicateButton;}(NestedActionButton)) || _class8); NestedActionButton.Duplicate = NestedDuplicateButton;