//@flow import React from "react"; import classNames from "classnames"; export type SelectItem = { value: string, label: string }; type Props = { label?: string, options: SelectItem[], value?: SelectItem, onChange: string => void, loading?: boolean }; class Select extends React.Component { field: ?HTMLSelectElement; componentDidMount() { // trigger change after render, if value is null to set it to the first value // of the given options. if (!this.props.value && this.field && this.field.value) { this.props.onChange(this.field.value); } } handleInput = (event: SyntheticInputEvent) => { this.props.onChange(event.target.value); }; renderLabel = () => { const label = this.props.label; if (label) { return ; } return ""; }; render() { const { options, value, loading } = this.props; const loadingClass = loading ? "is-loading" : ""; return (
{this.renderLabel()}
); } } export default Select;