import React, { RefObject, Fragment } from 'react'; import { Link, withRouter, RouteComponentProps } from 'react-router-dom'; import { Drawer, AppBar, Toolbar, Avatar, Divider, Button, Box, IconButton } from '@material-ui/core'; import { ClickAwayListener, Popper, Hidden, Typography } from '@material-ui/core'; import { List, ListItem, ListItemIcon, ListItemText, ListItemAvatar } from '@material-ui/core'; import { Card, CardContent, CardActions } from '@material-ui/core'; import { withStyles, createStyles, Theme, WithTheme, WithStyles, withTheme } from '@material-ui/core/styles'; import WifiIcon from '@material-ui/icons/Wifi'; import SettingsIcon from '@material-ui/icons/Settings'; import AccessTimeIcon from '@material-ui/icons/AccessTime'; import AccountCircleIcon from '@material-ui/icons/AccountCircle'; import SettingsInputAntennaIcon from '@material-ui/icons/SettingsInputAntenna'; import DeviceHubIcon from '@material-ui/icons/DeviceHub'; import LockIcon from '@material-ui/icons/Lock'; import MenuIcon from '@material-ui/icons/Menu'; import ProjectMenu from '../project/ProjectMenu'; import { PROJECT_NAME } from '../api'; import { withAuthenticatedContext, AuthenticatedContextProps } from '../authentication'; import { withFeatures, WithFeaturesProps } from '../features/FeaturesContext'; const drawerWidth = 290; const styles = (theme: Theme) => createStyles({ root: { display: 'flex', }, drawer: { [theme.breakpoints.up('md')]: { width: drawerWidth, flexShrink: 0, }, }, title: { flexGrow: 1 }, appBar: { marginLeft: drawerWidth, [theme.breakpoints.up('md')]: { width: `calc(100% - ${drawerWidth}px)`, }, }, toolbarImage: { [theme.breakpoints.up('xs')]: { height: 24, marginRight: theme.spacing(2) }, [theme.breakpoints.up('sm')]: { height: 36, marginRight: theme.spacing(3) }, }, menuButton: { marginRight: theme.spacing(2), [theme.breakpoints.up('md')]: { display: 'none', }, }, toolbar: theme.mixins.toolbar, drawerPaper: { width: drawerWidth, }, content: { flexGrow: 1 }, authMenu: { zIndex: theme.zIndex.tooltip, maxWidth: 400, }, authMenuActions: { padding: theme.spacing(2), "& > * + *": { marginLeft: theme.spacing(2), } }, }); interface MenuAppBarState { mobileOpen: boolean; authMenuOpen: boolean; } interface MenuAppBarProps extends WithFeaturesProps, AuthenticatedContextProps, WithTheme, WithStyles, RouteComponentProps { sectionTitle: string; } class MenuAppBar extends React.Component { constructor(props: MenuAppBarProps) { super(props); this.state = { mobileOpen: false, authMenuOpen: false }; } anchorRef: RefObject = React.createRef(); handleToggle = () => { this.setState({ authMenuOpen: !this.state.authMenuOpen }); } handleClose = (event: React.MouseEvent) => { if (this.anchorRef.current && this.anchorRef.current.contains(event.currentTarget)) { return; } this.setState({ authMenuOpen: false }); } handleDrawerToggle = () => { this.setState({ mobileOpen: !this.state.mobileOpen }); }; render() { const { classes, theme, children, sectionTitle, authenticatedContext, features } = this.props; const { mobileOpen, authMenuOpen } = this.state; const path = this.props.match.url; const drawer = (
{PROJECT_NAME} {PROJECT_NAME} {features.project && ( )} {features.ntp && ( )} {features.mqtt && ( )} {features.security && ( )}
); const userMenu = (
); return (
{sectionTitle} {features.security && userMenu}
{children}
); } } export default withRouter( withTheme( withFeatures( withAuthenticatedContext( withStyles(styles)(MenuAppBar) ) ) ) );