Newer
Older
import React from 'react'
import classnames from 'classnames'
// TODO: match the width of the container to the width of the widest option?
class Menu extends React.Component {
super(props)
this.state = {
open: false,
const { options } = this.props
return options.find(option => option.value === value).label
}
const { label, options, placeholder = 'Choose in the list' } = this.props
const { open, selected } = this.state
return (
<div
className={classnames(classes.root, {
[classes.open]: open,
})}
>
{label && <span className={classes.label}>{label}</span>}
<div className={classes.main}>
<div className={classes.openerContainer}>
<button
className={classes.opener}
{selected ? (
<span>{this.optionLabel(selected)}</span>
) : (
<span className={classes.placeholder}>{placeholder}</span>
)}
<span className={classes.arrow}>▼</span>
</button>
</div>
<div className={classes.optionsContainer}>
{open && (
<div className={classes.options}>
{options.map(option => (
<div
className={classnames(classes.option, {
onClick={() => this.handleSelect(option.value)}