UNPKG

ucsc-xena-client

Version:

UCSC Xena Client. Functional genomics visualizations.

116 lines (89 loc) 4.71 kB
'use strict'; 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 _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 _input = require('react-toolbox/lib/input'); var _input2 = _interopRequireDefault(_input); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } 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; } var React = require('react'); var _ = require('../underscore_ext'); var _require = require('../react-utils'), rxEvents = _require.rxEvents; var isValid = _.curry(function (min, max, value) { var v = value.trim(), i = parseInt(v); return v === '' || !(isNaN(i) || i < min || i > max); }); function parseValue(value, dflt) { var v = value.trim(); return v === '' ? dflt : parseInt(v); } // initialValue is int or null. // dflt, min, max are int. var NumberForm = function (_React$Component) { _inherits(NumberForm, _React$Component); function NumberForm(props) { _classCallCheck(this, NumberForm); var _this = _possibleConstructorReturn(this, (NumberForm.__proto__ || Object.getPrototypeOf(NumberForm)).call(this, props)); _this.onBlur = function () { _this.setState({ focused: false }); }; _this.onFocus = function () { _this.setState({ focused: true }); }; var initialValue = props.initialValue; _this.state = { value: initialValue == null ? '' : '' + initialValue, focused: false }; return _this; } _createClass(NumberForm, [{ key: 'componentWillMount', value: function componentWillMount() { var _this2 = this; var _props = this.props, dflt = _props.dflt, min = _props.min, max = _props.max; var events = rxEvents(this, 'change'); this.change = events.change.do(function (value) { return _this2.setState({ value: value }); }).debounceTime(200).filter(isValid(min, max)).subscribe(function (value) { return _this2.props.onChange(parseValue(value, dflt)); }); } }, { key: 'componentWillUnmount', value: function componentWillUnmount() { this.change.unsubscribe(); } }, { key: 'render', value: function render() { var _props2 = this.props, min = _props2.min, max = _props2.max, dflt = _props2.dflt, initialValue = _props2.initialValue, other = _objectWithoutProperties(_props2, ['min', 'max', 'dflt', 'initialValue']), _state = this.state, value = _state.value, focused = _state.focused; return React.createElement( 'form', { className: 'form-horizontal' }, React.createElement(_input2.default, _extends({}, other, { onBlur: this.onBlur, onFocus: this.onFocus, type: 'text', value: '' + value, label: 'Custom survival time cutoff', placeholder: focused ? 'Enter a number between ' + min + ' and ' + max : undefined, onChange: this.on.change })) ); } }]); return NumberForm; }(React.Component); module.exports = NumberForm;