wix-style-react
Version:
wix-style-react
92 lines (73 loc) • 3.92 kB
JavaScript
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; }; }();
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; }
/* eslint-disable no-console */
import React from 'react';
import InputWithOptions from 'wix-style-react/InputWithOptions';
var style = {
display: 'inline-block',
padding: '0 5px 0',
width: '200px',
lineHeight: '22px',
marginBottom: '350px'
};
var options = [{ id: '0', value: 'First option' }, { id: '1', value: 'Second option' }, { id: '2', value: 'Third option', disabled: true }, { id: '3', value: 'Fourth option' }, { id: '4', value: 'Fifth option' }, {
id: '5',
value: 'Very long option text jldlkasj ldk jsalkdjsal kdjaklsjdlkasj dklasj'
}];
var ControlledInputWithOptions = function (_React$Component) {
_inherits(ControlledInputWithOptions, _React$Component);
function ControlledInputWithOptions(props) {
_classCallCheck(this, ControlledInputWithOptions);
var _this = _possibleConstructorReturn(this, (ControlledInputWithOptions.__proto__ || Object.getPrototypeOf(ControlledInputWithOptions)).call(this, props));
_this.state = {
value: '',
selectedId: -1
};
return _this;
}
_createClass(ControlledInputWithOptions, [{
key: 'render',
value: function render() {
var _this2 = this;
var onChange = function onChange(event) {
_this2.setState({ value: event.target.value });
};
var onSelect = function onSelect(option) {
var value = option.value;
_this2.setState({
value: value,
selectedId: option.id
});
console.log('Selected option id=' + JSON.stringify(option) + ', value=' + value);
};
var onManuallyInput = function onManuallyInput(value) {
_this2.setState({
selectedId: -1
});
console.log('Manually selected ' + value);
};
var predicate = function predicate(element) {
return _this2.state.value ? element.value.toLowerCase().indexOf(_this2.state.value.toLowerCase()) !== -1 : true;
};
return React.createElement(InputWithOptions, {
options: options.filter(predicate),
selectedId: this.state.selectedId,
value: this.state.value,
onChange: onChange,
onSelect: onSelect,
onManuallyInput: onManuallyInput,
highlight: true
});
}
}]);
return ControlledInputWithOptions;
}(React.Component);
export default (function () {
return React.createElement(
'div',
{ style: style },
React.createElement(ControlledInputWithOptions, null)
);
});