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 = ({ 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 = list => ({ 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, ...rest }) => { return ( {children}
) } const ListItems = ({ children }) => { return ( ) } const ListItem = ({ children, isHighlighted, isSelected, ...rest }) => { return (
  • {children} {isSelected ? : null}
  • ) } function minWidth(list) { return list.reduce((max, { name }) => { const wordSize = name.length * 12 return wordSize > max ? wordSize : max }, 0) } export default Dropdown