Skip to content

Commit 8cf6467

Browse files
committed
add: sidebar position sticky
1 parent 26a1127 commit 8cf6467

File tree

2 files changed

+73
-67
lines changed

2 files changed

+73
-67
lines changed

components/Sidebar.tsx

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -179,77 +179,77 @@ export const SidebarLayout = ({ children }: { children: React.ReactNode }) => {
179179
}
180180
}, [typeof window !== 'undefined']);
181181
return (
182-
<div className='max-w-[1400px] mx-auto flex flex-col items-center'>
183-
<section>
184-
<div className='bg-primary dark:bg-slate-900 w-full h-12 mt-[4.5rem] z-150 flex relative flex-col justify-center items-center lg:hidden '>
185-
<div
186-
className='z-[150] flex w-full bg-primary dark:bg-slate-900 justify-between items-center'
187-
onMouseDown={(e) => e.stopPropagation()}
188-
onClick={(e) => {
189-
e.stopPropagation();
190-
handleRotate();
191-
setOpen(!open);
192-
}}
193-
>
194-
{getDocsPath.includes(pathWtihoutFragment) && (
195-
<h3 className='text-white ml-12'>Overview</h3>
196-
)}
197-
{getStartedPath.includes(pathWtihoutFragment) && (
198-
<h3 className='text-white ml-12'>Getting Started</h3>
199-
)}
200-
201-
{getReferencePath.includes(pathWtihoutFragment) && (
202-
<h3 className='text-white ml-12'>Reference</h3>
203-
)}
204-
205-
{getSpecificationPath.includes(pathWtihoutFragment) && (
206-
<h3 className='text-white ml-12'>Specification</h3>
207-
)}
182+
<div className='max-w-[1400px] mx-auto flex flex-col items-center'>
183+
<section>
184+
<div className='bg-primary dark:bg-slate-900 w-full h-12 mt-[4.5rem] z-150 flex relative flex-col justify-center items-center lg:hidden'>
185+
<div
186+
className='z-[150] flex w-full bg-primary dark:bg-slate-900 justify-between items-center'
187+
onMouseDown={(e) => e.stopPropagation()}
188+
onClick={(e) => {
189+
e.stopPropagation();
190+
handleRotate();
191+
setOpen(!open);
192+
}}
193+
>
194+
{getDocsPath.includes(pathWtihoutFragment) && (
195+
<h3 className='text-white ml-12'>Overview</h3>
196+
)}
197+
{getStartedPath.includes(pathWtihoutFragment) && (
198+
<h3 className='text-white ml-12'>Getting Started</h3>
199+
)}
200+
{getReferencePath.includes(pathWtihoutFragment) && (
201+
<h3 className='text-white ml-12'>Reference</h3>
202+
)}
203+
{getSpecificationPath.includes(pathWtihoutFragment) && (
204+
<h3 className='text-white ml-12'>Specification</h3>
205+
)}
206+
{router.pathname === null && (
207+
<h3 className='text-white ml-12'>Docs</h3>
208+
)}
209+
<svg
210+
style={{
211+
marginRight: '50px',
212+
color: 'white',
213+
transform: rotate,
214+
transition: 'all 0.2s linear',
215+
}}
216+
xmlns='http://www.w3.org/2000/svg'
217+
height='24'
218+
viewBox='0 0 256 512'
219+
>
220+
<path
221+
d='M64 448c-8.188 0-16.38-3.125-22.62-9.375c-12.5-12.5-12.5-32.75 0-45.25L178.8 256L41.38 118.6c-12.5-12.5-12.5-32.75 0-45.25s32.75-12.5 45.25 0l160 160c12.5 12.5 12.5 32.75 0 45.25l-160 160C80.38 444.9 72.19 448 64 448z'
222+
id='mainIconPathAttribute'
223+
fill='#ffffff'
224+
></path>
225+
</svg>
226+
</div>
227+
</div>
208228

209-
{router.pathname === null && (
210-
<h3 className='text-white ml-12'>Docs</h3>
211-
)}
212-
<svg
213-
style={{
214-
marginRight: '50px',
215-
color: 'white',
216-
transform: rotate,
217-
transition: 'all 0.2s linear',
218-
}}
219-
xmlns='http://www.w3.org/2000/svg'
220-
height='24'
221-
viewBox='0 0 256 512'
222-
>
223-
<path
224-
d='M64 448c-8.188 0-16.38-3.125-22.62-9.375c-12.5-12.5-12.5-32.75 0-45.25L178.8 256L41.38 118.6c-12.5-12.5-12.5-32.75 0-45.25s32.75-12.5 45.25 0l160 160c12.5 12.5 12.5 32.75 0 45.25l-160 160C80.38 444.9 72.19 448 64 448z'
225-
id='mainIconPathAttribute'
226-
fill='#ffffff'
227-
></path>
228-
</svg>
229-
</div>
230-
</div>
229+
<div
230+
className={`z-[150] absolute top-10 mt-24 left-0 h-full w-screen bg-white dark:bg-slate-900 dark:shadow-lg transform ${open ? '-translate-x-0' : '-translate-x-full'} transition-transform duration-300 ease-in-out filter drop-shadow-md`}
231+
>
232+
<div className='flex flex-col dark:bg-slate-900'>
233+
<DocsNav open={open} setOpen={setOpen} />
234+
</div>
235+
</div>
231236

232-
<div
233-
className={`z-[150] absolute top-10 mt-24 left-0 h-full w-screen bg-white dark:bg-slate-900 dark:shadow-lg transform ${open ? '-translate-x-0' : '-translate-x-full'} transition-transform duration-300 ease-in-out filter drop-shadow-md `}
234-
>
235-
<div className='flex flex-col dark:bg-slate-900'>
236-
<DocsNav open={open} setOpen={setOpen} />
237-
</div>
238-
</div>
239-
<div className='dark:bg-slate-800 max-w-[1400px] grid grid-cols-1 lg:grid-cols-4 mx-4 md:mx-12'>
240-
<div className='hidden lg:block mt-24'>
241-
<DocsNav open={open} setOpen={setOpen} />
242-
<CarbonAds
243-
className='lg:mt-8 w-4/5 mx-auto lg:ml-4'
244-
variant='sidebar'
245-
/>
246-
</div>
247-
<div className='col-span-4 md:col-span-3 lg:mt-20 lg:w-5/6 mx-4 md:mx-0'>
248-
{children}
249-
</div>
237+
<div className='dark:bg-slate-800 max-w-[1400px] grid grid-cols-1 lg:grid-cols-4 mx-4 md:mx-12'>
238+
<div className='hidden lg:block mt-24 sticky top-24 h-[calc(100vh-6rem)] overflow-hidden'>
239+
<div className='h-full overflow-y-auto scrollbar-hidden'>
240+
<DocsNav open={open} setOpen={setOpen} />
241+
<CarbonAds
242+
className='lg:mt-8 w-4/5 mx-auto lg:ml-4'
243+
variant='sidebar'
244+
/>
250245
</div>
251-
</section>
246+
</div>
247+
<div className='col-span-4 md:col-span-3 lg:mt-20 lg:w-5/6 mx-4 md:mx-0'>
248+
{children}
249+
</div>
252250
</div>
251+
</section>
252+
</div>
253253
);
254254
};
255255

styles/globals.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,9 @@ border-radius: 4px; */
289289
background: grey;
290290
border-radius: 8px;
291291
}
292+
.scrollbar-hidden {
293+
scrollbar-width: none; /* Firefox */
294+
}
295+
.scrollbar-hidden::-webkit-scrollbar {
296+
display: none; /* Chrome, Safari, and Opera */
297+
}

0 commit comments

Comments
 (0)