1- import React , { useMemo , useState } from "react" ;
1+ import React , { useCallback , useMemo , useState } from "react" ;
22import { styled } from "@linaria/react" ;
33import {
44 DeclarationsContext ,
@@ -83,6 +83,7 @@ export default function DeclarationsPage({
8383} ) {
8484 const [ filter , setFilter ] = useState ( "" ) ;
8585 const [ search , setSearch ] = useState ( "" ) ;
86+ const [ sidebarOpen , setSidebarOpen ] = useState ( false ) ;
8687
8788 const references = useMemo ( ( ) => buildReferences ( context . declarations ) , [ context . declarations ] ) ;
8889
@@ -104,14 +105,20 @@ export default function DeclarationsPage({
104105 const searchCtx = useMemo ( ( ) => ( { search, setSearch } ) , [ search , setSearch ] ) ;
105106 const filterCtx = useMemo ( ( ) => ( { filter, setFilter } ) , [ filter , setFilter ] ) ;
106107
108+ const closeSidebar = useCallback ( ( ) => setSidebarOpen ( false ) , [ ] ) ;
109+ const openSidebar = useCallback ( ( ) => setSidebarOpen ( true ) , [ ] ) ;
110+
107111 return (
108112 < DeclarationsContext . Provider value = { fullContext } >
109113 < SearchContext . Provider value = { searchCtx } >
110114 < SidebarFilterContext . Provider value = { filterCtx } >
111115 < PageGrid >
112- < DeclarationsSidebar />
116+ < MobileSidebarOverlay data-open = { sidebarOpen || undefined } onClick = { closeSidebar } />
117+ < SidebarPanel data-open = { sidebarOpen || undefined } >
118+ < DeclarationsSidebar onNavigate = { closeSidebar } />
119+ </ SidebarPanel >
113120 < ContentColumn >
114- < NavBar baseUrl = { context . root } />
121+ < NavBar baseUrl = { context . root } onMenuClick = { openSidebar } />
115122 < ContentList />
116123 </ ContentColumn >
117124 </ PageGrid >
@@ -127,15 +134,49 @@ const ContentColumn = styled.div`
127134 overflow: hidden;
128135` ;
129136
137+ const MobileSidebarOverlay = styled . div `
138+ display: none;
139+
140+ @media (max-width: 768px) {
141+ &[data-open] {
142+ display: block;
143+ position: fixed;
144+ inset: 0;
145+ background: rgba(0, 0, 0, 0.5);
146+ z-index: 300;
147+ }
148+ }
149+ ` ;
150+
151+ const SidebarPanel = styled . div `
152+ display: contents;
153+
154+ @media (max-width: 768px) {
155+ display: none;
156+ position: fixed;
157+ top: 0;
158+ left: 0;
159+ bottom: 0;
160+ width: 300px;
161+ z-index: 301;
162+ background: var(--sidebar);
163+
164+ &[data-open] {
165+ display: flex;
166+ }
167+
168+ > * {
169+ flex: 1;
170+ min-height: 0;
171+ }
172+ }
173+ ` ;
174+
130175const PageGrid = styled . div `
131176 display: grid;
132177 grid-template-columns: 340px 1fr;
133178 height: 100dvh;
134179
135- @media (max-width: 1100px) {
136- grid-template-columns: 200px 1fr;
137- }
138-
139180 @media (max-width: 768px) {
140181 grid-template-columns: 1fr;
141182 }
0 commit comments