2020-07-21 18:03:00 +00:00
|
|
|
import React from 'react';
|
2020-07-22 18:37:44 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2020-07-21 18:03:00 +00:00
|
|
|
import { Link } from 'react-router';
|
2020-07-22 18:37:44 +00:00
|
|
|
import styled from 'styled-components';
|
|
|
|
import { remSize, prop, common } from '../theme';
|
2020-07-22 19:24:39 +00:00
|
|
|
import IconButton from './mobile/IconButton';
|
|
|
|
import Button from '../common/Button';
|
2020-07-21 18:03:00 +00:00
|
|
|
|
2020-07-22 19:24:39 +00:00
|
|
|
const DropdownWrapper = styled.ul`
|
2020-07-22 18:37:44 +00:00
|
|
|
background-color: ${prop('Modal.background')};
|
|
|
|
border: 1px solid ${prop('Modal.border')};
|
2020-07-22 19:24:39 +00:00
|
|
|
box-shadow: 0 0 18px 0 ${prop('shadowColor')};
|
2020-07-22 18:37:44 +00:00
|
|
|
color: ${prop('primaryTextColor')};
|
|
|
|
|
2020-07-22 21:48:24 +00:00
|
|
|
position: absolute;
|
2020-07-29 20:52:57 +00:00
|
|
|
right: ${props => (props.right ? 0 : 'initial')};
|
|
|
|
left: ${props => (props.left ? 0 : 'initial')};
|
|
|
|
|
2020-07-30 17:36:34 +00:00
|
|
|
${props => (props.align === 'right' && 'right: 0;')}
|
|
|
|
${props => (props.align === 'left' && 'left: 0;')}
|
|
|
|
|
2020-07-22 21:48:24 +00:00
|
|
|
|
2020-07-22 18:37:44 +00:00
|
|
|
text-align: left;
|
|
|
|
width: ${remSize(180)};
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
height: auto;
|
|
|
|
z-index: 9999;
|
|
|
|
border-radius: ${remSize(6)};
|
|
|
|
|
2020-07-22 19:24:39 +00:00
|
|
|
& li:first-child { border-radius: ${remSize(5)} ${remSize(5)} 0 0; }
|
|
|
|
& li:last-child { border-radius: 0 0 ${remSize(5)} ${remSize(5)}; }
|
|
|
|
|
|
|
|
& li:hover {
|
|
|
|
|
|
|
|
background-color: ${prop('Button.hover.background')};
|
|
|
|
color: ${prop('Button.hover.foreground')};
|
|
|
|
|
|
|
|
& button, & a {
|
|
|
|
color: ${prop('Button.hover.foreground')};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
li {
|
|
|
|
height: ${remSize(36)};
|
|
|
|
cursor: pointer;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
& button,
|
|
|
|
& a {
|
|
|
|
color: ${prop('primaryTextColor')};
|
|
|
|
width: 100%;
|
|
|
|
text-align: left;
|
|
|
|
padding: ${remSize(8)} ${remSize(16)};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2020-07-22 21:48:24 +00:00
|
|
|
// TODO: Add Icon to the left of the items in the menu
|
|
|
|
// const MaybeIcon = (Element, label) => Element && <Element aria-label={label} />;
|
2020-07-22 18:37:44 +00:00
|
|
|
|
2020-07-30 17:36:34 +00:00
|
|
|
const Dropdown = ({ items, align }) => (
|
|
|
|
<DropdownWrapper align={align} >
|
2020-07-22 18:37:44 +00:00
|
|
|
{/* className="nav__items-left" */}
|
2020-07-22 19:24:39 +00:00
|
|
|
{items && items.map(({ title, icon, href }) => (
|
|
|
|
<li key={`nav-${title && title.toLowerCase()}`}>
|
|
|
|
<Link to={href}>
|
2020-07-22 21:48:24 +00:00
|
|
|
{/* {MaybeIcon(icon, `Navigate to ${title}`)} */}
|
2020-07-22 19:24:39 +00:00
|
|
|
{title}
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
))
|
|
|
|
}
|
2020-07-22 18:37:44 +00:00
|
|
|
</DropdownWrapper>
|
2020-07-21 18:03:00 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
Dropdown.propTypes = {
|
2020-07-30 17:36:34 +00:00
|
|
|
align: PropTypes.oneOf(['left', 'right']),
|
2020-07-21 18:03:00 +00:00
|
|
|
items: PropTypes.arrayOf(PropTypes.shape({
|
2020-07-22 19:24:39 +00:00
|
|
|
action: PropTypes.func,
|
|
|
|
icon: PropTypes.func,
|
|
|
|
href: PropTypes.string
|
|
|
|
})),
|
2020-07-21 18:03:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Dropdown.defaultProps = {
|
2020-07-22 19:24:39 +00:00
|
|
|
items: [],
|
2020-07-30 17:36:34 +00:00
|
|
|
align: null
|
2020-07-21 18:03:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Dropdown;
|