@@ -19,23 +19,29 @@ import { PageLastUpdated } from '../PageLastUpdated';
19
19
import Feedback from '../Feedback' ;
20
20
import RepoActions from '../Menu/RepoActions' ;
21
21
import { usePathWithoutHash } from '@/utils/usePathWithoutHash' ;
22
+ import { TableOfContents } from '../TableOfContents' ;
22
23
23
24
export const LayoutHeader = ( {
24
25
currentPlatform,
25
26
isGen1,
26
27
pageType = 'inner' ,
27
28
showLastUpdatedDate = true ,
28
- showTOC
29
+ showTOC,
30
+ tocHeadings
29
31
} : {
30
32
currentPlatform : Platform ;
31
33
isGen1 : boolean ;
32
34
pageType ?: 'home' | 'inner' ;
33
35
showLastUpdatedDate : boolean ;
34
36
showTOC ?: boolean ;
37
+ tocHeadings ;
35
38
} ) => {
36
39
const { menuOpen, toggleMenuOpen } = useContext ( LayoutContext ) ;
37
40
const menuButtonRef = useRef < HTMLButtonElement > ( null ) ;
38
41
const sidebarMenuButtonRef = useRef < HTMLButtonElement > ( null ) ;
42
+ const { tocOpen, toggleTocOpen } = useContext ( LayoutContext ) ;
43
+ const tocButtonRef = useRef < HTMLButtonElement > ( null ) ;
44
+ const sidebarTocButtonRef = useRef < HTMLButtonElement > ( null ) ;
39
45
const router = useRouter ( ) ;
40
46
const asPathWithNoHash = usePathWithoutHash ( ) ;
41
47
@@ -51,6 +57,18 @@ export const LayoutHeader = ({
51
57
}
52
58
} ;
53
59
60
+ const handleTocToggle = ( ) => {
61
+ if ( ! tocOpen ) {
62
+ toggleTocOpen ( true ) ;
63
+ // For keyboard navigators, move focus to the close menu button in the nav
64
+ setTimeout ( ( ) => sidebarTocButtonRef ?. current ?. focus ( ) , 0 ) ;
65
+ } else {
66
+ toggleTocOpen ( false ) ;
67
+ // For keyboard navigators, move focus back to menu button in header
68
+ tocButtonRef ?. current ?. focus ( ) ;
69
+ }
70
+ } ;
71
+
54
72
// Search result transform function that will strip out the pageMain anchor tag
55
73
// Algolia search results include the anchor tag where the content was found but since we
56
74
// are aggregating records this ends up always being the pageMain anchor tag which is the
@@ -78,6 +96,16 @@ export const LayoutHeader = ({
78
96
Menu
79
97
</ Button >
80
98
99
+ < Button
100
+ onClick = { ( ) => handleTocToggle ( ) }
101
+ size = "small"
102
+ ref = { tocButtonRef }
103
+ className = "search-menu-toggle mobile-toggle"
104
+ >
105
+ < IconMenu aria-hidden = "true" />
106
+ On this page
107
+ </ Button >
108
+
81
109
< View
82
110
className = { classNames (
83
111
'layout-search__search' ,
@@ -149,6 +177,41 @@ export const LayoutHeader = ({
149
177
</ div >
150
178
</ View >
151
179
</ View >
180
+
181
+ { /* toc */ }
182
+ < View
183
+ className = { classNames ( 'layout-sidebar' , {
184
+ 'layout-sidebar--expanded' : tocOpen
185
+ } ) }
186
+ >
187
+ < Button
188
+ size = "small"
189
+ colorTheme = "overlay"
190
+ className = { classNames ( 'layout-sidebar__mobile-toggle' , 'right-menu' , {
191
+ 'layout-sidebar__mobile-toggle--open' : tocOpen
192
+ } ) }
193
+ ref = { sidebarTocButtonRef }
194
+ onClick = { ( ) => handleTocToggle ( ) }
195
+ >
196
+ < IconDoubleChevron />
197
+ < VisuallyHidden > Close table of contents</ VisuallyHidden >
198
+ </ Button >
199
+ < View
200
+ className = { classNames ( 'layout-sidebar__backdrop' , {
201
+ 'layout-sidebar__backdrop--expanded' : tocOpen
202
+ } ) }
203
+ onClick = { ( ) => toggleTocOpen ( false ) }
204
+ > </ View >
205
+ < View
206
+ className = { classNames ( 'layout-sidebar__inner' , 'right-menu' , {
207
+ 'layout-sidebar__inner--expanded' : tocOpen
208
+ } ) }
209
+ >
210
+ < div className = "layout-sidebar-menu" >
211
+ < TableOfContents headers = { tocHeadings } />
212
+ </ div >
213
+ </ View >
214
+ </ View >
152
215
</ View >
153
216
) ;
154
217
} ;
0 commit comments