-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean BlockMover component and styles (#40379)
- Loading branch information
1 parent
1fc751c
commit c135816
Showing
12 changed files
with
220 additions
and
342 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
24 changes: 0 additions & 24 deletions
24
packages/block-editor/src/components/block-mobile-toolbar/index.js
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
packages/block-editor/src/components/block-mobile-toolbar/style.scss
This file was deleted.
Oops, something went wrong.
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
110 changes: 110 additions & 0 deletions
110
packages/block-editor/src/components/block-mover/stories/index.js
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,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> | ||
); | ||
}; |
Oops, something went wrong.