import React from 'react' import Downshift from 'downshift' import ArrowDown from './svg/Arrowdown' import CheckMark from './svg/Checkmark' import { COLORS } from '../lib/constants' const Dropdown = ({ button, color, list, selected, onChange }) => { return ( it === selected)} itemToString={item => item.name} onChange={onChange} stateReducer={reduceState(list)} /> ) } const reduceState = list => (state, changes) => { switch (changes.type) { case Downshift.stateChangeTypes.keyDownArrowUp: case Downshift.stateChangeTypes.keyDownArrowDown: return { ...changes, selectedItem: list[changes.highlightedIndex] } default: return changes } } const renderDropdown = ({ button, color, list, selected }) => ({ isOpen, highlightedIndex, setHighlightedIndex, selectHighlightedItem, selectedItem, getRootProps, getButtonProps, getInputProps, getItemProps }) => { return ( {selectedItem.name} {isOpen ? ( {list.map((item, index) => ( {item.name} ))} ) : null} ) } const DropdownContainer = ({ children, innerRef, minWidth, ...rest }) => { return (
{children}
) } const SelectedItem = ({ children, isOpen, color, ...rest }) => { const itemColor = color || COLORS.SECONDARY return ( {children}
) } const ListItems = ({ children, color }) => { return ( ) } const ListItem = ({ children, color, isHighlighted, isSelected, ...rest }) => { const itemColor = color || COLORS.SECONDARY return (
  • {children} {isSelected ? : null}
  • ) } function minWidth(isButton, selected, list) { const items = isButton ? [...list, selected] : list return items.reduce((max, { name }) => { const wordSize = name.length * 10 + 32 return wordSize > max ? wordSize : max }, 0) } export default Dropdown