Skip to content

Commit 257cb37

Browse files
docs(layout): add dynamic top/bottom gradient fades for docs sidebar on scroll to improve navigation UX.
🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent 44535dc commit 257cb37

File tree

2 files changed

+70
-5
lines changed

2 files changed

+70
-5
lines changed

web/src/app/docs/layout.tsx

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { Menu } from 'lucide-react'
44
import { usePathname } from 'next/navigation'
5-
import { useState, useEffect } from 'react'
5+
import { useState, useEffect, useRef } from 'react'
66

77
import { DocSidebar, sections } from '@/components/docs/doc-sidebar'
88
import { Button } from '@/components/ui/button'
@@ -15,6 +15,9 @@ export default function DocsLayout({
1515
}) {
1616
const pathname = usePathname()
1717
const [open, setOpen] = useState(false)
18+
const [showTopFade, setShowTopFade] = useState(false)
19+
const [showBottomFade, setShowBottomFade] = useState(false)
20+
const sidebarRef = useRef<HTMLDivElement>(null)
1821

1922
// New: Smoothly scroll to hash target on back/forward navigation
2023
useEffect(() => {
@@ -32,14 +35,48 @@ export default function DocsLayout({
3235
return () => window.removeEventListener('hashchange', handleHashChange)
3336
}, [])
3437

38+
// Handle sidebar scroll for dynamic fade effects
39+
useEffect(() => {
40+
const sidebarElement = sidebarRef.current
41+
if (!sidebarElement) return
42+
43+
const handleScroll = () => {
44+
const { scrollTop, scrollHeight, clientHeight } = sidebarElement
45+
const isAtTop = scrollTop === 0
46+
const isAtBottom = scrollTop + clientHeight >= scrollHeight - 1
47+
48+
setShowTopFade(!isAtTop)
49+
setShowBottomFade(!isAtBottom)
50+
}
51+
52+
// Check initial state
53+
handleScroll()
54+
55+
sidebarElement.addEventListener('scroll', handleScroll)
56+
return () => sidebarElement.removeEventListener('scroll', handleScroll)
57+
}, [])
58+
3559
return (
3660
<div className="pt-8">
3761
<div className="container flex md:space-x-8 overflow-x-hidden">
3862
<div className="hidden lg:block w-64 shrink-0">
39-
<DocSidebar
40-
className="fixed top-24 w-64 h-[calc(100vh-12rem)] overflow-y-auto pr-4 z-40"
41-
onNavigate={() => setOpen(false)}
42-
/>
63+
<div className="fixed top-24 w-64 h-[calc(100vh-12rem)] z-40">
64+
{/* Dynamic gradient fade indicators */}
65+
{showTopFade && (
66+
<div className="absolute top-0 left-0 right-0 h-6 bg-gradient-to-b from-background to-transparent pointer-events-none z-10 rounded-t-lg transition-opacity duration-200" />
67+
)}
68+
{showBottomFade && (
69+
<div className="absolute bottom-0 left-0 right-0 h-6 bg-gradient-to-t from-background to-transparent pointer-events-none z-10 rounded-b-lg transition-opacity duration-200" />
70+
)}
71+
72+
{/* Enhanced scrollable container */}
73+
<div
74+
ref={sidebarRef}
75+
className="relative h-full overflow-y-auto pr-4 pl-4 pt-6 pb-6 custom-scrollbar bg-background/95 backdrop-blur-sm rounded-lg border border-border/50 shadow-lg"
76+
>
77+
<DocSidebar className="" onNavigate={() => setOpen(false)} />
78+
</div>
79+
</div>
4380
</div>
4481
<main className="flex-1 mx-auto pb-36 md:px-8 min-w-0">{children}</main>
4582
</div>

web/src/styles/globals.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,31 @@
133133
.terminal-code::-webkit-scrollbar-thumb:hover {
134134
@apply bg-zinc-600;
135135
}
136+
137+
/* Enhanced docs sidebar scrollbar */
138+
.custom-scrollbar::-webkit-scrollbar {
139+
width: 6px;
140+
}
141+
142+
.custom-scrollbar::-webkit-scrollbar-track {
143+
@apply bg-transparent;
144+
}
145+
146+
.custom-scrollbar::-webkit-scrollbar-thumb {
147+
@apply bg-border/60 rounded-full;
148+
transition: background-color 0.2s ease;
149+
}
150+
151+
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
152+
@apply bg-border;
153+
}
154+
155+
.custom-scrollbar::-webkit-scrollbar-thumb:active {
156+
@apply bg-foreground/20;
157+
}
158+
159+
/* Firefox scrollbar */
160+
.custom-scrollbar {
161+
scrollbar-width: thin;
162+
scrollbar-color: hsl(var(--border) / 0.6) transparent;
163+
}

0 commit comments

Comments
 (0)