@@ -9,6 +9,11 @@ import { Toc } from './Toc'
99import { twMerge } from 'tailwind-merge'
1010import { TocMobile } from './TocMobile'
1111import { GamLeader } from './Gam'
12+ import { useWidthToggle } from '~/components/DocsLayout'
13+ import {
14+ BsArrowsCollapseVertical ,
15+ BsArrowsExpandVertical ,
16+ } from 'react-icons/bs'
1217
1318type DocProps = {
1419 title : string
@@ -52,6 +57,18 @@ export function Doc({
5257 Record < string , IntersectionObserverEntry >
5358 > ( { } )
5459
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+
5572 React . useEffect ( ( ) => {
5673 const callback = ( headingsList : Array < IntersectionObserverEntry > ) => {
5774 headingElementRefs . current = headingsList . reduce (
@@ -107,7 +124,24 @@ export function Doc({
107124 ) }
108125 >
109126 < 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 }
111145 < div className = "h-4" />
112146 < div className = "h-px bg-gray-500 opacity-20" />
113147 < div className = "h-4" />
0 commit comments