@intuitionrobotics/thunderstorm
Version:
51 lines • 2.02 kB
JavaScript
import * as React from "react";
import Select, { components } from "react-select";
import {} from "react";
export 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(Select, { 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(components.DropdownIndicator, { ..._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);
}
}
class SelectItem {
value;
label;
constructor(s) {
this.value = s;
this.label = s;
}
}
//# sourceMappingURL=GenericSelect.js.map