UNPKG

hbp-quickfire

Version:

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

38 lines (30 loc) 23.3 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 _get = function get(object, property, receiver) {if (object === null) object = Function.prototype;var desc = Object.getOwnPropertyDescriptor(object, property);if (desc === undefined) {var parent = Object.getPrototypeOf(object);if (parent === null) {return undefined;} else {return get(parent, property, receiver);}} else if ("value" in desc) {return desc.value;} else {var getter = desc.get;if (getter === undefined) {return undefined;}return getter.call(receiver);}};var _desc, _value, _class, _descriptor, _descriptor2, _descriptor3, _descriptor4;function _initDefineProp(target, property, descriptor, context) {if (!descriptor) return;Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 });}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;}function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {var desc = {};Object['ke' + 'ys'](descriptor).forEach(function (key) {desc[key] = descriptor[key];});desc.enumerable = !!desc.enumerable;desc.configurable = !!desc.configurable;if ('value' in desc || desc.initializer) {desc.writable = true;}desc = decorators.slice().reverse().reduce(function (desc, decorator) {return decorator(target, property, desc) || desc;}, desc);if (context && desc.initializer !== void 0) {desc.value = desc.initializer ? desc.initializer.call(context) : void 0;desc.initializer = undefined;}if (desc.initializer === void 0) {Object['define' + 'Property'](target, property, desc);desc = null;}return desc;}function _initializerWarningHelper(descriptor, context) {throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.');} /* * 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 { observable } from "mobx";import union from "lodash/union"; import DefaultField from "./DefaultField"; /** * @memberof FormFields.Slider * @name Options * @param {string} label "" - The field label * @param {string} labelTooltip "" - The field label tooltip message * @param {string} labelTooltipPlacement "top" - The field label tooltip message position * @param {string} type "Slider" * @param {number|Range} value null - The current value. If only a number is provided, a single slider will get rendered. If a range object {min:x, max:y} is provided, two sliders will get rendered. * @param {number|Range} defaultValue null - The defaultValue of the field * @param {string} path "" - Field path * @param {boolean} disabled false - Is the field disabled or not, a disabled field won't be editable or processed by FormStore.getValues() * @param {boolean} readOnly false - Is the field readOnly or not, a readOnly field won't be editable but will be processed by FormStore.getValues() * @param {boolean} readMode false - If true, displays the field as label and value without the actual form input * @param {number} min null (required) - minimum value. You cannot drag your slider under this value. * @param {number} max null (required) - maximum value. You cannot drag your slider beyond this value. * @param {number} step 1 - The default increment/decrement is 1. You can change that by setting a different number to this property. * @param {(value: number, type: string): string} formatLabel value => value - By default, value labels are displayed as plain numbers. If you want to change the display, you can do so by passing in a function */var Slider = (_class = function (_DefaultField) {_inherits(Slider, _DefaultField);function Slider() {var _ref;var _temp, _this, _ret;_classCallCheck(this, Slider);for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {args[_key] = arguments[_key];}return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Slider.__proto__ || Object.getPrototypeOf(Slider)).call.apply(_ref, [this].concat(args))), _this), _initDefineProp(_this, "min", _descriptor, _this), _initDefineProp(_this, "max", _descriptor2, _this), _initDefineProp(_this, "step", _descriptor3, _this), _initDefineProp(_this, "formatLabel", _descriptor4, _this), _temp), _possibleConstructorReturn(_this, _ret);}_createClass(Slider, null, [{ key: "properties", get: function get() { return union(_get(Slider.__proto__ || Object.getPrototypeOf(Slider), "properties", this), ["min", "max", "step", "formatLabel"]); } }]);return Slider;}(DefaultField), (_descriptor = _applyDecoratedDescriptor(_class.prototype, "min", [observable], { enumerable: true, initializer: function initializer() {return null;} }), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, "max", [observable], { enumerable: true, initializer: function initializer() {return null;} }), _descriptor3 = _applyDecoratedDescriptor(_class.prototype, "step", [observable], { enumerable: true, initializer: function initializer() {return 1;} }), _descriptor4 = _applyDecoratedDescriptor(_class.prototype, "formatLabel", [observable], { enumerable: true, initializer: function initializer() {return function (value) {return value;};} })), _class);export { Slider as default };