wix-style-react
Version:
wix-style-react
123 lines (107 loc) • 4.67 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 AutoComplete from 'wix-style-react/AutoComplete';
var style = {
display: 'inline-block',
padding: '0 5px 0',
width: '200px',
lineHeight: '22px',
marginBottom: '200px'
};
var options = [{ id: 0, value: 'First option', v: 'F' }, { id: 1, value: React.createElement(
'div',
{ style: { color: 'red' } },
'test'
), v: 'S' }, { id: 2, value: 'Third option', v: 'T', disabled: true }, { id: 3, value: 'Fifth option', v: 'Fi' }, { id: 4, value: 'Fourth option', v: 'Fo' }];
// text -> value
// value -> ?
var ControlledAutoComplete = function (_React$Component) {
_inherits(ControlledAutoComplete, _React$Component);
function ControlledAutoComplete(props) {
_classCallCheck(this, ControlledAutoComplete);
var _this = _possibleConstructorReturn(this, (ControlledAutoComplete.__proto__ || Object.getPrototypeOf(ControlledAutoComplete)).call(this, props));
_this.state = { value: '', suggestions: options };
_this.onChange = _this.onChange.bind(_this);
_this.onSet = _this.onSet.bind(_this);
_this.onBlur = _this.onBlur.bind(_this);
_this.onFocus = _this.onFocus.bind(_this);
_this.onEscapePressed = _this.onEscapePressed.bind(_this);
_this.onKeyDown = _this.onKeyDown.bind(_this);
return _this;
}
_createClass(ControlledAutoComplete, [{
key: 'render',
value: function render() {
console.log('@@@@@@@@@@', this.state.suggestions);
return React.createElement(AutoComplete, {
ref: 'title',
value: this.state.title,
placeholder: 'Place holder',
autoSelect: true,
options: this.state.suggestions,
onSelect: this.onSet,
onManuallyInput: this.onManuallyInput,
onBlur: this.onBlur,
onFocus: this.onFocus,
onChange: this.onChange,
onEscapePressed: this.onEscapePressed,
onKeyDown: this.onKeyDown
});
}
// suggestions -> options
// onSet -> onSelect
}, {
key: 'onChange',
value: function onChange(e) {
console.log('>> Change!', e.target.value);
var value = e.target.value;
this.setState({
suggestions: options.filter(function (o) {
return o.value.toString().toLowerCase().indexOf(value.toLowerCase()) > -1;
})
});
}
}, {
key: 'onSet',
value: function onSet(e) {
console.log('>> Set!', e);
}
}, {
key: 'onBlur',
value: function onBlur() {
console.log('>> Blur!');
}
}, {
key: 'onFocus',
value: function onFocus() {
console.log('>> Focus!');
}
}, {
key: 'onEscapePressed',
value: function onEscapePressed() {
console.log('>> Escape Pressed!');
}
}, {
key: 'onManuallyInput',
value: function onManuallyInput(e) {
console.log('>> Manually input!', e);
}
}, {
key: 'onKeyDown',
value: function onKeyDown(e) {
console.log('>> Key down:', e, e.keyCode);
}
}]);
return ControlledAutoComplete;
}(React.Component);
export default (function () {
return React.createElement(
'div',
{ style: style },
React.createElement(ControlledAutoComplete, null)
);
});