Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap the widgets screen design #14612

Merged
merged 8 commits into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions assets/stylesheets/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ $z-layers: (
".block-library-gallery-item__inline-menu": 20,
".block-editor-url-input__suggestions": 30,
".edit-post-header": 30,
".edit-widgets-header": 30,
".block-library-button__inline-link .block-editor-url-input__suggestions": 6, // URL suggestions for button block above sibling inserter
".block-library-image__resize-handlers": 1, // Resize handlers above sibling inserter
".wp-block-cover__inner-container": 1, // InnerBlocks area inside cover image block
Expand Down Expand Up @@ -64,6 +65,7 @@ $z-layers: (
// Show sidebar above wp-admin navigation bar for mobile viewports:
// #wpadminbar { z-index: 99999 }
".edit-post-sidebar": 100000,
".edit-widgets-sidebar": 100000,
".edit-post-layout .edit-post-post-publish-panel": 100001,

// Show sidebar in greater than small viewports above editor related elements
Expand Down
2 changes: 1 addition & 1 deletion lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ function gutenberg_register_scripts_and_styles() {
gutenberg_override_style(
'wp-edit-widgets',
gutenberg_url( 'build/edit-widgets/style.css' ),
array(),
array( 'wp-components', 'wp-block-editor', 'wp-edit-blocks' ),
filemtime( gutenberg_dir_path() . 'build/edit-widgets/style.css' )
);
wp_style_add_data( 'wp-edit-widgets', 'rtl', 'replace' );
Expand Down
4 changes: 4 additions & 0 deletions lib/packages-dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@
'wp-viewport',
),
'wp-edit-widgets' => array(
'wp-block-editor',
'wp-block-library',
'wp-components',
'wp-element',
'wp-i18n',
),
'wp-editor' => array(
'lodash',
Expand Down
6 changes: 5 additions & 1 deletion lib/widgets-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
function the_gutenberg_widgets() {
?>
<div class="blocks-widgets-container">
<div id="widgets-editor" class="blocks-widgets-container">
</div>
<?php
}
Expand All @@ -29,6 +29,10 @@ function gutenberg_widgets_init( $hook ) {
return;
}

wp_add_inline_script(
'wp-edit-widgets',
'wp.editWidgets.initialize( "widgets-editor" )'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should include a terminating semi-colon. Otherwise it may result in other wp_add_inline_script for wp-edit-widgets being treated as a continuation of this code, e.g. an IIFE would result in "VM662:2 Uncaught TypeError: wp.editWidgets.initialize(...) is not a function".

);
wp_enqueue_script( 'wp-edit-widgets' );
wp_enqueue_style( 'wp-edit-widgets' );
}
Expand Down
5 changes: 4 additions & 1 deletion packages/edit-widgets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
"react-native": "src/index",
"dependencies": {
"@babel/runtime": "^7.0.0",
"@wordpress/element": "file:../element"
"@wordpress/block-editor": "file:../block-editor",
"@wordpress/components": "file:../components",
"@wordpress/element": "file:../element",
"@wordpress/i18n": "file:../i18n"
},
"publishConfig": {
"access": "public"
Expand Down
28 changes: 28 additions & 0 deletions packages/edit-widgets/src/components/header/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* WordPress dependencies
*/
import { Button } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

function Header() {
return (
<div
className="edit-widgets-header"
role="region"
aria-label={ __( 'Widgets screen top bar' ) }
tabIndex="-1"
>
<h1 className="edit-widgets-header__title">
{ __( 'Block Areas' ) } { __( '(experimental)' ) }
</h1>

<div className="edit-widgets-header__actions">
<Button isPrimary isLarge>
{ __( 'Update' ) }
</Button>
</div>
</div>
);
}

export default Header;
37 changes: 37 additions & 0 deletions packages/edit-widgets/src/components/header/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.edit-widgets-header {
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid $light-gray-500;
height: $header-height;
background: $white;
z-index: z-index(".edit-widgets-header");

left: 0;
right: 0;
// Stick the toolbar to the top, because the admin bar is not fixed on mobile.
top: 0;
position: sticky;

// 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;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of these styles to properly style the sidebar and the top bar and the main area are shared with the edit-post module. While I don't mind duplication as it's very related to the screen (those screens are similar) but I think we could extract some reusable mixins here (maybe a follow-up).

}
@include editor-left(".edit-widgets-header");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible future task: Is there sense in making this specific to "editor"? Or is it more about how the UI interacts with the admin sidebar more generally?


.edit-widgets-header__title {
font-size: 16px;
padding: 0 20px;
margin: 0;
}

.edit-widgets-header__actions {
padding: 0 20px;
}
42 changes: 42 additions & 0 deletions packages/edit-widgets/src/components/layout/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* WordPress dependencies
*/
import { Fragment } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { navigateRegions } from '@wordpress/components';

/**
* Internal dependencies
*/
import Header from '../header';
import Sidebar from '../sidebar';
import WidgetArea from '../widget-area';

function Layout() {
const areas = [
Copy link
Member

@noisysocks noisysocks Mar 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Time for our favourite past time... ✨ naming things!

It looks like WordPress calls the part of the page where a group of widgets appears a "sidebar" in the code but a "Widget Area" in the documentation. Which term should we use in Gutenberg?

I am thinking it would be confusing, after Phase 2 is merged into trunk, to have both wp.data.select( 'core/edit-widgets' ).getWidgetAreas() and register_sidebar().

(Nothing to do with this PR—just trying to get ahead of the terminology here.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I don't really know. I don't like "sidebars" personally as it's not really what these things are meant for but I can be on board with it for consistency. @aduth our naming expert to the rescue? :P

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help text in the current widgets screen also includes some references to this concept as a "widget area", so there's certainly precedent for both cases. I assume it's likely a matter of historical legacy on the "sidebar" naming.

image

Phase 2 could be a good opportunity to push to adopt the "area" naming, and move away from considering these as constrained to sidebars. Consistency with existing function naming is worth considering, but I also wonder if it's not out-of-the-question to consider a soft-deprecation of existing register_sidebar functions in favor of newly-introduced equivalent register_widget_area, etc. functions? It would need to be a conscious and agreed-upon effort, but I could definitely get behind "area" naming if that were an option.

In any case, I also agree that it needn't block merging this, especially as they're not exposed as part of a public interface (aside from the one class name).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was some conversation about this in the customizer issue as well. I went with "Block Areas" in the prototype.

__( 'Sidebar' ),
__( 'Footer' ),
__( 'Header' ),
];

return (
<Fragment>
<Header />
<Sidebar />
<div
className="edit-widgets-layout__content"
role="region"
aria-label={ __( 'Widgets screen content' ) }
tabIndex="-1"
>
{ areas.map( ( area, index ) => (
<div key={ index } className="edit-widgets-layout__area">
<WidgetArea title={ area } initialOpen={ index === 0 } />
</div>
) ) }
</div>
</Fragment>
);
}

export default navigateRegions( Layout );
16 changes: 16 additions & 0 deletions packages/edit-widgets/src/components/layout/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.edit-widgets-layout__content {
min-height: 100%;
background: $light-gray-300;
padding: 30px 0;

// Temporarily disable the sidebar on mobile
@include break-small() {
margin-right: $sidebar-width;
margin-top: $header-height;
}
}

.edit-widgets-layout__area {
max-width: $content-width;
margin: 0 auto 30px;
}
20 changes: 20 additions & 0 deletions packages/edit-widgets/src/components/sidebar/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* WordPress dependencies
*/
import { Panel } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

function Sidebar() {
return (
<div
className="edit-widgets-sidebar"
role="region"
aria-label={ __( 'Widgets advanced settings' ) }
tabIndex="-1"
>
<Panel header={ __( 'Block Areas' ) } />
</div>
);
}

export default Sidebar;
42 changes: 42 additions & 0 deletions packages/edit-widgets/src/components/sidebar/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.edit-widgets-sidebar {
position: fixed;
z-index: z-index(".edit-widgets-sidebar");
top: 0;
right: 0;
bottom: 0;
width: $sidebar-width;
border-left: $border-width solid $light-gray-500;
background: $white;
color: $dark-gray-500;
height: 100vh;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is height necessary if top, right, bottom are zero'd ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know, this is copied from the edit-post but I can test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like an explicit change done for mobile here #1691

In my testing it doesn't impact to remove but given how fragile these things are, I prefer to leave and defer to @jasmussen

overflow: hidden;

@include break-small() {
top: $admin-bar-height-big + $header-height;
z-index: z-index(".edit-post-sidebar {greater than small}");
height: auto;
overflow: auto;
-webkit-overflow-scrolling: touch;
}

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

// Temporarily disable the sidebar on mobile
display: none;
@include break-small() {
display: block;
}

> .components-panel {
margin-top: -1px;
margin-bottom: -1px;
border-left: 0;
border-right: 0;

> .components-panel__header {
background: $light-gray-200;
}
}
}
32 changes: 32 additions & 0 deletions packages/edit-widgets/src/components/widget-area/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* WordPress dependencies
*/
import { Panel, PanelBody } from '@wordpress/components';
import {
BlockEditorProvider,
BlockList,
} from '@wordpress/block-editor';
import { useState } from '@wordpress/element';

function WidgetArea( { title, initialOpen } ) {
const [ blocks, updateBlocks ] = useState( [] );

return (
<Panel>
<PanelBody
title={ title }
initialOpen={ initialOpen }
>
<BlockEditorProvider
value={ blocks }
onInput={ updateBlocks }
onChange={ updateBlocks }
>
<BlockList />
</BlockEditorProvider>
</PanelBody>
</Panel>
);
}

export default WidgetArea;
22 changes: 18 additions & 4 deletions packages/edit-widgets/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,22 @@
* WordPress dependencies
*/
import { render } from '@wordpress/element';
import { registerCoreBlocks } from '@wordpress/block-library';

render(
<h1>Widgets (beta)</h1>,
document.querySelector( '.blocks-widgets-container' )
);
/**
* Internal dependencies
*/
import Layout from './components/layout';

/**
* Initilizes the widgets screen
*
* @param {string} id Id of the root element to render the screen.
*/
export function initialize( id ) {
registerCoreBlocks();
render(
<Layout />,
document.getElementById( id )
);
}
25 changes: 24 additions & 1 deletion packages/edit-widgets/src/style.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@import "./components/header/style.scss";
@import "./components/layout/style.scss";
@import "./components/sidebar/style.scss";

// In order to use mix-blend-mode, this element needs to have an explicitly set background-color
// We scope it to .wp-toolbar to be wp-admin only, to prevent bleed into other implementations
html.wp-toolbar {
Expand All @@ -12,8 +16,27 @@ body.gutenberg_page_gutenberg-widgets {
// The modals are shown outside the .blocks-widgets-container wrapper, they need these styles
.components-modal__frame {
@include reset;

youknowriad marked this conversation as resolved.
Show resolved Hide resolved
}

.blocks-widgets-container {
padding: 0 10px;
// On mobile the main content area has to scroll, otherwise you can invoke
// the overscroll bounce on the non-scrolling container, for a bad experience.
@include break-small {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
min-height: calc(100vh - #{ $admin-bar-height-big });
}

// The WP header height changes at this breakpoint.
@include break-medium {
min-height: calc(100vh - #{ $admin-bar-height });
}

> .components-navigate-regions {
height: 100%;
}
}