@@ -2,13 +2,15 @@ import { Route, Switch } from "react-router-dom";
22import { default as AntdLayout } from "antd/es/layout" ;
33import { AppHeader } from "pages/common/header" ;
44import * as React from "react" ;
5- import { ReactElement } from "react" ;
5+ import { ReactElement , useState , useEffect } from "react" ;
66import { HelpDropdown } from "pages/common/help" ;
77import MainContent from "components/layout/MainContent" ;
88import SideBar from "components/layout/SideBar" ;
99import { CNMainContent , CNSidebar } from "constants/styleSelectors" ;
1010import { SideBarSection , SideBarSectionProps } from "./SideBarSection" ;
1111import styled from "styled-components" ;
12+ import { MenuOutlined } from "@ant-design/icons" ;
13+ import { Drawer , Button } from "antd" ;
1214
1315type LayoutProps = {
1416 sections : SideBarSectionProps [ ] ;
@@ -29,9 +31,53 @@ const SideBarV2 = styled(SideBar)`
2931 }
3032` ;
3133
34+ const MobileMenuButton = styled ( Button ) `
35+ display: none;
36+ position: fixed;
37+ top: 75px;
38+ right: 22px;
39+ z-index: 1000;
40+
41+ @media screen and (max-width: 720px) {
42+ display: block;
43+ }
44+ ` ;
45+
46+ const DrawerContentWrapper = styled . div `
47+ height: 100%;
48+ display: flex;
49+ flex-direction: column;
50+ ` ;
51+
3252export function Layout ( props : LayoutProps ) {
53+
54+ const [ drawerVisible , setDrawerVisible ] = useState ( false ) ;
55+ const [ isMobile , setIsMobile ] = useState ( false ) ;
56+
57+ const toggleDrawer = ( ) => {
58+ setDrawerVisible ( ! drawerVisible ) ;
59+ } ;
60+
61+ const handleMenuClick = ( ) => {
62+ setDrawerVisible ( false ) ; // Close the drawer
63+ } ;
64+
65+ useEffect ( ( ) => {
66+ const handleResize = ( ) => setIsMobile ( window . innerWidth <= 720 ) ;
67+ handleResize ( ) ; // Check on initial render
68+ window . addEventListener ( "resize" , handleResize ) ;
69+ return ( ) => window . removeEventListener ( "resize" , handleResize ) ;
70+ } , [ ] ) ;
71+
72+ const mobileSections = props . sections . map ( ( section ) => ( {
73+ ...section ,
74+ items : section . items . filter ( ( item ) => item . mobileVisible !== false ) , // Filter mobile-visible items
75+ } ) ) ;
76+
77+ const desktopSections = props . sections ;
78+
3379 const routes : ReactElement [ ] = [ ] ;
34- props . sections . forEach ( ( section ) => {
80+ desktopSections . forEach ( ( section ) => {
3581 section . items . forEach ( ( item ) => {
3682 routes . push (
3783 < Route
@@ -48,18 +94,57 @@ export function Layout(props: LayoutProps) {
4894 < AntdLayout style = { { height : "100%" } } >
4995 < AppHeader />
5096 < HelpDropdown />
97+
98+ { /* Mobile Hamburger Button */ }
99+ { isMobile && (
100+ < MobileMenuButton
101+ type = "primary"
102+ shape = "circle"
103+ icon = { < MenuOutlined /> }
104+ onClick = { toggleDrawer }
105+ />
106+ ) }
107+
108+ { /* Drawer for Mobile Sidebar */ }
109+ < Drawer
110+ width = { "240px" }
111+ placement = "right"
112+ closable = { true }
113+ onClose = { toggleDrawer }
114+ visible = { drawerVisible }
115+ bodyStyle = { { padding : "0px" } }
116+ destroyOnClose // Ensure drawer content is removed when closed
117+ >
118+ < DrawerContentWrapper >
119+ < SideBarV2 className = { CNSidebar } >
120+ { mobileSections
121+ . filter ( ( section ) => section . items . length > 0 )
122+ . map ( ( section , index ) => (
123+ < SideBarSection
124+ key = { index }
125+ { ...section }
126+ onItemClick = { handleMenuClick } // Pass handler to close the drawer
127+ />
128+ ) ) }
129+ </ SideBarV2 >
130+ </ DrawerContentWrapper >
131+ </ Drawer >
132+
133+ { /* Desktop Layout */ }
51134 < AntdLayout >
52- < SideBarV2 className = { CNSidebar } >
53- { props . sections
54- . filter ( ( section ) => section . items . length > 0 )
55- . map ( ( section , index ) => (
56- < SideBarSection key = { index } { ...section } />
57- ) ) }
58- </ SideBarV2 >
135+ { ! isMobile && (
136+ < SideBarV2 className = { `${ CNSidebar } desktop-only` } >
137+ { desktopSections
138+ . filter ( ( section ) => section . items . length > 0 )
139+ . map ( ( section , index ) => (
140+ < SideBarSection key = { index } { ...section } />
141+ ) ) }
142+ </ SideBarV2 >
143+ ) }
59144 < MainContent className = { CNMainContent } >
60- < Switch > { routes } </ Switch >
145+ < Switch > { routes } </ Switch >
61146 </ MainContent >
62147 </ AntdLayout >
63148 </ AntdLayout >
64149 ) ;
65- }
150+ }
0 commit comments