From 0c121d49a13c10a60bb2de6dc8caacb84e7d22d1 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Thu, 12 Oct 2017 09:13:23 +0100 Subject: [PATCH] Block Toolbar: Move the block toolbar to the editor's header --- components/navigable-menu/index.js | 4 ++ editor/assets/stylesheets/_z-index.scss | 1 - editor/block-switcher/style.scss | 7 --- editor/block-toolbar/index.js | 65 ++++++++++--------------- editor/block-toolbar/style.scss | 60 ++--------------------- editor/header/index.js | 2 + editor/modes/visual-editor/block.js | 2 +- 7 files changed, 38 insertions(+), 103 deletions(-) diff --git a/components/navigable-menu/index.js b/components/navigable-menu/index.js index d4ce50ee065e52..5932b088a04e90 100644 --- a/components/navigable-menu/index.js +++ b/components/navigable-menu/index.js @@ -26,6 +26,10 @@ class NavigableMenu extends Component { } onKeyDown( event ) { + if ( this.props.onKeyDown ) { + this.props.onKeyDown( event ); + } + const { orientation = 'vertical', onNavigate = noop, deep = false } = this.props; if ( ( orientation === 'vertical' && [ UP, DOWN, TAB ].indexOf( event.keyCode ) === -1 ) || diff --git a/editor/assets/stylesheets/_z-index.scss b/editor/assets/stylesheets/_z-index.scss index e60bbe931db189..3a7155f6d8d304 100644 --- a/editor/assets/stylesheets/_z-index.scss +++ b/editor/assets/stylesheets/_z-index.scss @@ -7,7 +7,6 @@ $z-layers: ( '.editor-visual-editor__block:before': -1, '.editor-visual-editor__block .wp-block-more:before': -1, '.editor-visual-editor__block {core/image aligned left or right}': 10, - '.editor-block-toolbar': 1, '.editor-visual-editor__block-warning': 1, '.components-form-toggle__input': 1, '.editor-format-list__menu': 1, diff --git a/editor/block-switcher/style.scss b/editor/block-switcher/style.scss index 233d3de4971bcd..095a6b85818dfd 100644 --- a/editor/block-switcher/style.scss +++ b/editor/block-switcher/style.scss @@ -1,12 +1,5 @@ .editor-block-switcher { position: relative; - border: 1px solid $light-gray-500; - background-color: $white; - font-family: $default-font; - font-size: $default-font-size; - line-height: $default-line-height; - margin-right: -1px; - margin-bottom: -1px; } .editor-block-switcher__toggle { diff --git a/editor/block-toolbar/index.js b/editor/block-toolbar/index.js index 6fd3582b07c25b..479a999519e064 100644 --- a/editor/block-toolbar/index.js +++ b/editor/block-toolbar/index.js @@ -1,15 +1,14 @@ /** * External dependencies */ -import { Slot } from 'react-slot-fill'; -import CSSTransitionGroup from 'react-transition-group/CSSTransitionGroup'; +import { Slot, Fill } from 'react-slot-fill'; import classnames from 'classnames'; /** * WordPress Dependencies */ import { IconButton, Toolbar, NavigableMenu } from '@wordpress/components'; -import { Component, Children, findDOMNode } from '@wordpress/element'; +import { Component, findDOMNode } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { focus, keycodes } from '@wordpress/utils'; @@ -27,11 +26,6 @@ import { isMac } from '../utils/dom'; */ const { ESCAPE, F10 } = keycodes; -function FirstChild( { children } ) { - const childrenArray = Children.toArray( children ); - return childrenArray[ 0 ] || null; -} - function metaKeyPressed( event ) { return isMac() ? event.metaKey : ( event.ctrlKey && ! event.altKey ); } @@ -114,45 +108,38 @@ class BlockToolbar extends Component { } ); return ( - + -
- { ! showMobileControls && [ - , - , - ] } - - - - { showMobileControls && -
- - -
- } -
-
+ { ! showMobileControls && [ + , + , + ] } + + + + { showMobileControls && +
+ + +
+ } +
-
+ ); } } diff --git a/editor/block-toolbar/style.scss b/editor/block-toolbar/style.scss index 98b691a8bc42d6..3f39c07a829fe2 100644 --- a/editor/block-toolbar/style.scss +++ b/editor/block-toolbar/style.scss @@ -1,64 +1,14 @@ - .editor-block-toolbar { - display: flex; - position: sticky; - z-index: z-index( '.editor-block-toolbar' ); - margin-top: -$block-controls-height - $item-spacing; - margin-bottom: $item-spacing + 20px; // 20px is the offset from the bottom of the selected block where it stops sticking - white-space: nowrap; - height: $block-controls-height; - - // Mobile viewport - top: $header-height - 1px; - margin-left: -$block-padding; - margin-right: -$block-padding; - - // Allow this invisible layer to be clicked through. - pointer-events: none; - - // Reset pointer-events on children. - & > * { - pointer-events: auto; - } - - // Larger viewports - @include break-small() { - margin-left: 0; - } - - @include break-medium() { - top: $item-spacing; - } - - &.is-appearing-active { - @include animate_fade; - } -} - -.editor-block-toolbar__group { display: inline-flex; - box-shadow: $shadow-toolbar; - width: 100%; - background: $white; - overflow: auto; // allow horizontal scrolling on mobile + overflow: auto; // allow horizontal scrolling on mobile + flex-grow: 1; - @include break-small() { - width: auto; - overflow: hidden; + .components-toolbar { + border: none; + border-left: 1px solid $light-gray-500; } } -$sticky-bottom-offset: 20px; -.editor-block-toolbar + div { - // prevent collapsing margins between block and toolbar, matches the 20px bottom offset - margin-top: -$sticky-bottom-offset - 1px; - padding-top: 1px; - } - -.editor-block-toolbar .components-toolbar { - margin-right: -1px; -} - .editor-block-toolbar .editor-block-switcher { display: inline-flex; } diff --git a/editor/header/index.js b/editor/header/index.js index 9c922f4f72599e..c7bf963eb416eb 100644 --- a/editor/header/index.js +++ b/editor/header/index.js @@ -2,6 +2,7 @@ * External dependencies */ import { connect } from 'react-redux'; +import { Slot } from 'react-slot-fill'; /** * WordPress dependencies @@ -47,6 +48,7 @@ function Header( { label={ __( 'Redo' ) } disabled={ ! hasRedo } onClick={ redo } /> +
diff --git a/editor/modes/visual-editor/block.js b/editor/modes/visual-editor/block.js index e6f6d98e2da7b7..8c4999e448aee3 100644 --- a/editor/modes/visual-editor/block.js +++ b/editor/modes/visual-editor/block.js @@ -343,7 +343,7 @@ class VisualEditorBlock extends Component { { ( showUI || isProperlyHovered ) && } { ( showUI || isProperlyHovered ) && } - { showUI && isValid && mode === 'visual' && } + { isSelected && isValid && mode === 'visual' && } { isFirstMultiSelected && ! this.props.isSelecting && }