import React, { Component } from 'react'; import classnames from 'classnames'; import DropdownShell from './DropdownShell'; interface Props { value: T | undefined; options: T[]; ariaLabel: string; label?: string; extra?: any; size?: string; color?: string; menuAlign?: string; formatTitle?(option: T): any; onChange?(value: T): void; } export default class DropdownComponent extends Component, {}> { private dropdownShell: DropdownShell | null; public render() { const { ariaLabel, color, size } = this.props; return ( (this.dropdownShell = el)} /> ); } private renderLabel = () => { const { value } = this.props; const labelStr = this.props.label ? `${this.props.label}:` : ''; return ( {labelStr} {this.formatTitle(value)} ); }; private renderOptions = () => { const { options, value, menuAlign, extra } = this.props; const menuClass = classnames({ 'dropdown-menu': true, [`dropdown-menu-${menuAlign || ''}`]: !!menuAlign }); return ( ); }; private formatTitle = (option: any) => { if (this.props.formatTitle) { return this.props.formatTitle(option); } else { return option; } }; private onChange = (value: any) => { if (this.props.onChange) { this.props.onChange(value); } if (this.dropdownShell) { this.dropdownShell.close(); } }; }