import React from 'react'; import PropTypes from 'prop-types'; import { DropdownItem, DropdownDivider } from './Base'; class InnerLabelDropdown extends React.Component { constructor(props) { super(props); this.state = { isOpen: false, }; this.toggle = this.toggle.bind(this); this.close = this.close.bind(this); } toggle() { this.setState({ isOpen: !this.state.isOpen, }); } close() { this.setState({ isOpen: false, }); } selectOption(opt) { this.close(); this.props.handleUpdate(opt); } getOptionElems() { return this.props.options.map((opt, i) => { if (opt.type === 'divider') { return ; } else { return ( this.selectOption(opt.value)}> {opt.title} ); } }); } render() { const { props, state } = this; const optionElems = this.getOptionElems(); const menuVisibility = state.isOpen === true ? 'visible' : 'hidden'; const selectedClasses = state.isOpen === true ? 'br-blue' : 'br-gray-50'; const fullWidthClass = props.fullWidth ? 'full-width' : ''; return (
{optionElems}
); } } InnerLabelDropdown.propTypes = { disabled: PropTypes.bool, className: PropTypes.string, title: PropTypes.string, style: PropTypes.object, currentSelectionTitle: PropTypes.string, children: PropTypes.node, }; InnerLabelDropdown.defaultProps = { disabled: false, className: '', title: '', style: {}, currentSelectionTitle: '', }; export default InnerLabelDropdown;