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

Clean BlockMover component and styles #40379

Merged
merged 8 commits into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions packages/base-styles/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ $z-layers: (
// Ensures content overlay appears higher than resize containers used for image/video/etc.
".block-editor-block-content-overlay__overlay": 10,

// The block mover, particularly in nested contexts,
// should overlap most block content.
".block-editor-block-list__block.is-{selected,hovered} .block-editor-block-mover": 61,

// Query block setup state.
".block-editor-block-pattern-setup .pattern-slide": 100,
".block-editor-block-pattern-setup .{next,previous}-slide": 101,
Expand Down

This file was deleted.

This file was deleted.

6 changes: 3 additions & 3 deletions packages/block-editor/src/components/block-mover/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { castArray, first, last } from 'lodash';
* WordPress dependencies
*/
import { getBlockType } from '@wordpress/blocks';
import { Button } from '@wordpress/components';
import { Button, VisuallyHidden } from '@wordpress/components';
import { useInstanceId } from '@wordpress/compose';
import { useSelect, useDispatch } from '@wordpress/data';
import { forwardRef } from '@wordpress/element';
Expand Down Expand Up @@ -141,7 +141,7 @@ const BlockMoverButton = forwardRef(
onClick={ isDisabled ? null : onClick }
aria-disabled={ isDisabled }
/>
<span
<VisuallyHidden
id={ descriptionId }
className="block-editor-block-mover-button__description"
>
Expand All @@ -154,7 +154,7 @@ const BlockMoverButton = forwardRef(
direction === 'up' ? -1 : 1,
orientation
) }
</span>
</VisuallyHidden>
</>
);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/block-editor/src/components/block-mover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function BlockMover( {
// to an unfocused state (body as active element) without firing blur on,
// the rendering parent, leaving it unable to react to focus out.
return (
<div
<ToolbarGroup
className={ classnames( 'block-editor-block-mover', {
'is-visible': isFocused || ! isHidden,
'is-horizontal': orientation === 'horizontal',
Expand All @@ -73,7 +73,7 @@ function BlockMover( {
) }
</BlockDraggable>
) }
<ToolbarGroup className="block-editor-block-mover__move-button-container">
<div className="block-editor-block-mover__move-button-container">
<ToolbarItem onFocus={ onFocus } onBlur={ onBlur }>
{ ( itemProps ) => (
<BlockMoverUpButton
Expand All @@ -90,8 +90,8 @@ function BlockMover( {
/>
) }
</ToolbarItem>
</ToolbarGroup>
</div>
</div>
</ToolbarGroup>
);
}

Expand Down
110 changes: 110 additions & 0 deletions packages/block-editor/src/components/block-mover/stories/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* WordPress dependencies
*/
import { useEffect } from '@wordpress/element';
import { createBlock } from '@wordpress/blocks';
import { registerCoreBlocks } from '@wordpress/block-library';
import { useDispatch } from '@wordpress/data';
import { Toolbar } from '@wordpress/components';

/**
* Internal dependencies
*/
import BlockMover from '../';
import BlockEditorProvider from '../../provider';
import { store as blockEditorStore } from '../../../store';

registerCoreBlocks();
const blocks = [
// vertical
createBlock( 'core/group', { layout: { type: 'flex' } }, [
createBlock( 'core/paragraph' ),
createBlock( 'core/paragraph' ),
createBlock( 'core/paragraph' ),
] ),
// horizontal
createBlock( 'core/buttons', {}, [
createBlock( 'core/button' ),
createBlock( 'core/button' ),
createBlock( 'core/button' ),
] ),
];

function Provider( { children } ) {
const wrapperStyle = { margin: '24px', position: 'relative' };

return (
<div style={ wrapperStyle }>
<BlockEditorProvider value={ blocks }>
{ children }
</BlockEditorProvider>
</div>
);
}

function BlockMoverStory() {
const { updateBlockListSettings } = useDispatch( blockEditorStore );

useEffect( () => {
/**
* This shouldn't be needed but unfortunatley
* the layout orientation is not declarative, we need
* to render the blocks to update the block settings in the state.
*/
updateBlockListSettings( blocks[ 1 ].clientId, {
orientation: 'horizontal',
} );
}, [] );

return (
<div>
<p>The mover by default is vertical</p>
<Toolbar label="Block Mover">
<BlockMover
clientIds={
blocks.length
? [ blocks[ 0 ].innerBlocks[ 1 ].clientId ]
: []
}
/>
</Toolbar>

<p style={ { marginTop: 36 } }>
But it can also accomodate horizontal blocks.
</p>
<Toolbar label="Block Mover">
<BlockMover
clientIds={
blocks.length
? [ blocks[ 1 ].innerBlocks[ 1 ].clientId ]
: []
}
/>
</Toolbar>

<p style={ { marginTop: 36 } }>We can also hide the drag handle.</p>
<Toolbar label="Block Mover">
<BlockMover
clientIds={
blocks.length
? [ blocks[ 1 ].innerBlocks[ 0 ].clientId ]
: []
}
hideDragHandle
/>
</Toolbar>
</div>
);
}

export default {
title: 'BlockEditor/BlockMover',
};

export const _default = () => {
return (
<Provider>
<BlockMoverStory />
</Provider>
);
};