11import type React from 'react'
22import { PageToggleButton } from '@patternfly/react-core'
3+ import styles from '@patternfly/react-styles/css/components/Page/page'
34import BarsIcon from '@patternfly/react-icons/dist/esm/icons/bars-icon'
45import { useStore } from '@nanostores/react'
56import { isNavOpen } from '../stores/navStore'
@@ -8,38 +9,26 @@ import { useEffect } from 'react'
89export const PageToggle : React . FunctionComponent = ( ) => {
910 const $isNavOpen = useStore ( isNavOpen )
1011
11- /** Applies sidebar styles to the island element astro creates as a wrapper for the sidebar.
12- * Without it the page content will not expand to fill the space left by the sidebar when it is collapsed.
13- */
14- function applySidebarStylesToIsland ( ) {
15- const isClientSide = typeof window !== 'undefined'
16- const sideBarIsland = document . getElementById ( 'page-sidebar' ) ?. parentElement
17-
18- if ( ! isClientSide || ! sideBarIsland ) {
19- return
20- }
21-
22- if ( ! sideBarIsland . classList . contains ( 'pf-v6-c-page__sidebar' ) ) {
23- sideBarIsland . classList . add ( 'pf-v6-c-page__sidebar' , 'pf-m-expanded' )
24- } else {
25- sideBarIsland . classList . toggle ( 'pf-m-expanded' )
26- sideBarIsland . classList . toggle ( 'pf-m-collapsed' )
27- }
28- }
29-
3012 function onToggle ( ) {
3113 isNavOpen . set ( ! $isNavOpen )
3214 }
3315
3416 useEffect ( ( ) => {
35- applySidebarStylesToIsland ( )
17+ const pageComp = document . querySelector ( `.${ styles . page } ` ) ;
18+
19+ if ( pageComp ) {
20+ ( pageComp as HTMLElement ) . style . setProperty (
21+ `--${ styles . page } __sidebar--Width` ,
22+ $isNavOpen ? '' : '0' ,
23+ )
24+ }
3625 } , [ $isNavOpen ] )
3726
3827 return (
3928 < PageToggleButton
40- variant = "plain"
4129 aria-label = "Global navigation"
4230 onSidebarToggle = { onToggle }
31+ isSidebarOpen = { $isNavOpen }
4332 >
4433 < BarsIcon />
4534 </ PageToggleButton >
0 commit comments