import React from 'react' import classnames from 'classnames' import FeatherIcon from 'feather-icons-react' import { Menu, MenuList, MenuButton, MenuItem } from '@reach/menu-button' export function DropdownList(props) { const { id, className, current, formatValue, hoverTextColor, label, textColor, values, onValueSet, placeholder } = props const handleChangeValueClick = (newValue) => { onValueSet(newValue) } let valuesArray = [] if (Array.isArray(values)) { valuesArray = values } else if (typeof values === 'object') { valuesArray = Object.keys(values).map((v) => v) } const menuItems = valuesArray.map((value) => { const selected = value === current if (value.groupHeader) { return (
{value.groupHeader}
) } return ( { handleChangeValueClick(value) }} className={classnames({ selected })} disabled={value.disabled} > {formatValue ? formatValue(value) : value} ) }) const inactiveTextColorClasses = `${textColor} hover:${hoverTextColor}` const activeTextColorClasses = `${hoverTextColor} hover:${hoverTextColor}` let buttonText = '' if (label) { buttonText = label } else if (current) { buttonText = formatValue(current) } else if (placeholder) { buttonText = placeholder } return ( <> {({ isExpanded }) => ( <> {buttonText} {menuItems} )} ) }