// @flow import React from 'react'; class Option extends React.Component { props: { value: string, active: boolean, onChange: (value: string) => void }; render() { const { value, active } = this.props; return (
  • {value}
  • ); } onChange = () => { this.props.onChange(this.props.value); }; } export default class UnitDropdown extends React.Component { props: { value: string, options: string[], onChange?: (value: string) => void }; state: { expanded: boolean } = { expanded: false }; render() { const { value, options, onChange } = this.props; const isReadonly = !onChange; return (
    {value} {this.state.expanded && !isReadonly && }
    ); } onToggleExpand = () => { this.setState(state => { return { expanded: !state.expanded }; }); }; onChange = (value: string) => { this.setState({ expanded: false }); if (this.props.onChange) { this.props.onChange(value); } }; }