Skip to content

Commit

Permalink
Revert "Revert "Fullscreen Mode: Change the "Back" button to toggle t…
Browse files Browse the repository at this point in the history
…he sidebar (#21121)" (#21929)"

This reverts commit caf52c1.
  • Loading branch information
Jon Q authored and shaunandrews committed May 8, 2020
1 parent fca4e02 commit 8af4377
Show file tree
Hide file tree
Showing 14 changed files with 230 additions and 88 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,5 @@ describe( 'Fullscreen Mode', () => {
} );

expect( isFullscreenEnabled ).toBe( true );

const fullscreenCloseButton = await page.$(
'.edit-post-fullscreen-mode-close'
);

expect( fullscreenCloseButton ).not.toBeNull();
} );
} );

This file was deleted.

This file was deleted.

9 changes: 6 additions & 3 deletions packages/edit-post/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import { Button } from '@wordpress/components';
import { PostSavedState, PostPreviewButton } from '@wordpress/editor';
import { useSelect, useDispatch } from '@wordpress/data';
import { cog } from '@wordpress/icons';
import { PinnedItems } from '@wordpress/interface';
import { PinnedItems, AdminMenuToggle } from '@wordpress/interface';

/**
* Internal dependencies
*/
import FullscreenModeClose from './fullscreen-mode-close';
import HeaderToolbar from './header-toolbar';
import MoreMenu from './more-menu';
import PostPublishButtonOrToggle from './post-publish-button-or-toggle';
Expand All @@ -29,6 +28,7 @@ function Header( {
isPublishSidebarOpened,
isSaving,
getBlockSelectionStart,
isFullscreenActive,
} = useSelect(
( select ) => ( {
shortcut: select(
Expand All @@ -45,6 +45,9 @@ function Header( {
getBlockSelectionStart: select( 'core/block-editor' )
.getBlockSelectionStart,
isPostSaveable: select( 'core/editor' ).isEditedPostSaveable(),
isFullscreenActive: select( 'core/edit-post' ).isFeatureActive(
'fullscreenMode'
),
deviceType: select(
'core/edit-post'
).__experimentalGetPreviewDeviceType(),
Expand All @@ -66,7 +69,7 @@ function Header( {

return (
<div className="edit-post-header">
<FullscreenModeClose />
{ isFullscreenActive && <AdminMenuToggle /> }
<div className="edit-post-header__toolbar">
<HeaderToolbar
onToggleInserter={ onToggleInserter }
Expand Down
1 change: 0 additions & 1 deletion packages/edit-post/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ $footer-height: $button-size-small;
@import "../../interface/src/style.scss";

@import "./components/header/style.scss";
@import "./components/header/fullscreen-mode-close/style.scss";
@import "./components/header/header-toolbar/style.scss";
@import "./components/header/more-menu/style.scss";
@import "./components/keyboard-shortcut-help-modal/style.scss";
Expand Down
11 changes: 10 additions & 1 deletion packages/edit-site/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
__experimentalPreviewOptions as PreviewOptions,
} from '@wordpress/block-editor';
import { useSelect, useDispatch } from '@wordpress/data';
import { PinnedItems } from '@wordpress/interface';
import { PinnedItems, AdminMenuToggle } from '@wordpress/interface';

/**
* Internal dependencies
Expand Down Expand Up @@ -54,6 +54,15 @@ export default function Header( { openEntitiesSavedStates } ) {
[]
);

const { isFullscreenActive } = useSelect(
( select ) => ( {
isFullscreenActive: select( 'core/edit-site' ).isFeatureActive(
'fullscreenMode'
),
} ),
[]
);

const deviceType = useSelect( ( select ) => {
return select( 'core/edit-site' ).__experimentalGetPreviewDeviceType();
}, [] );
Expand Down
1 change: 0 additions & 1 deletion packages/edit-site/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

@import "./components/block-editor/style.scss";
@import "./components/header/style.scss";
@import "./components/header/fullscreen-mode-close/style.scss";
@import "./components/header/more-menu/style.scss";
@import "./components/notices/style.scss";
@import "./components/sidebar/style.scss";
Expand Down
1 change: 1 addition & 0 deletions packages/interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@wordpress/element": "file:../element",
"@wordpress/i18n": "file:../i18n",
"@wordpress/icons": "file:../icons",
"@wordpress/keycodes": "file:../keycodes",
"@wordpress/plugins": "file:../plugins",
"classnames": "^2.2.5",
"lodash": "^4.17.15"
Expand Down
105 changes: 105 additions & 0 deletions packages/interface/src/components/admin-menu-toggle/index.js
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 packages/interface/src/components/admin-menu-toggle/style.scss
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;
}
}
}
Loading

0 comments on commit 8af4377

Please sign in to comment.