import * as React from 'react'; import clsx from 'clsx'; import MenuIcon from '@material-ui/icons/Menu'; import DrawerMenu from './components/DrawerMenu'; import Github from '../_shared/svgIcons/GithubIcon'; import SettingsIcon from '@material-ui/icons/Settings'; import LightbulbOutlineIcon from '../_shared/svgIcons/LightbulbIcon'; import TextDirectionRtLIcon from '@material-ui/icons/FormatTextdirectionRToL'; import TextDirectionLtrIcon from '@material-ui/icons/FormatTextdirectionLToR'; import { GITHUB_URL } from '_constants'; import { createOverrides } from './styleOverrides'; import { withRouter, WithRouterProps } from 'next/router'; import { utilsMap, UtilsLib } from '../utils/utilsService'; import { withStyles, WithStyles, createStyles } from '@material-ui/core/styles'; import { Hidden, Drawer, AppBar, Toolbar, IconButton, Tooltip, Theme, Menu, MenuItem, } from '@material-ui/core'; interface LayoutProps extends WithRouterProps, WithStyles { toggleThemeType: () => void; toggleDirection: () => void; onChangeUtils: (lib: UtilsLib) => void; } const styles = (theme: Theme) => createStyles({ // @ts-ignore '@global': createOverrides(theme), flex: { flex: 1, }, menuButton: { marginLeft: -12, marginRight: 20, }, appBar: { [theme.breakpoints.up('md')]: { width: 'calc(100% - 250px)', left: 250, }, }, utilsMenuItem: { textTransform: 'capitalize', }, main: { padding: '20px', paddingTop: 75, minHeight: 'calc(100vh - 55px)', [theme.breakpoints.up('md')]: { minHeight: 'calc(100vh - 64px)', marginLeft: 250, }, }, content: { [theme.breakpoints.up('lg')]: { maxWidth: 1100, margin: '0 auto', }, }, landingMain: { padding: 0, maxWidth: '100vw', marginLeft: 0, marginRight: 0, }, landingAppBar: { left: 0, right: 0, width: '100vw', boxShadow: 'unset', }, }); class Layout extends React.Component { state = { anchorEl: null, drawerOpen: false, selectedIndex: Object.keys(utilsMap).findIndex((lib) => lib === 'date-fns'), }; handleDrawerToggle = () => { this.setState({ drawerOpen: !this.state.drawerOpen }); }; handleUtilsMenuOpen = (event: React.MouseEvent) => { this.setState({ anchorEl: event.currentTarget }); }; handleUtilsChange = (e: React.MouseEvent, index: number) => { this.props.onChangeUtils(Object.keys(utilsMap)[index] as UtilsLib); this.setState({ selectedIndex: index, anchorEl: null }); }; handleClose = () => { this.setState({ anchorEl: null }); }; scrollToContent = () => { const contentEl = document.getElementById('content'); contentEl!.scrollIntoView({ behavior: 'smooth', block: 'start', }); }; render() { const { anchorEl } = this.state; const { classes, toggleThemeType, toggleDirection, theme, router } = this.props; const isLanding = (router || location).pathname === '/'; return (
{Object.keys(utilsMap).map((option, index) => ( this.handleUtilsChange(event, index)} > {option} ))} {theme.direction === 'rtl' ? : }
{this.props.children}
); } } export default withStyles(styles, { withTheme: true })(withRouter(Layout));