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;
|
2020-08-06 18:59:22 +00:00
|
|
|
z-index: 2;
|
2020-07-22 18:37:44 +00:00
|
|
|
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')};
|
|
|
|
|
2020-08-12 13:25:41 +00:00
|
|
|
* { color: ${prop('Button.hover.foreground')}; }
|
2020-07-22 19:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
li {
|
|
|
|
height: ${remSize(36)};
|
|
|
|
cursor: pointer;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
& button,
|
2020-08-12 13:25:41 +00:00
|
|
|
& button span,
|
2020-07-22 19:24:39 +00:00
|
|
|
& a {
|
2020-08-13 12:34:09 +00:00
|
|
|
padding: ${remSize(8)} ${remSize(16)};
|
|
|
|
}
|
|
|
|
|
|
|
|
* {
|
2020-07-22 19:24:39 +00:00
|
|
|
text-align: left;
|
2020-08-12 13:25:41 +00:00
|
|
|
justify-content: left;
|
2020-08-13 12:34:09 +00:00
|
|
|
|
2020-07-22 19:24:39 +00:00
|
|
|
color: ${prop('primaryTextColor')};
|
|
|
|
width: 100%;
|
2020-08-13 12:34:09 +00:00
|
|
|
justify-content: flex-start;
|
2020-07-22 19:24:39 +00:00
|
|
|
}
|
2020-08-12 13:25:41 +00:00
|
|
|
|
|
|
|
& button span { padding: 0px }
|
2020-07-22 19:24:39 +00:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
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-08-12 13:19:06 +00:00
|
|
|
{items && items.map(({
|
|
|
|
title, icon, href, action
|
|
|
|
}) => (
|
2020-07-22 19:24:39 +00:00
|
|
|
<li key={`nav-${title && title.toLowerCase()}`}>
|
2020-08-12 13:25:41 +00:00
|
|
|
{/* {MaybeIcon(icon, `Navigate to ${title}`)} */}
|
2020-08-12 13:19:06 +00:00
|
|
|
{href
|
|
|
|
? <IconButton to={href}>{title}</IconButton>
|
|
|
|
: <IconButton onClick={() => action()}>{title}</IconButton>}
|
|
|
|
|
2020-07-22 19:24:39 +00:00
|
|
|
</li>
|
|
|
|
))
|
|
|
|
}
|
2020-07-22 18:37:44 +00:00
|
|
|
</DropdownWrapper>
|
2020-07-21 18:03:00 +00:00
|
|
|
);
|
|
|
|
|
2020-08-12 13:19:06 +00:00
|
|
|
|
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,
|
2020-08-20 18:59:05 +00:00
|
|
|
href: PropTypes.string,
|
|
|
|
title: PropTypes.string
|
2020-07-22 19:24:39 +00:00
|
|
|
})),
|
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;
|