UNPKG

@intuitionrobotics/thunderstorm

Version:
52 lines 2.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GenericSelect = void 0; const React = require("react"); const react_select_1 = require("react-select"); class GenericSelect extends React.Component { constructor(props) { super(props); this.state = { menuIsOpen: false }; this.handleSelection = this.handleSelection.bind(this); } render() { const props = this.props; const items = []; const options = props.options; let value = null; if (options) { const selectedOption = props.selectedOption; options.forEach((option, idx) => { const optionPresentation = props.presentation(option); const item = { label: optionPresentation, value: "" + idx }; if (selectedOption !== undefined) { if (optionPresentation === props.presentation(selectedOption)) { value = item; } } items.push(item); }); } return React.createElement(react_select_1.default, { options: items, value: value, onChange: item => this.handleSelection(item), onMenuClose: () => this.setState({ menuIsOpen: false }), onMenuOpen: () => this.setState({ menuIsOpen: true }), styles: this.props.styles, placeholder: props.placeholder, components: props.components ? props.components : { IndicatorSeparator: () => null, DropdownIndicator: (_props) => (React.createElement(react_select_1.components.DropdownIndicator, Object.assign({}, _props), this.state.menuIsOpen ? props.iconClose : props.iconOpen)) }, isDisabled: props.isDisabled }); } handleSelection(item) { if (!this.props.options) return; const idx = Number(item.value); const option = this.props.options[idx]; this.props.onChange(option); } } exports.GenericSelect = GenericSelect; class SelectItem { constructor(s) { this.value = s; this.label = s; } } //# sourceMappingURL=GenericSelect.js.map