-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add block name label and improve nested blocks UI (#5658)
BlockList and Block item: * Improve the nested blocks contextual UI. * Show insertion point prior to block. Better compatibility with high z-index of sibling inserter conflicting with hover behavior of block. * Show label and block breadcrumb prior to block. * Expose "BlockTitle" component. * Cancel hover on handled descendant mouseover. * Fix issue with nesting when only one block present on the movers. * Movers now work on wide and fullwide, and look good. * Hovering now both works without horizontal scrollbars on wide items, and they aren't overlapped by the movers. * Wide alignment blocks now don't have negative margin to accommodate side UI. * Add padding left and right on fullwide columns. * Improve the appender inside columns, so it's the same UI as it is on mobile. * Assign mover z-index via map entry.
- Loading branch information
Showing
23 changed files
with
571 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// These margins make sure that nested blocks stack/overlay with the parent block chrome | ||
// This is sort of an experiment at making sure the editor looks as much like the end result as possible | ||
// Potentially the rules here can apply to all nested blocks and enable stacking, in which case it should be moved elsewhere | ||
.wp-block-columns .editor-block-list__layout { | ||
&:first-child { | ||
margin-left: -$block-padding; | ||
} | ||
&:last-child { | ||
margin-right: -$block-padding; | ||
} | ||
|
||
// This max-width is used to constrain the main editor column, it should not cascade into columns | ||
.editor-block-list__block { | ||
max-width: none; | ||
} | ||
} | ||
|
||
// Wide: show no left/right margin on wide, so they stack with the column side UI | ||
.editor-block-list__block[data-align="wide"] .wp-block-columns .editor-block-list__layout { | ||
&:first-child { | ||
margin-left: 0; | ||
} | ||
&:last-child { | ||
margin-right: 0; | ||
} | ||
} | ||
|
||
// Fullwide: show margin left/right to ensure there's room for the side UI | ||
// This is not a 1:1 preview with the front-end where these margins would presumably be zero | ||
// @todo this could be revisited, by for example showing this margin only when the parent block was selected first | ||
// Then at least an unselected columns block would be an accurate preview | ||
.editor-block-list__block[data-align="full"] .wp-block-columns .editor-block-list__layout { | ||
&:first-child { | ||
margin-left: $block-side-ui-padding; | ||
} | ||
&:last-child { | ||
margin-right: $block-side-ui-padding; | ||
} | ||
} | ||
|
||
// Hide appender shortcuts in columns | ||
// @todo This essentially duplicates the mobile styles for the appender component | ||
// It would be nice to be able to use element queries in that component instead https://github.com/tomhodgins/element-queries-spec | ||
.wp-block-columns { | ||
.editor-inserter-with-shortcuts { | ||
display: none; | ||
} | ||
|
||
.editor-block-list__empty-block-inserter, | ||
.editor-default-block-appender .editor-inserter { | ||
left: auto; | ||
right: $item-spacing; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { compose } from '@wordpress/element'; | ||
import { Dashicon, Tooltip, Toolbar, Button } from '@wordpress/components'; | ||
import { withDispatch, withSelect } from '@wordpress/data'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import NavigableToolbar from '../navigable-toolbar'; | ||
import BlockTitle from '../block-title'; | ||
|
||
/** | ||
* Stops propagation of the given event argument. Assumes that the event has | ||
* been completely handled and no other listeners should be informed. | ||
* | ||
* For the breadcrumb component, this is used for improved interoperability | ||
* with the block's `onFocus` handler which selects the block, thus conflicting | ||
* with the intention to select the root block. | ||
* | ||
* @param {Event} event Event for which propagation should be stopped. | ||
*/ | ||
function stopPropagation( event ) { | ||
event.stopPropagation(); | ||
} | ||
|
||
/** | ||
* Block breadcrumb component, displaying the label of the block. If the block | ||
* descends from a root block, a button is displayed enabling the user to select | ||
* the root block. | ||
* | ||
* @param {string} props.uid UID of block. | ||
* @param {string} props.rootUID UID of block's root. | ||
* @param {Function} props.selectRootBlock Callback to select root block. | ||
* | ||
* @return {WPElement} Breadcrumb element. | ||
*/ | ||
function BlockBreadcrumb( { uid, rootUID, selectRootBlock } ) { | ||
return ( | ||
<NavigableToolbar className="editor-block-breadcrumb"> | ||
<Toolbar> | ||
{ rootUID && ( | ||
<Tooltip text={ __( 'Select parent block' ) }> | ||
<Button | ||
onClick={ selectRootBlock } | ||
onFocus={ stopPropagation } | ||
> | ||
<Dashicon icon="arrow-left" uid={ uid } /> | ||
</Button> | ||
</Tooltip> | ||
) } | ||
<BlockTitle uid={ uid } /> | ||
</Toolbar> | ||
</NavigableToolbar> | ||
); | ||
} | ||
|
||
export default compose( [ | ||
withSelect( ( select, ownProps ) => { | ||
const { getBlockRootUID } = select( 'core/editor' ); | ||
const { uid } = ownProps; | ||
|
||
return { | ||
rootUID: getBlockRootUID( uid ), | ||
}; | ||
} ), | ||
withDispatch( ( dispatch, ownProps ) => { | ||
const { rootUID } = ownProps; | ||
const { selectBlock } = dispatch( 'core/editor' ); | ||
|
||
return { | ||
selectRootBlock: () => selectBlock( rootUID ), | ||
}; | ||
} ), | ||
] )( BlockBreadcrumb ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.