UNPKG

@telsystems/inputs

Version:
52 lines 2.62 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import * as React from 'react'; import { BasicDropDown } from './BasicDropDown'; import { TextInput } from '../TextInput'; import theme from '@telsystems/design/dist/themes/default/Dropdown.scss'; var SuggestingInput = (function (_super) { __extends(SuggestingInput, _super); function SuggestingInput() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var _this = _super.apply(this, args) || this; _this.onDropDownToggle = function (isDropDownActive) { return function () { _this.setState({ isDropDownActive: isDropDownActive }); }; }; _this.state = { isDropDownActive: false }; return _this; } SuggestingInput.prototype.render = function () { var _a = this.props, placeholder = _a.placeholder, disabled = _a.disabled, items = _a.items, selectedIndex = _a.selectedIndex, hideAfterClick = _a.hideAfterClick, onItemClick = _a.onItemClick, onChange = _a.onChange, value = _a.value; return (React.createElement(BasicDropDown, { items: this.highlightSuggest(items), disabled: disabled, onItemClick: onItemClick, selectedIndex: selectedIndex, hideAfterClick: hideAfterClick, onOpen: this.onDropDownToggle(true), onClose: this.onDropDownToggle(false) }, React.createElement(TextInput, { disabled: disabled, placeholder: placeholder, value: value, onChange: onChange }))); }; SuggestingInput.prototype.highlightSuggest = function (items) { var _this = this; return items.map(function (item) { var title = item.content.title; var value = _this.props.value; return { content: { title: title.replace(value, "<span class=\"" + theme['selected-text'] + "\">" + value + "</span>"), originTitle: title } }; }); }; return SuggestingInput; }(React.PureComponent)); export { SuggestingInput }; //# sourceMappingURL=SuggestingInput.js.map