import classnames from 'classnames'; import CSSTransitionGroup from 'react-addons-css-transition-group'; import React from 'react'; const methodsToBind = [ 'getDropdownButton', 'getDropdownMenu', 'handleDropdownBlur', 'handleDropdownClick', 'handleDropdownFocus', 'handleItemSelect' ]; export default class Dropdown extends React.Component { constructor() { super(); this.state = { isExpanded: false }; methodsToBind.forEach((method) => { this[method] = this[method].bind(this); }); } handleDropdownBlur() { this.setState({ isExpanded: false }); } handleDropdownClick() { if (this.state.isExpanded) { this.refs.dropdown.blur(); } else { this.refs.dropdown.focus(); } } handleDropdownFocus(event) { this.setState({ isExpanded: true }); } handleItemSelect(item) { this.refs.dropdown.blur(); this.props.handleItemSelect(item); } getDropdownButton() { return (
{this.props.header}
); } getDropdownMenu() { let menuItems = this.props.menuItems.map(function(property, index) { let classes = classnames({ 'dropdown__item': true, 'is-selected': this.props.selectedItem.property === property.property }) return (
  • {property.displayName}
  • ); }, this); return (
    {this.getDropdownButton()}
    ); } render() { let dropdownWrapperClass = classnames({ [this.props.dropdownWrapperClass]: true, 'is-expanded': this.state.isExpanded }); let menu = null; if (this.state.isExpanded) { menu = this.getDropdownMenu(); } return (
    {this.getDropdownButton()} {menu}
    ); } } Dropdown.defaultProps = { dropdownWrapperClass: 'dropdown', dropdownButtonClass: 'dropdown__trigger' };