1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/frontend/src/component/menu/drawer.jsx

104 lines
3.4 KiB
React
Raw Normal View History

2021-06-29 10:35:09 +02:00
import { Divider, Drawer, List } from '@material-ui/core';
import PropTypes from 'prop-types';
2021-06-29 10:35:09 +02:00
import GitHubIcon from '@material-ui/icons/GitHub';
import LibraryBooksIcon from '@material-ui/icons/LibraryBooks';
import styles from './drawer.module.scss';
import { ReactComponent as LogoIcon } from '../../assets/icons/logo_wbg.svg';
import NavigationLink from './Header/NavigationLink/NavigationLink';
import ConditionallyRender from '../common/ConditionallyRender';
2020-05-12 20:41:03 +02:00
export const DrawerMenu = ({
links = [],
title = 'Unleash',
flags = {},
open = false,
toggleDrawer,
admin,
routes,
}) => {
const renderLinks = () => {
return links.map(link => {
let icon = null;
if (link.value === 'GitHub') {
icon = <GitHubIcon className={styles.navigationIcon} />;
} else if (link.value === 'Documentation') {
icon = <LibraryBooksIcon className={styles.navigationIcon} />;
}
return (
<a
href={link.href}
rel="noopener noreferrer"
target="_blank"
className={styles.iconLink}
key={link.value}
>
{icon}
{link.value}
</a>
);
});
};
return (
<Drawer
className={styles.drawer}
open={open}
anchor={'left'}
onClose={() => toggleDrawer()}
>
<div className={styles.drawerContainer}>
<div>
<span className={[styles.drawerTitle].join(' ')}>
<LogoIcon className={styles.drawerTitleLogo} />
<span className={styles.drawerTitleText}>{title}</span>
</span>
</div>
<Divider />
<List className={styles.drawerList}>
{routes.mainNavRoutes.map(item => (
<NavigationLink
handleClose={() => toggleDrawer()}
path={item.path}
text={item.title}
key={item.path}
/>
))}
</List>
<ConditionallyRender
condition={admin}
show={
<>
<Divider />
<List className={styles.drawerList}>
{routes.adminRoutes.map(item => (
<NavigationLink
handleClose={() => toggleDrawer()}
path={item.path}
text={item.title}
key={item.path}
/>
))}
</List>
</>
}
/>
<Divider />
<div className={styles.iconLinkList}>{renderLinks()}</div>
</div>
</Drawer>
);
};
DrawerMenu.propTypes = {
links: PropTypes.array,
2020-10-05 21:51:45 +02:00
title: PropTypes.string,
flags: PropTypes.object,
open: PropTypes.bool,
toggleDrawer: PropTypes.func,
};