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

Update BlockMover Stories and README #66519

Merged
merged 14 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions packages/block-editor/src/components/block-mover/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Block mover
# BlockMover

Block movers allow moving blocks inside the editor using up and down buttons.
BlockMover component allows moving blocks inside the editor using up and down buttons.

![Block mover screenshot](https://make.wordpress.org/core/files/2020/08/block-mover-screenshot.png)

## Development guidelines

### Usage
## Usage

Shows the block mover buttons in the block toolbar.

Expand All @@ -15,13 +13,22 @@ import { BlockMover } from '@wordpress/block-editor';
const MyMover = () => <BlockMover clientIds={ [ clientId ] } />;
```

### Props
## Props
t-hamano marked this conversation as resolved.
Show resolved Hide resolved

#### clientIds
### clientIds

Blocks IDs
The IDs of the blocks to move.

- Type: `Array`
- Required: Yes

### hideDragHandle

If this property is true, the drag handle is hidden.

- Type: `boolean`
- Required: No
- Default: `false`

## Related components

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import BlockMover from '../';
import { ExperimentalBlockEditorProvider } from '../../provider';
import { store as blockEditorStore } from '../../../store';

// For the purpose of this story, we need to register the core blocks samples.
registerCoreBlocks();
const blocks = [
// vertical
Expand All @@ -30,81 +31,82 @@ const blocks = [
] ),
];

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

return (
<div style={ wrapperStyle }>
/**
* BlockMover component allows moving blocks inside the editor using up and down buttons.
*/
const meta = {
title: 'BlockEditor/BlockMover',
component: BlockMover,
parameters: {
docs: { canvas: { sourceState: 'shown' } },
},
decorators: [
( Story ) => (
<ExperimentalBlockEditorProvider value={ blocks }>
{ children }
<Toolbar label="Block Mover">
<Story />
</Toolbar>
</ExperimentalBlockEditorProvider>
</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 accommodate horizontal blocks.
</p>
<Toolbar label="Block Mover">
<BlockMover
clientIds={
blocks.length
? [ blocks[ 1 ].innerBlocks[ 1 ].clientId ]
: []
}
/>
</Toolbar>
),
],
argTypes: {
clientIds: {
control: {
type: 'none',
},
description: 'The client IDs of the blocks to move.',
},
hideDragHandle: {
control: {
type: 'boolean',
},
description: 'If this property is true, the drag handle is hidden.',
},
},
};
export default meta;

<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 const Default = {
args: {
clientIds: [ blocks[ 0 ].innerBlocks[ 1 ].clientId ],
},
};

export default {
title: 'BlockEditor/BlockMover',
/**
* This story shows the block mover with horizontal orientation.
* It is necessary to render the blocks to update the block settings in the state.
*/
export const Horizontal = {
decorators: [
( Story ) => {
const { updateBlockListSettings } = useDispatch( blockEditorStore );
useEffect( () => {
/**
* This shouldn't be needed but unfortunately
* 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 <Story />;
},
],
args: {
clientIds: [ blocks[ 1 ].innerBlocks[ 1 ].clientId ],
},
parameters: {
docs: { canvas: { sourceState: 'hidden' } },
},
};

export const _default = () => {
return (
<Provider>
<BlockMoverStory />
</Provider>
);
/**
* You can hide the drag handle by `hideDragHandle` attribute.
*/
export const HideDragHandle = {
args: {
...Default.args,
hideDragHandle: true,
},
};
Loading