22
33import { Menu } from 'lucide-react'
44import { usePathname } from 'next/navigation'
5- import { useState , useEffect } from 'react'
5+ import { useState , useEffect , useRef } from 'react'
66
77import { DocSidebar , sections } from '@/components/docs/doc-sidebar'
88import { 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 >
0 commit comments