-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "Fullscreen Mode: Change the "Back" button to toggle t…
- Loading branch information
1 parent
fca4e02
commit 8af4377
Showing
14 changed files
with
230 additions
and
88 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 0 additions & 44 deletions
44
packages/edit-post/src/components/header/fullscreen-mode-close/index.js
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
packages/edit-post/src/components/header/fullscreen-mode-close/style.scss
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
packages/interface/src/components/admin-menu-toggle/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Button } from '@wordpress/components'; | ||
import { useRef, useEffect, useState } from '@wordpress/element'; | ||
import { ESCAPE, TAB } from '@wordpress/keycodes'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { wordpress } from '@wordpress/icons'; | ||
|
||
function AdminMenuToggle() { | ||
const buttonRef = useRef(); | ||
const toggleMenu = useToggle( { ref: buttonRef } ); | ||
|
||
return ( | ||
<Button | ||
className="interface-admin-menu-toggle" | ||
icon={ wordpress } | ||
iconSize={ 36 } | ||
onClick={ toggleMenu } | ||
label={ __( 'Show sidebar menu' ) } | ||
ref={ buttonRef } | ||
/> | ||
); | ||
} | ||
|
||
function useToggle( { ref } ) { | ||
const [ isActive, setIsActive ] = useState( false ); | ||
const buttonNode = ref?.current; | ||
|
||
const adminMenuNode = document.querySelector( '#adminmenumain' ); | ||
|
||
const toggleClassName = 'is-showing-admin-menu'; | ||
|
||
const toggleAdminMenu = () => setIsActive( ! isActive ); | ||
const closeAdminMenu = () => setIsActive( false ); | ||
|
||
const focusFirstAdminMenuItem = () => { | ||
if ( ! buttonNode ) return; | ||
|
||
const isButtonFocused = buttonNode.matches( ':focus' ); | ||
const item = adminMenuNode.querySelector( '#adminmenu > li > a' ); | ||
|
||
if ( isButtonFocused && item ) { | ||
item.focus(); | ||
} | ||
}; | ||
|
||
// Renders the open/closed UI for the admin menu | ||
useEffect( () => { | ||
if ( isActive ) { | ||
document.body.classList.add( toggleClassName ); | ||
} else { | ||
document.body.classList.remove( toggleClassName ); | ||
} | ||
}, [ isActive ] ); | ||
|
||
// Handles closing the admin menu when clicking outside | ||
useEffect( () => { | ||
const handleOnClickOutside = ( event ) => { | ||
if ( ! isActive ) return; | ||
|
||
const { target } = event; | ||
|
||
const didClickOutside = | ||
! adminMenuNode.contains( target ) && target !== buttonNode; | ||
|
||
if ( didClickOutside ) { | ||
closeAdminMenu(); | ||
} | ||
}; | ||
|
||
document.body.addEventListener( 'click', handleOnClickOutside ); | ||
|
||
return () => { | ||
document.body.removeEventListener( 'click', handleOnClickOutside ); | ||
}; | ||
}, [ isActive, buttonNode ] ); | ||
|
||
// Handles admin menu keyboard interactions | ||
useEffect( () => { | ||
const handleOnKeyDown = ( event ) => { | ||
if ( ! isActive ) return; | ||
|
||
const { keyCode } = event; | ||
|
||
if ( keyCode === ESCAPE ) { | ||
closeAdminMenu(); | ||
} | ||
|
||
if ( keyCode === TAB ) { | ||
focusFirstAdminMenuItem(); | ||
} | ||
}; | ||
|
||
document.body.addEventListener( 'keydown', handleOnKeyDown ); | ||
|
||
return () => { | ||
document.body.removeEventListener( 'keydown', handleOnKeyDown ); | ||
}; | ||
}, [ isActive ] ); | ||
|
||
return toggleAdminMenu; | ||
} | ||
|
||
export default AdminMenuToggle; |
52 changes: 52 additions & 0 deletions
52
packages/interface/src/components/admin-menu-toggle/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
.interface-admin-menu-toggle.has-icon { | ||
// Do not show the toolbar icon on small screens, | ||
// when Fullscreen Mode is not an option in the "More" menu. | ||
display: none; | ||
|
||
@include break-medium() { | ||
display: flex; | ||
align-items: center; | ||
align-self: stretch; | ||
border: none; | ||
border-radius: 0; | ||
height: auto; | ||
width: $header-height; | ||
background: #23282e; // WP-admin gray. | ||
transition: all 0.12s ease-in-out; | ||
|
||
svg { | ||
padding: 6px; | ||
pointer-events: none; | ||
border-radius: 2px; | ||
width: 44px; | ||
height: 44px; | ||
fill: $white; | ||
} | ||
|
||
&:hover { | ||
svg { | ||
fill: rgba($white, 0.8); | ||
} | ||
} | ||
|
||
&:active { | ||
color: $white; | ||
} | ||
|
||
&:focus { | ||
box-shadow: none; | ||
|
||
svg { | ||
box-shadow: 0 0 0 1.5px color($theme-color); | ||
} | ||
} | ||
|
||
body.is-showing-admin-menu & { | ||
width: 160px; | ||
} | ||
|
||
body.is-showing-admin-menu.folded & { | ||
width: $header-height; | ||
} | ||
} | ||
} |
Oops, something went wrong.