Skip to content

Commit

Permalink
Improve the Back to WP button in Fullscreen Mode (#20603)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored and jorgefilipecosta committed Mar 10, 2020
1 parent d8e0dd1 commit c7ed00e
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 43 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 @@ -22,10 +22,10 @@ describe( 'Fullscreen Mode', () => {

expect( isFullscreenEnabled ).toBe( true );

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

expect( fullscreenToolbar ).not.toBeNull();
expect( fullscreenCloseButton ).not.toBeNull();
} );
} );
1 change: 1 addition & 0 deletions packages/edit-post/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@wordpress/media-utils": "file:../media-utils",
"@wordpress/notices": "file:../notices",
"@wordpress/plugins": "file:../plugins",
"@wordpress/primitives": "file:../primitives",
"@wordpress/url": "file:../url",
"@wordpress/viewport": "file:../viewport",
"classnames": "^2.2.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,45 @@ import { get } from 'lodash';
/**
* WordPress dependencies
*/
import { withSelect } from '@wordpress/data';
import { Button, Toolbar } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { Button } from '@wordpress/components';
import { Path, SVG } from '@wordpress/primitives';
import { __ } from '@wordpress/i18n';
import { addQueryArgs } from '@wordpress/url';
import { chevronLeft } from '@wordpress/icons';

function FullscreenModeClose( { isActive, postType } ) {
const wordPressLogo = (
<SVG width="28" height="28" viewBox="0 0 128 128" version="1.1">
<Path d="M100 61.3c0-6.6-2.4-11.2-4.4-14.7-2.7-4.4-5.2-8.1-5.2-12.5 0-4.9 3.7-9.5 9-9.5h.7c-9.5-8.7-22.1-14-36-14-18.6 0-35 9.6-44.6 24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4 3.5.4 5.5z" />
</SVG>
);

function FullscreenModeClose() {
const { isActive, postType } = useSelect( ( select ) => {
const { getCurrentPostType } = select( 'core/editor' );
const { isFeatureActive } = select( 'core/edit-post' );
const { getPostType } = select( 'core' );

return {
isActive: isFeatureActive( 'fullscreenMode' ),
postType: getPostType( getCurrentPostType() ),
};
}, [] );

if ( ! isActive || ! postType ) {
return null;
}

return (
<Toolbar className="edit-post-fullscreen-mode-close__toolbar">
<Button
icon={ chevronLeft }
href={ addQueryArgs( 'edit.php', {
post_type: postType.slug,
} ) }
label={ get(
postType,
[ 'labels', 'view_items' ],
__( 'Back' )
) }
/>
</Toolbar>
<Button
className="edit-post-fullscreen-mode-close"
icon={ wordPressLogo }
iconSize={ 36 }
href={ addQueryArgs( 'edit.php', {
post_type: postType.slug,
} ) }
label={ get( postType, [ 'labels', 'view_items' ], __( 'Back' ) ) }
/>
);
}

export default withSelect( ( select ) => {
const { getCurrentPostType } = select( 'core/editor' );
const { isFeatureActive } = select( 'core/edit-post' );
const { getPostType } = select( 'core' );

return {
isActive: isFeatureActive( 'fullscreenMode' ),
postType: getPostType( getCurrentPostType() ),
};
} )( FullscreenModeClose );
export default FullscreenModeClose;
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
.edit-post-fullscreen-mode-close__toolbar {
.edit-post-fullscreen-mode-close.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;
border-top: 0;
border-bottom: 0;
border-left: 0;
margin: -9px 10px -8px -10px;
padding: 9px 10px;
align-items: center;
align-self: stretch;
border: none;
background: #23282e; // WP-admin gray.
color: $white;
border-radius: 0;
height: auto;
width: $header-height;

&:hover {
background: #32373d !important; // WP-admin light-gray.
color: $white !important;
box-shadow: none !important;
}

&:active {
color: $white;
}
}
svg {
margin-left: auto;
margin-right: auto;
}
}
2 changes: 1 addition & 1 deletion packages/edit-post/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ function Header() {

return (
<div className="edit-post-header">
<FullscreenModeClose />
<div className="edit-post-header__toolbar">
<FullscreenModeClose />
<HeaderToolbar />
</div>
<div className="edit-post-header__settings">
Expand Down
9 changes: 3 additions & 6 deletions packages/edit-post/src/components/header/style.scss
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
.edit-post-header {
height: $header-height;
padding: $grid-size-small 2px;
background: $white;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
// The header should never be wider than the viewport, or buttons might be hidden. Especially relevant at high zoom levels. Related to https://core.trac.wordpress.org/ticket/47603#ticket.
max-width: 100vw;
Expand All @@ -14,10 +12,6 @@
flex-wrap: nowrap;
}

@include break-small {
padding: $grid-size;
}

// Some browsers, most notably IE11, honor an older version of the flexbox spec
// which takes absolutely positioned items into account when calculating `space-between`.
// https://www.w3.org/TR/2012/WD-css3-flexbox-20120612/#abspos-flex-items
Expand All @@ -39,12 +33,15 @@

.edit-post-header__toolbar {
display: flex;
flex-grow: 1;
padding-left: $grid-size * 2;
}

.edit-post-header__settings {
display: inline-flex;
align-items: center;
flex-wrap: wrap;
padding-right: $grid-size;
}

.edit-post-header .components-button {
Expand Down

0 comments on commit c7ed00e

Please sign in to comment.