UNPKG

wix-style-react

Version:
81 lines (67 loc) 3.85 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; }; }(); function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } 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 MultiSelect from 'wix-style-react/MultiSelect'; var ExampleTagInput = function (_React$Component) { _inherits(ExampleTagInput, _React$Component); function ExampleTagInput(props) { _classCallCheck(this, ExampleTagInput); var _this = _possibleConstructorReturn(this, (ExampleTagInput.__proto__ || Object.getPrototypeOf(ExampleTagInput)).call(this, props)); _this.nextId = 0; _this.state = { tags: [], inputValue: '' }; _this.handleOnManuallyInput = _this.handleOnManuallyInput.bind(_this); _this.handleOnRemoveTag = _this.handleOnRemoveTag.bind(_this); _this.handleOnChange = _this.handleOnChange.bind(_this); return _this; } _createClass(ExampleTagInput, [{ key: 'handleOnRemoveTag', value: function handleOnRemoveTag(tagId) { console.log('onRemoveTag(tagId): tagId=' + tagId + ')'); this.setState({ tags: this.state.tags.filter(function (currTag) { return currTag.id !== tagId; }) }); } }, { key: 'handleOnChange', value: function handleOnChange(event) { console.log('onChange(\'' + event.target.value + '\')'); this.setState({ inputValue: event.target.value }); } }, { key: 'handleOnManuallyInput', value: function handleOnManuallyInput(values) { var _this2 = this; console.log('onManuallyInput(values): values=' + values); var tags = values.map(function (value) { var tag = { id: String(_this2.nextId++), label: value }; return tag; }); this.setState({ tags: [].concat(_toConsumableArray(this.state.tags), _toConsumableArray(tags)) }); } }, { key: 'render', value: function render() { return React.createElement(MultiSelect, { dataHook: 'multi-select-tags-input', value: this.state.inputValue, onChange: this.handleOnChange, tags: this.state.tags, onManuallyInput: this.handleOnManuallyInput, onRemoveTag: this.handleOnRemoveTag, upgrade: true }); } }]); return ExampleTagInput; }(React.Component); export default ExampleTagInput;