Skip to content

Commit

Permalink
Visually separate the parent selector from the other buttons.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZebulanStanphill committed Aug 12, 2020
1 parent 02cf4da commit ba3866b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
Expand All @@ -12,17 +17,23 @@ import NavigableToolbar from '../navigable-toolbar';
import { BlockToolbar } from '../';

function BlockContextualToolbar( { focusOnMount, ...props } ) {
const { blockType } = useSelect( ( select ) => {
const { getBlockName, getSelectedBlockClientIds } = select(
'core/block-editor'
);
const { blockType, hasParent, isMultiToolbar } = useSelect( ( select ) => {
const {
getBlockName,
getBlockParents,
getSelectedBlockClientIds,
} = select( 'core/block-editor' );
const { getBlockType } = select( 'core/blocks' );
const selectedBlockClientIds = getSelectedBlockClientIds();
const selectedBlockClientId = selectedBlockClientIds[ 0 ];
return {
blockType:
selectedBlockClientId &&
getBlockType( getBlockName( selectedBlockClientId ) ),
hasParent:
selectedBlockClientId &&
getBlockParents( selectedBlockClientId ).length > 0,
isMultiToolbar: selectedBlockClientIds.length > 1,
};
}, [] );
if ( blockType ) {
Expand All @@ -34,7 +45,10 @@ function BlockContextualToolbar( { focusOnMount, ...props } ) {
<div className="block-editor-block-contextual-toolbar-wrapper">
<NavigableToolbar
focusOnMount={ focusOnMount }
className="block-editor-block-contextual-toolbar"
className={ classnames(
'block-editor-block-contextual-toolbar',
{ 'has-parent-selector': hasParent && ! isMultiToolbar }
) }
/* translators: accessibility text for the block toolbar */
aria-label={ __( 'Block tools' ) }
{ ...props }
Expand Down
5 changes: 5 additions & 0 deletions packages/block-editor/src/components/block-list/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,11 @@
border-radius: $radius-block-ui;
background-color: $white;

// Adjust positioning when parent selector button is available
&.has-parent-selector {
margin-left: $grid-unit-60 + $grid-unit-15;
}

.block-editor-block-toolbar .components-toolbar-group,
.block-editor-block-toolbar .components-toolbar {
border-right-color: $gray-900;
Expand Down
19 changes: 18 additions & 1 deletion packages/block-editor/src/components/block-toolbar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,27 @@
}

.block-editor-block-toolbar__block-parent-selector-wrapper {
// Hide the Parent button in Top Toolbar mode.
position: absolute;
left: -($grid-unit-60 + $grid-unit-15);
width: $grid-unit-60;
height: $grid-unit-60;
border-radius: $radius-block-ui;

// Extra specificity to override toolbar or toolbar group styles.
&.block-editor-block-toolbar__block-parent-selector-wrapper {
background-color: $white;
border: $border-width solid $gray-900;
}

// Hide the parent selector button in Top Toolbar mode.
.edit-post-header-toolbar__block-toolbar & {
display: none;
}

.block-editor-block-parent-selector {
margin-top: -1px;
margin-left: -1px;
}
}

.block-editor-block-toolbar-animated-width-container {
Expand Down

0 comments on commit ba3866b

Please sign in to comment.