hbp-react-ui
Version:
A library of useful user-interface components built with React and MobX
110 lines (76 loc) • 7.87 kB
JavaScript
;Object.defineProperty(exports, "__esModule", { value: true });exports.default = undefined;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 _class, _desc, _value, _class2, _descriptor; ///////////////////////////////////////////////////////////
// File : InputText.js
// Description :
/**
* InputText allows simple text input.
* @class InputText
* @property {function} onChange The event-handler for a change in value
* @property {string} path The path to specify when reporting the value
* @property {object} item A NameValue object specifying the initial value
* @property {object} style Styling overrides
* @property {string} description The tooltip to display
*/
// Imports :
var _react = require('react');var _react2 = _interopRequireDefault(_react);
var _reactBootstrap = require('react-bootstrap');
var _mobx = require('mobx');
var _mobxReact = require('mobx-react');
var _InputTextStyles = require('./InputTextStyles');var _InputTextStyles2 = _interopRequireDefault(_InputTextStyles);
var _BaseClass2 = require('./BaseClass');var _BaseClass3 = _interopRequireDefault(_BaseClass2);
var _NameValue = require('./NameValue');function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}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.');}
// Class Definition
var
InputText = (0, _mobxReact.observer)(_class = (_class2 = function (_BaseClass) {_inherits(InputText, _BaseClass);
// Constructor
function InputText(props) {_classCallCheck(this, InputText);
if (typeof _hbp_debug_ != 'undefined') console.log('InputText.constructor');var _this = _possibleConstructorReturn(this, (InputText.__proto__ || Object.getPrototypeOf(InputText)).call(this,
props));_initDefineProp(_this, 'item', _descriptor, _this);
_this.item = props.item || _this.empty;
_this.style = props.style || _InputTextStyles2.default.styleContainer();return _this;
}
// Operations
_createClass(InputText, [{ key: 'componentWillMount', value: function componentWillMount() {
} }, { key: 'render', value: function render()
{
return (
_react2.default.createElement('div', { style: this.style },
_react2.default.createElement(_reactBootstrap.Panel, { header: this.title, bsStyle: 'info', className: 'text-center', title: this.description },
_react2.default.createElement(_reactBootstrap.FormGroup, { controlId: 'formControlsText', className: 'row-single-body', style: { marginBottom: '0' } },
_react2.default.createElement(_reactBootstrap.FormControl, {
type: 'text',
placeholder: 'type...',
onChange: this.onChange.bind(this),
value: this.item.$value })))));
} }, { key: 'componentDidMount', value: function componentDidMount()
{
} }, { key: 'componentWillReceiveProps', value: function componentWillReceiveProps(
nextProps) {
if (typeof _hbp_debug_ != 'undefined') console.log('InputText.componentWillReceiveProps');
_get(InputText.prototype.__proto__ || Object.getPrototypeOf(InputText.prototype), 'componentWillReceiveProps', this).call(this, nextProps);
if (nextProps.item != this.props.item) {// Re-initialised
this.item = nextProps.item;
}
} }, { key: 'shouldComponentUpdate', value: function shouldComponentUpdate(
nextProps, nextState) {
return _get(InputText.prototype.__proto__ || Object.getPrototypeOf(InputText.prototype), 'shouldComponentUpdate', this).call(this);
} }, { key: 'componentWillUpdate', value: function componentWillUpdate(
nextProps, nextState) {
} }, { key: 'componentDidUpdate', value: function componentDidUpdate(
prevProps, prevState) {
} }, { key: 'componentWillUnmount', value: function componentWillUnmount()
{
} }, { key: 'componentDidCatch', value: function componentDidCatch(
error, info) {
} }, { key: 'renderContainer', value: function renderContainer()
{
} }, { key: 'renderHeader', value: function renderHeader()
{
} }, { key: 'renderBody', value: function renderBody()
{
} }, { key: 'onChange', value: function onChange(
event) {
this.item = new _NameValue.NameValue(undefined, event.target.value);
this.props.onChange(this.props.path, this.item);
} }]);return InputText;}(_BaseClass3.default), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, 'item', [_mobx.observable], { enumerable: true, initializer: null })), _class2)) || _class;
// Exports
exports.default = InputText;