Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change mobile menu to use drawer #201

Merged
merged 2 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 1 addition & 32 deletions src/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,6 @@
> .sidebar {
height: 100vh;
background-color: white;
padding: 10px;

.sidebar-logo {
position: relative;
margin: 20px 50px 26px 0;
width: 119px;
font-size: 30px;
border-top: 6px solid gray;
border-bottom: 8px solid gray;
padding-bottom: 0;
line-height: 25px;
}
.sidebar-logo::before {
height: 10px;
width: 10px;
border-radius: 5px;
position: absolute;
background: gray;
top: 28px;
right: 24px;
content: ' '
}
.sidebar-logo::after {
height: 10px;
width: 10px;
border-radius: 5px;
position: absolute;
background: gray;
top: 28px;
left: 17px;
content: ' '
}
padding: 10px;
}
}
21 changes: 13 additions & 8 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { AdapterMoment } from '@mui/x-date-pickers/AdapterMoment'
import { LocalizationProvider } from '@mui/x-date-pickers'

import RoutesList, { PAGES } from './routes'
import MainHeader from './pages/components/header/Header'
import LayoutContext from './layout/LayoutContext'
const { Content } = Layout

const StyledLayout = styled(Layout)`
Expand Down Expand Up @@ -107,14 +109,17 @@ const App = () => {
<LocalizationProvider dateAdapter={AdapterMoment} adapterLocale="he">
<ConfigProvider direction="rtl" locale={heIL}>
<StyledLayout className="main">
<SideBar />
<Layout>
<StyledContent>
<StyledBody>
<RoutesList />
</StyledBody>
</StyledContent>
</Layout>
<LayoutContext>
<SideBar />
<Layout>
<MainHeader />
<StyledContent>
<StyledBody>
<RoutesList />
</StyledBody>
</StyledContent>
</Layout>
</LayoutContext>
</StyledLayout>
</ConfigProvider>
</LocalizationProvider>
Expand Down
12 changes: 12 additions & 0 deletions src/layout/LayoutContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { FC, PropsWithChildren, createContext, useState } from 'react'

export interface LayoutContextInterface {
setDrawerOpen: (isOpen: boolean) => void
drawerOpen: boolean
}
export const LayoutCtx = createContext({} as LayoutContextInterface)
const LayoutContext: FC<PropsWithChildren> = ({ children }) => {
const [drawerOpen, setDrawerOpen] = useState(false)
return <LayoutCtx.Provider value={{ drawerOpen, setDrawerOpen }}>{children}</LayoutCtx.Provider>
}
export default LayoutContext
16 changes: 16 additions & 0 deletions src/pages/components/header/Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Layout } from 'antd'
import { MenuOutlined } from '@ant-design/icons'
import { useContext } from 'react'
import { LayoutContextInterface, LayoutCtx } from 'src/layout/LayoutContext'

const { Header } = Layout

const MainHeader = () => {
const { setDrawerOpen } = useContext<LayoutContextInterface>(LayoutCtx)
return (
<Header style={{ background: 'white' }} className="hideOnDesktop">
<MenuOutlined onClick={() => setDrawerOpen(true)} />
</Header>
)
}
export default MainHeader
37 changes: 23 additions & 14 deletions src/pages/components/header/sidebar/SideBar.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
import { useState } from 'react'
import Menu from './menu/Menu'
import { MenuOutlined } from '@ant-design/icons'
import './sidebar.scss'
import cn from 'classnames'
import { Drawer } from 'antd'
import { useContext } from 'react'
import { LayoutContextInterface, LayoutCtx } from 'src/layout/LayoutContext'

const SidebarToggle = ({ open, setOpen }: { open: boolean; setOpen: (open: boolean) => void }) => (
<div className="sidebar-menu-toggle" onClick={() => setOpen(!open)}>
<MenuOutlined />
const Logo = () => (
<div style={{ overflow: 'hidden' }}>
<h1 className={'sidebar-logo'}>דאטאבוס</h1>
</div>
)

const Logo = () => <h1 className={'sidebar-logo'}>דאטאבוס</h1>

export default function SideBar() {
const [open, setOpen] = useState(false)
const { drawerOpen, setDrawerOpen } = useContext<LayoutContextInterface>(LayoutCtx)

return (
<aside className={cn('sidebar', { open })}>
<Logo />
<SidebarToggle open={open} setOpen={setOpen} />
<Menu />
</aside>
<>
<Drawer
placement="right"
mask
width={280}
onClose={() => setDrawerOpen(false)}
open={drawerOpen}
className="hideOnDesktop">
<Menu />
</Drawer>
<aside className={'sidebar hideOnMobile'}>
<Logo />
<Menu />
</aside>
</>
)
}
59 changes: 59 additions & 0 deletions src/pages/components/header/sidebar/sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,62 @@
}

}
.hideOnMobile {
display: none;
}
@media only screen and (min-width: 768px) {
.hideOnMobile {
display: block;
}
}

.hideOnDesktop {
display: block;
}
@media only screen and (min-width: 768px) {
.hideOnDesktop {
display: none;
}
}

.sidebar-logo {
position: relative;
margin: 20px auto;
width: 119px;
font-size: 30px;
border-top: 6px solid gray;
border-bottom: 8px solid gray;
padding-bottom: 0;
line-height: 25px;
&::before {
height: 10px;
width: 10px;
border-radius: 5px;
position: absolute;
background: gray;
top: 28px;
right: 24px;
content: ' '
}
&::after {
height: 10px;
width: 10px;
border-radius: 5px;
position: absolute;
background: gray;
top: 28px;
left: 17px;
content: ' '
}
}

.sidebar-logo-collapsed {
position: relative;
margin: 20px auto;
text-align: center;
font-size: 30px;
border-top: 6px solid gray;
border-bottom: 8px solid gray;
padding-bottom: 0;
line-height: 25px;
}
Loading