@@ -5,6 +5,7 @@ import { useIsomorphicLayoutEffect } from '@/hooks/useIsomorphicLayoutEffect'
5
5
import clsx from 'clsx'
6
6
import { SearchButton } from '@/components/Search'
7
7
import { Dialog } from '@headlessui/react'
8
+ import { useCallback , useEffect , useState } from 'react'
8
9
9
10
export const SidebarContext = createContext ( )
10
11
@@ -517,11 +518,42 @@ export function SidebarLayout({
517
518
fallbackHref,
518
519
layoutProps : { allowOverflow = true } = { } ,
519
520
} ) {
521
+ /** @type {import('react').MutableRefObject<HTMLElement | null> } */
522
+ const pageWrapper = useRef ( null )
523
+ const [ wrapperOffset , setWrapperOffset ] = useState ( '0px' )
524
+
525
+ const updateWrapperOffset = useCallback (
526
+ ( records ) => {
527
+ let paddingLeft = document . documentElement . style . getPropertyValue ( 'padding-right' ) || '0px'
528
+
529
+ if ( wrapperOffset !== paddingLeft ) {
530
+ setWrapperOffset ( paddingLeft )
531
+ }
532
+ } ,
533
+ [ wrapperOffset ]
534
+ )
535
+
536
+ useEffect ( ( ) => {
537
+ let observer = new MutationObserver ( updateWrapperOffset )
538
+
539
+ observer . observe ( document . documentElement , {
540
+ attributes : true ,
541
+ childList : false ,
542
+ subtree : false ,
543
+ } )
544
+
545
+ return ( ) => observer . disconnect ( )
546
+ } , [ updateWrapperOffset ] )
547
+
520
548
return (
521
549
< SidebarContext . Provider value = { { nav, navIsOpen, setNavIsOpen } } >
522
550
< Wrapper allowOverflow = { allowOverflow } >
523
- < div className = "max-w-8xl mx-auto px-4 sm:px-6 md:px-8" >
524
- < div className = "hidden lg:block fixed z-20 inset-0 top-[3.8125rem] left-[max(0px,calc(50%-45rem))] right-auto w-[19rem] pb-10 pl-8 pr-6 overflow-y-auto" >
551
+ < div
552
+ className = "max-w-8xl mx-auto px-4 sm:px-6 md:px-8"
553
+ ref = { pageWrapper }
554
+ style = { { '--wrapper-offset' : wrapperOffset } }
555
+ >
556
+ < div className = "hidden lg:block fixed z-20 inset-0 top-[3.8125rem] left-[max(0px,calc(calc(50%-45rem)-calc(var(--wrapper-offset)/2)))] right-auto w-[19rem] pb-10 pl-8 pr-6 overflow-y-auto" >
525
557
< Nav nav = { nav } fallbackHref = { fallbackHref } >
526
558
{ sidebar }
527
559
</ Nav >
0 commit comments