Skip to content

Commit

Permalink
Add functionality on inner blocks to not include parts of the UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Dec 23, 2019
1 parent a94c854 commit e5c31e8
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { __ } from '@wordpress/i18n';
import NavigableToolbar from '../navigable-toolbar';
import { BlockToolbar } from '../';

function BlockContextualToolbar( { focusOnMount, moverDirection, ...props } ) {
function BlockContextualToolbar( { focusOnMount, hasMovers, moverDirection, ...props } ) {
return (
<NavigableToolbar
focusOnMount={ focusOnMount }
Expand All @@ -18,7 +18,7 @@ function BlockContextualToolbar( { focusOnMount, moverDirection, ...props } ) {
aria-label={ __( 'Block tools' ) }
{ ...props }
>
<BlockToolbar moverDirection={ moverDirection } />
<BlockToolbar moverDirection={ moverDirection } hasMovers={ hasMovers } />
</NavigableToolbar>
);
}
Expand Down
6 changes: 5 additions & 1 deletion packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ function BlockListBlock( {
setNavigationMode,
isMultiSelecting,
isLargeViewport,
hasSelectedUI = true,
hasMovers = true,
} ) {
// In addition to withSelect, we should favor using useSelect in this component going forward
// to avoid leaking new props to the public API (editor.BlockListBlock filter)
Expand Down Expand Up @@ -446,8 +448,9 @@ function BlockListBlock( {
const wrapperClassName = classnames(
'wp-block block-editor-block-list__block',
{
'has-selected-ui': hasSelectedUI,
'has-warning': ! isValid || !! hasError || isUnregisteredBlock,
'is-selected': shouldAppearSelected,
'is-selected': shouldAppearSelected && hasSelectedUI,
'is-navigate-mode': isNavigationMode,
'is-multi-selected': isMultiSelected,
'is-hovered': shouldAppearHovered,
Expand Down Expand Up @@ -509,6 +512,7 @@ function BlockListBlock( {
data-type={ name }
data-align={ wrapperProps ? wrapperProps[ 'data-align' ] : undefined }
moverDirection={ moverDirection }
hasMovers={ hasMovers }
/>
);

Expand Down
9 changes: 9 additions & 0 deletions packages/block-editor/src/components/block-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function BlockList( {
__experimentalMoverDirection: moverDirection = 'vertical',
isDraggable,
renderAppender,
__experimentalUIParts = {},
} ) {
function selector( select ) {
const {
Expand Down Expand Up @@ -74,6 +75,12 @@ function BlockList( {
const ref = useRef();
const onSelectionStart = useMultiSelection( { ref, rootClientId } );

const uiParts = {
hasMovers: true,
hasSelectedUI: true,
...__experimentalUIParts,
};

return (
<div
ref={ ref }
Expand Down Expand Up @@ -105,6 +112,8 @@ function BlockList( {
// otherwise there might be a small delay to trigger the animation.
animateOnChange={ index }
enableAnimation={ enableAnimation }
hasSelectedUI={ uiParts.hasSelectedUI }
hasMovers={ uiParts.hasMovers }
/>
</BlockAsyncModeProvider>
);
Expand Down
10 changes: 5 additions & 5 deletions packages/block-editor/src/components/block-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import BlockSwitcher from '../block-switcher';
import MultiBlocksSwitcher from '../block-switcher/multi-blocks-switcher';
import BlockMover from '../block-mover';

export default function BlockToolbar( { moverDirection } ) {
export default function BlockToolbar( { moverDirection, hasMovers = true } ) {
const { blockClientIds, isValid, mode } = useSelect( ( select ) => {
const {
getBlockMode,
Expand All @@ -41,10 +41,10 @@ export default function BlockToolbar( { moverDirection } ) {
if ( blockClientIds.length > 1 ) {
return (
<div className="block-editor-block-toolbar">
<BlockMover
{ hasMovers && ( <BlockMover
clientIds={ blockClientIds }
__experimentalOrientation={ moverDirection }
/>
/> ) }
<MultiBlocksSwitcher />
<BlockSettingsMenu clientIds={ blockClientIds } />
</div>
Expand All @@ -53,10 +53,10 @@ export default function BlockToolbar( { moverDirection } ) {

return (
<div className="block-editor-block-toolbar">
<BlockMover
{ hasMovers && ( <BlockMover
clientIds={ blockClientIds }
__experimentalOrientation={ moverDirection }
/>
/> ) }
{ mode === 'visual' && isValid && (
<>
<BlockSwitcher clientIds={ blockClientIds } />
Expand Down
7 changes: 2 additions & 5 deletions packages/block-editor/src/components/inner-blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,8 @@ class InnerBlocks extends Component {
enableClickThrough,
clientId,
hasOverlay,
renderAppender,
__experimentalMoverDirection: moverDirection,
__experimentalCaptureToolbars: captureToolbars,

...props
} = this.props;
const { templateInProcess } = this.state;

Expand All @@ -123,8 +121,7 @@ class InnerBlocks extends Component {
{ ! templateInProcess && (
<BlockList
rootClientId={ clientId }
renderAppender={ renderAppender }
__experimentalMoverDirection={ moverDirection }
{ ...props }
/>
) }
</div>
Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/src/group/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ function GroupEdit( {
<div className="wp-block-group__inner-container">
<InnerBlocks
renderAppender={ ! hasInnerBlocks && InnerBlocks.ButtonBlockAppender }
__experimentalUIParts={ {
hasSelectedUI: false,
hasMovers: false,
} }
/>
</div>
</div>
Expand Down

0 comments on commit e5c31e8

Please sign in to comment.