11import type React from 'react'
2+ import styles from '@patternfly/react-styles/css/components/Page/page'
23import { PageToggleButton } from '@patternfly/react-core'
34import BarsIcon from '@patternfly/react-icons/dist/esm/icons/bars-icon'
45import { useStore } from '@nanostores/react'
@@ -8,38 +9,40 @@ 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 ( ) {
12+ function onToggle ( ) {
13+ isNavOpen . set ( ! $isNavOpen )
14+ }
15+
16+ useEffect ( ( ) => {
17+ /** Applies sidebar styles to the island element astro creates as a wrapper for the sidebar.
18+ * Without it the page content will not expand to fill the space left by the sidebar when it is collapsed.
19+ */
20+ // Possibly can refactor to remove applying classes when https://github.com/patternfly/patternfly/issues/7377 goes in
1521 const isClientSide = typeof window !== 'undefined'
16- const sideBarIsland = document . getElementById ( 'page-sidebar' ) ?. parentElement
22+ const sideBarIsland =
23+ document . getElementById ( 'page-sidebar-body' ) ?. parentElement
1724
1825 if ( ! isClientSide || ! sideBarIsland ) {
1926 return
2027 }
2128
22- if ( ! sideBarIsland . classList . contains ( 'pf-v6-c-page__sidebar' ) ) {
23- sideBarIsland . classList . add ( 'pf-v6-c-page__sidebar' , 'pf-m-expanded' )
29+ if ( ! sideBarIsland . classList . contains ( styles . pageSidebar ) ) {
30+ sideBarIsland . classList . add (
31+ styles . pageSidebar ,
32+ $isNavOpen ? styles . modifiers . expanded : styles . modifiers . collapsed ,
33+ )
2434 } else {
25- sideBarIsland . classList . toggle ( 'pf-m- expanded' )
26- sideBarIsland . classList . toggle ( 'pf-m- collapsed' )
35+ sideBarIsland . classList . toggle ( styles . modifiers . expanded )
36+ sideBarIsland . classList . toggle ( styles . modifiers . collapsed )
2737 }
28- }
29-
30- function onToggle ( ) {
31- isNavOpen . set ( ! $isNavOpen )
32- }
33-
34- useEffect ( ( ) => {
35- applySidebarStylesToIsland ( )
38+ sideBarIsland . setAttribute ( 'aria-hidden' , `${ ! $isNavOpen } ` )
3639 } , [ $isNavOpen ] )
3740
3841 return (
3942 < PageToggleButton
40- variant = "plain"
4143 aria-label = "Global navigation"
4244 onSidebarToggle = { onToggle }
45+ isSidebarOpen = { $isNavOpen }
4346 >
4447 < BarsIcon />
4548 </ PageToggleButton >
0 commit comments