|
| 1 | +import React from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import { Link } from 'react-router'; |
| 4 | +import styled from 'styled-components'; |
| 5 | +import { remSize, prop, common } from '../theme'; |
| 6 | +import IconButton from './mobile/IconButton'; |
| 7 | +import Button from '../common/Button'; |
| 8 | + |
| 9 | +const DropdownWrapper = styled.ul` |
| 10 | + background-color: ${prop('Modal.background')}; |
| 11 | + border: 1px solid ${prop('Modal.border')}; |
| 12 | + box-shadow: 0 0 18px 0 ${prop('shadowColor')}; |
| 13 | + color: ${prop('primaryTextColor')}; |
| 14 | +
|
| 15 | + position: absolute; |
| 16 | + right: ${props => (props.right ? 0 : 'initial')}; |
| 17 | + left: ${props => (props.left ? 0 : 'initial')}; |
| 18 | +
|
| 19 | + ${props => (props.align === 'right' && 'right: 0;')} |
| 20 | + ${props => (props.align === 'left' && 'left: 0;')} |
| 21 | +
|
| 22 | +
|
| 23 | + text-align: left; |
| 24 | + width: ${remSize(180)}; |
| 25 | + display: flex; |
| 26 | + flex-direction: column; |
| 27 | + height: auto; |
| 28 | + z-index: 9999; |
| 29 | + border-radius: ${remSize(6)}; |
| 30 | +
|
| 31 | + & li:first-child { border-radius: ${remSize(5)} ${remSize(5)} 0 0; } |
| 32 | + & li:last-child { border-radius: 0 0 ${remSize(5)} ${remSize(5)}; } |
| 33 | +
|
| 34 | + & li:hover { |
| 35 | + |
| 36 | + background-color: ${prop('Button.hover.background')}; |
| 37 | + color: ${prop('Button.hover.foreground')}; |
| 38 | +
|
| 39 | + & button, & a { |
| 40 | + color: ${prop('Button.hover.foreground')}; |
| 41 | + } |
| 42 | + } |
| 43 | +
|
| 44 | + li { |
| 45 | + height: ${remSize(36)}; |
| 46 | + cursor: pointer; |
| 47 | + display: flex; |
| 48 | + align-items: center; |
| 49 | +
|
| 50 | + & button, |
| 51 | + & a { |
| 52 | + color: ${prop('primaryTextColor')}; |
| 53 | + width: 100%; |
| 54 | + text-align: left; |
| 55 | + padding: ${remSize(8)} ${remSize(16)}; |
| 56 | + } |
| 57 | + } |
| 58 | +`; |
| 59 | + |
| 60 | +// TODO: Add Icon to the left of the items in the menu |
| 61 | +// const MaybeIcon = (Element, label) => Element && <Element aria-label={label} />; |
| 62 | + |
| 63 | +const Dropdown = ({ items, align }) => ( |
| 64 | + <DropdownWrapper align={align} > |
| 65 | + {/* className="nav__items-left" */} |
| 66 | + {items && items.map(({ title, icon, href }) => ( |
| 67 | + <li key={`nav-${title && title.toLowerCase()}`}> |
| 68 | + <Link to={href}> |
| 69 | + {/* {MaybeIcon(icon, `Navigate to ${title}`)} */} |
| 70 | + {title} |
| 71 | + </Link> |
| 72 | + </li> |
| 73 | + )) |
| 74 | + } |
| 75 | + </DropdownWrapper> |
| 76 | +); |
| 77 | + |
| 78 | +Dropdown.propTypes = { |
| 79 | + align: PropTypes.oneOf(['left', 'right']), |
| 80 | + items: PropTypes.arrayOf(PropTypes.shape({ |
| 81 | + action: PropTypes.func, |
| 82 | + icon: PropTypes.func, |
| 83 | + href: PropTypes.string |
| 84 | + })), |
| 85 | +}; |
| 86 | + |
| 87 | +Dropdown.defaultProps = { |
| 88 | + items: [], |
| 89 | + align: null |
| 90 | +}; |
| 91 | + |
| 92 | +export default Dropdown; |
0 commit comments