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

Allow blocks to be grouped as a Grid #59853

Merged
merged 1 commit into from
Mar 14, 2024
Merged
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
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' ) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a TIL for me, I didn't realise that grid could be used as a verb: https://en.wiktionary.org/wiki/grid#Verb. Nice!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wondered if the use here is clear enough? But the alternative would be a verbose or potentially confusing description like "configurable rows and columns". I guess ultimately what matters is if the meaning is sufficiently clear to translators; grid as a verb is unlikely to exist in every language.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's probably fine for now, particularly since it'd be an easy thing to update. I suppose another option would be to use __( 'Grid' ) with no explanatory comment, to default to a noun 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave it as is for now.

onClick={ onConvertToGrid }
/>
) }
</ToolbarGroup>
);
}
Expand Down
Loading