@@ -6,6 +6,7 @@ import { tcls } from '@/lib/tailwind';
6
6
7
7
import { PagesList } from './PagesList' ;
8
8
import { TOCScrollContainer } from './TOCScroller' ;
9
+ import { TableOfContentsScript } from './TableOfContentsScript' ;
9
10
import { Trademark } from './Trademark' ;
10
11
11
12
export function TableOfContents ( props : {
@@ -17,97 +18,107 @@ export function TableOfContents(props: {
17
18
const { space, customization, pages } = context ;
18
19
19
20
return (
20
- < aside // Sidebar container, responsible for setting the right dimensions and position for the sidebar.
21
- data-testid = "table-of-contents"
22
- className = { tcls (
23
- 'group' ,
24
- 'text-sm' ,
21
+ < >
22
+ < aside // Sidebar container, responsible for setting the right dimensions and position for the sidebar.
23
+ data-testid = "table-of-contents"
24
+ id = "table-of-contents"
25
+ className = { tcls (
26
+ 'group' ,
27
+ 'text-sm' ,
25
28
26
- 'grow-0' ,
27
- 'shrink-0' ,
28
- 'basis-full' ,
29
- 'lg:basis-72' ,
30
- 'page-no-toc:lg:basis-56' ,
29
+ 'grow-0' ,
30
+ 'shrink-0' ,
31
+ 'basis-full' ,
32
+ 'lg:basis-72' ,
33
+ 'page-no-toc:lg:basis-56' ,
31
34
32
- 'relative' ,
33
- 'z-[1]' ,
34
- 'lg:sticky' ,
35
- // Without header
36
- 'lg:top-0' ,
37
- 'lg:h-screen' ,
35
+ 'relative' ,
36
+ 'z-[1]' ,
37
+ 'lg:sticky' ,
38
38
39
- // With header
40
- 'site-header:lg:top-16' ,
41
- 'site-header:lg:h-[calc(100vh_-_4rem)]' ,
39
+ // Server-side static positioning
40
+ 'lg:top-0' ,
41
+ 'lg:h-screen' ,
42
+ 'announcement:lg:h-[calc(100vh-4.25rem)]' ,
42
43
43
- // With header and sections
44
- 'site-header-sections :lg:top-[6.75rem ]' ,
45
- ' site-header-sections :lg:h-[calc(100vh_-_6.75rem )]',
44
+ 'site-header:lg:top-16' ,
45
+ 'site-header:lg:h-[calc(100vh-4rem) ]' ,
46
+ 'announcement: site-header:lg:h-[calc(100vh-4rem-4.25rem )]',
46
47
47
- 'pt-6' ,
48
- 'pb-4' ,
49
- 'sidebar-filled:lg:pr-6' ,
50
- 'page-no-toc:lg:pr-0' ,
48
+ 'site-header-sections:lg:top-[6.75rem]' ,
49
+ 'site-header-sections:lg:h-[calc(100vh-6.75rem)]' ,
50
+ 'announcement:site-header-sections:lg:h-[calc(100vh-6.75rem-4.25rem)]' ,
51
51
52
- 'hidden' ,
53
- 'navigation-open:!flex' ,
54
- 'lg:flex' ,
55
- 'page-no-toc:lg:hidden' ,
56
- 'page-no-toc:xl:flex' ,
57
- 'site-header-none:page-no-toc:lg:flex' ,
58
- 'flex-col' ,
59
- 'gap-4' ,
52
+ // Client-side dynamic positioning (CSS vars applied by script)
53
+ '[html[style*="--toc-top-offset"]_&]:lg:!top-[var(--toc-top-offset)]' ,
54
+ '[html[style*="--toc-height"]_&]:lg:!h-[var(--toc-height)]' ,
60
55
61
- 'navigation-open:border-b' ,
62
- 'border-tint-subtle'
63
- ) }
64
- >
65
- { header && header }
66
- < div // The actual sidebar, either shown with a filled bg or transparent.
67
- className = { tcls (
68
- 'lg:-ms-5' ,
69
- 'relative flex flex-grow flex-col overflow-hidden border-tint-subtle' ,
56
+ 'pt-6' ,
57
+ 'pb-4' ,
58
+ 'sidebar-filled:lg:pr-6' ,
59
+ 'page-no-toc:lg:pr-0' ,
70
60
71
- 'sidebar-filled:bg-tint-subtle' ,
72
- 'theme-muted:bg-tint-subtle' ,
73
- '[html.sidebar-filled.theme-bold.tint_&]:bg-tint-subtle' ,
74
- '[html.sidebar-filled.theme-muted_&]:bg-tint-base' ,
75
- '[html.sidebar-filled.theme-bold.tint_&]:bg-tint-base' ,
76
- '[html.sidebar-filled.theme-gradient_&]:border' ,
77
- 'page-no-toc:!bg-transparent' ,
61
+ 'hidden' ,
62
+ 'navigation-open:!flex' ,
63
+ 'lg:flex' ,
64
+ 'page-no-toc:lg:hidden' ,
65
+ 'page-no-toc:xl:flex' ,
66
+ 'site-header-none:page-no-toc:lg:flex' ,
67
+ 'flex-col' ,
68
+ 'gap-4' ,
78
69
79
- 'sidebar-filled:rounded-xl ' ,
80
- 'straight-corners:rounded-none '
70
+ 'navigation-open:border-b ' ,
71
+ 'border-tint-subtle '
81
72
) }
82
73
>
83
- { innerHeader && < div className = "px-5 *:my-4" > { innerHeader } </ div > }
84
- < TOCScrollContainer // The scrollview inside the sidebar
74
+ { header && header }
75
+ < div // The actual sidebar, either shown with a filled bg or transparent.
85
76
className = { tcls (
86
- 'flex flex-grow flex-col p-2' ,
87
- customization . trademark . enabled && 'lg:pb-20' ,
88
- 'lg:gutter-stable overflow-y-auto' ,
89
- '[&::-webkit-scrollbar]:bg-transparent' ,
90
- '[&::-webkit-scrollbar-thumb]:bg-transparent' ,
91
- 'group-hover:[&::-webkit-scrollbar]:bg-tint-subtle' ,
92
- 'group-hover:[&::-webkit-scrollbar-thumb]:bg-tint-7' ,
93
- 'group-hover:[&::-webkit-scrollbar-thumb:hover]:bg-tint-8'
77
+ 'lg:-ms-5' ,
78
+ 'relative flex flex-grow flex-col overflow-hidden border-tint-subtle' ,
79
+
80
+ 'sidebar-filled:bg-tint-subtle' ,
81
+ 'theme-muted:bg-tint-subtle' ,
82
+ '[html.sidebar-filled.theme-bold.tint_&]:bg-tint-subtle' ,
83
+ '[html.sidebar-filled.theme-muted_&]:bg-tint-base' ,
84
+ '[html.sidebar-filled.theme-bold.tint_&]:bg-tint-base' ,
85
+ '[html.sidebar-filled.theme-gradient_&]:border' ,
86
+ 'page-no-toc:!bg-transparent' ,
87
+
88
+ 'sidebar-filled:rounded-xl' ,
89
+ 'straight-corners:rounded-none'
94
90
) }
95
91
>
96
- < PagesList
97
- rootPages = { pages }
98
- pages = { pages }
99
- context = { context }
100
- style = "page-no-toc:hidden border-tint-subtle sidebar-list-line:border-l"
101
- />
102
- { customization . trademark . enabled ? (
103
- < Trademark
104
- space = { space }
105
- customization = { customization }
106
- placement = { SiteInsightsTrademarkPlacement . Sidebar }
92
+ { innerHeader && < div className = "px-5 *:my-4" > { innerHeader } </ div > }
93
+ < TOCScrollContainer // The scrollview inside the sidebar
94
+ className = { tcls (
95
+ 'flex flex-grow flex-col p-2' ,
96
+ customization . trademark . enabled && 'lg:pb-20' ,
97
+ 'lg:gutter-stable overflow-y-auto' ,
98
+ '[&::-webkit-scrollbar]:bg-transparent' ,
99
+ '[&::-webkit-scrollbar-thumb]:bg-transparent' ,
100
+ 'group-hover:[&::-webkit-scrollbar]:bg-tint-subtle' ,
101
+ 'group-hover:[&::-webkit-scrollbar-thumb]:bg-tint-7' ,
102
+ 'group-hover:[&::-webkit-scrollbar-thumb:hover]:bg-tint-8'
103
+ ) }
104
+ >
105
+ < PagesList
106
+ rootPages = { pages }
107
+ pages = { pages }
108
+ context = { context }
109
+ style = "page-no-toc:hidden border-tint-subtle sidebar-list-line:border-l"
107
110
/>
108
- ) : null }
109
- </ TOCScrollContainer >
110
- </ div >
111
- </ aside >
111
+ { customization . trademark . enabled ? (
112
+ < Trademark
113
+ space = { space }
114
+ customization = { customization }
115
+ placement = { SiteInsightsTrademarkPlacement . Sidebar }
116
+ />
117
+ ) : null }
118
+ </ TOCScrollContainer >
119
+ </ div >
120
+ </ aside >
121
+ < TableOfContentsScript />
122
+ </ >
112
123
) ;
113
124
}
0 commit comments