Skip to content

Commit

Permalink
Refactor layout component
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Oct 23, 2019
1 parent 78b3925 commit 80c0eac
Show file tree
Hide file tree
Showing 16 changed files with 290 additions and 337 deletions.
15 changes: 0 additions & 15 deletions assets/stylesheets/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -312,21 +312,6 @@
}
}

/**
* Applies editor right position to the selector passed as argument
*/

@mixin editor-right($selector) {
#{ $selector } {
right: 0;
}

.edit-post-layout.is-sidebar-opened #{ $selector } {
right: $sidebar-width;
}
}


/**
* Styles that are reused verbatim in a few places
*/
Expand Down
2 changes: 1 addition & 1 deletion assets/stylesheets/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ $z-layers: (
".components-autocomplete__results": 1000000,

".skip-to-selected-block": 100000,
".edit-post-toggle-publish-panel": 100000,
".edit-post-editor-regions__publish": 100000,

// Show NUX tips above popovers, wp-admin menus, submenus, and sidebar:
".nux-dot-tip": 1000001,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.components-navigate-regions.is-focusing-regions [role="region"] {
position: relative;

// For browsers that don't support outline-offset (IE11).
&:focus::after {
content: "";
Expand Down
72 changes: 72 additions & 0 deletions packages/edit-post/src/components/editor-regions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
import { navigateRegions } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

function EditorRegions( { footer, header, sidebar, content, publish, className } ) {
return (
<div className={ classnames( className, 'edit-post-editor-regions' ) }>
{ !! header && (
<div
className="edit-post-editor-regions__header"
role="region"
/* translators: accessibility text for the top bar landmark region. */
aria-label={ __( 'Editor top bar' ) }
tabIndex="-1"
>
{ header }
</div>
) }
<div className="edit-post-editor-regions__body">
<div
className="edit-post-editor-regions__content"
role="region"
/* translators: accessibility text for the content landmark region. */
aria-label={ __( 'Editor content' ) }
tabIndex="-1"
>
{ content }
</div>
{ !! publish && (
<div
className="edit-post-editor-regions__publish"
role="region"
/* translators: accessibility text for the publish landmark region. */
aria-label={ __( 'Editor publish' ) }
tabIndex="-1"
>
{ publish }
</div>
) }
{ !! sidebar && (
<div
className="edit-post-editor-regions__sidebar"
role="region"
aria-label={ 'Editor settings' }
tabIndex="-1"
>
{ sidebar }
</div>
) }
</div>
{ !! footer && (
<div
className="edit-post-editor-regions__footer"
role="region"
aria-label={ 'Editor footer' }
tabIndex="-1"
>
{ footer }
</div>
) }
</div>
);
}

export default navigateRegions( EditorRegions );
97 changes: 97 additions & 0 deletions packages/edit-post/src/components/editor-regions/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
.edit-post-editor-regions {
display: flex;
flex-direction: column;
height: 100%;
max-height: 100%;
position: relative;

// On Mobile keep a margin for the header and admin header
// as both of these are fixed
top: 0;
@include break-small() {
margin-top: 0;

// On Desktop position the container as fixed to avoid scroll bleed.
position: fixed;
top: $admin-bar-height-big;
left: 0;
right: 0;
bottom: 0;
height: auto;
}

@include break-medium() {
top: $admin-bar-height;
}
}
@include editor-left(".edit-post-editor-regions");

.edit-post-editor-regions__body {
flex-grow: 1;
display: flex;

// On Mobile the header is fixed to keep HTML as scrollable.
@include break-small() {
overflow: auto;
}
}

.edit-post-editor-regions__content {
flex-grow: 1;

// On Mobile the header is fixed to keep HTML as scrollable.
@include break-small() {
overflow: auto;
}
}

.edit-post-editor-regions__sidebar {
width: auto; // Keep the sidebar width flexible.
flex-shrink: 0;

// On Mobile the header is fixed to keep HTML as scrollable.
@include break-small() {
overflow: auto;
}
}

.edit-post-editor-regions__header {
flex-shrink: 0;
height: auto; // Keep the height flexible.

// On Mobile the header is sticky.
position: sticky;
top: 0;
@include break-small() {
// Cancel the fixed positionning used in mobile.
position: initial;
overflow: auto;
}
}

.edit-post-editor-regions__footer {
height: auto; // Keep the height flexible.
flex-shrink: 0;
overflow: auto;

// On Mobile the footer is hidden
display: none;
@include break-small() {
display: block;
}
}

.edit-post-editor-regions__publish {
z-index: z-index(".edit-post-editor-regions__publish");
position: fixed !important; // Need to override the default relative positionning
top: -9999em;
bottom: auto;
left: auto;
right: 0;
width: $sidebar-width;

&:focus {
top: auto;
bottom: 0;
}
}
8 changes: 1 addition & 7 deletions packages/edit-post/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,7 @@ function Header( {
const toggleGeneralSidebar = isEditorSidebarOpened ? closeGeneralSidebar : openGeneralSidebar;

return (
<div
role="region"
/* translators: accessibility text for the top bar landmark region. */
aria-label={ __( 'Editor top bar' ) }
className="edit-post-header"
tabIndex="-1"
>
<div className="edit-post-header">
<div className="edit-post-header__toolbar">
<FullscreenModeClose />
<HeaderToolbar />
Expand Down
19 changes: 0 additions & 19 deletions packages/edit-post/src/components/header/style.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.edit-post-header {
height: $header-height;
padding: $grid-size-small 2px;
border-bottom: $border-width solid $light-gray-500;
background: $white;
Expand All @@ -10,30 +9,14 @@
// 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;
z-index: z-index(".edit-post-header");
left: 0;
right: 0;

// Make toolbar sticky on larger breakpoints
@include break-zoomed-in {
height: $header-height;
top: 0;
position: sticky;
flex-wrap: nowrap;
}

// On mobile the main content area has to scroll, otherwise you can invoke the overscroll bounce on the non-scrolling container.
@include break-small {
position: fixed;
padding: $grid-size;
top: $admin-bar-height-big;
}

@include break-medium() {
top: $admin-bar-height;

body.is-fullscreen-mode & {
top: 0;
}
}

// Some browsers, most notably IE11, honor an older version of the flexbox spec
Expand All @@ -55,8 +38,6 @@
}
}

@include editor-left(".edit-post-header");

.edit-post-header__toolbar {
display: flex;
}
Expand Down
Loading

0 comments on commit 80c0eac

Please sign in to comment.