@@ -9,6 +9,11 @@ import { Toc } from './Toc'
9
9
import { twMerge } from 'tailwind-merge'
10
10
import { TocMobile } from './TocMobile'
11
11
import { GamLeader } from './Gam'
12
+ import { useWidthToggle } from '~/components/DocsLayout'
13
+ import {
14
+ BsArrowsCollapseVertical ,
15
+ BsArrowsExpandVertical ,
16
+ } from 'react-icons/bs'
12
17
13
18
type DocProps = {
14
19
title : string
@@ -52,6 +57,18 @@ export function Doc({
52
57
Record < string , IntersectionObserverEntry >
53
58
> ( { } )
54
59
60
+ // Try to get the width toggle context from DocsLayout
61
+ let isFullWidth = false
62
+ let setIsFullWidth : ( ( isFullWidth : boolean ) => void ) | undefined
63
+
64
+ try {
65
+ const context = useWidthToggle ( )
66
+ isFullWidth = context . isFullWidth
67
+ setIsFullWidth = context . setIsFullWidth
68
+ } catch {
69
+ // Context not available, that's okay
70
+ }
71
+
55
72
React . useEffect ( ( ) => {
56
73
const callback = ( headingsList : Array < IntersectionObserverEntry > ) => {
57
74
headingElementRefs . current = headingsList . reduce (
@@ -107,7 +124,24 @@ export function Doc({
107
124
) }
108
125
>
109
126
< GamLeader />
110
- { title ? < DocTitle > { title } </ DocTitle > : null }
127
+ { title ? (
128
+ < div className = "flex items-center justify-between gap-4" >
129
+ < DocTitle > { title } </ DocTitle >
130
+ { setIsFullWidth && (
131
+ < button
132
+ onClick = { ( ) => setIsFullWidth ( ! isFullWidth ) }
133
+ className = "p-2 mr-4 text-gray-600 hover:text-gray-800 dark:text-gray-400 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors flex-shrink-0 hidden [@media(min-width:1800px)]:inline-flex"
134
+ title = { isFullWidth ? 'Constrain width' : 'Expand width' }
135
+ >
136
+ { isFullWidth ? (
137
+ < BsArrowsCollapseVertical className = "w-4 h-4" />
138
+ ) : (
139
+ < BsArrowsExpandVertical className = "w-4 h-4" />
140
+ ) }
141
+ </ button >
142
+ ) }
143
+ </ div >
144
+ ) : null }
111
145
< div className = "h-4" />
112
146
< div className = "h-px bg-gray-500 opacity-20" />
113
147
< div className = "h-4" />
0 commit comments