Skip to content

Commit

Permalink
Allow blocks to be grouped as a Grid (WordPress#59853)
Browse files Browse the repository at this point in the history
Co-authored-by: tellthemachines <[email protected]>
Co-authored-by: andrewserong <[email protected]>
  • Loading branch information
3 people authored and carstingaxion committed Mar 27, 2024
1 parent 5cc9191 commit da17ddd
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { useDispatch, useSelect } from '@wordpress/data';
import { switchToBlockType, store as blocksStore } from '@wordpress/blocks';
import { ToolbarButton, ToolbarGroup } from '@wordpress/components';
import { group, row, stack } from '@wordpress/icons';
import { group, row, stack, grid } from '@wordpress/icons';
import { _x } from '@wordpress/i18n';

/**
Expand All @@ -17,6 +17,7 @@ const layouts = {
group: { type: 'constrained' },
row: { type: 'flex', flexWrap: 'nowrap' },
stack: { type: 'flex', orientation: 'vertical' },
grid: { type: 'grid' },
};

function BlockGroupToolbar() {
Expand Down Expand Up @@ -60,6 +61,7 @@ function BlockGroupToolbar() {

const onConvertToRow = () => onConvertToGroup( 'row' );
const onConvertToStack = () => onConvertToGroup( 'stack' );
const onConvertToGrid = () => onConvertToGroup( 'grid' );

// Don't render the button if the current selection cannot be grouped.
// A good example is selecting multiple button blocks within a Buttons block:
Expand All @@ -75,6 +77,9 @@ function BlockGroupToolbar() {
const canInsertStack = !! variations.find(
( { name } ) => name === 'group-stack'
);
const canInsertGrid = !! variations.find(
( { name } ) => name === 'group-grid'
);

return (
<ToolbarGroup>
Expand All @@ -97,6 +102,13 @@ function BlockGroupToolbar() {
onClick={ onConvertToStack }
/>
) }
{ canInsertGrid && (
<ToolbarButton
icon={ grid }
label={ _x( 'Grid', 'verb' ) }
onClick={ onConvertToGrid }
/>
) }
</ToolbarGroup>
);
}
Expand Down

0 comments on commit da17ddd

Please sign in to comment.