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

[Block Library - Heading]: Add heading levels as block variations #33811

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 2 additions & 0 deletions packages/block-library/src/heading/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import edit from './edit';
import metadata from './block.json';
import save from './save';
import transforms from './transforms';
import variations from './variations';

const { name } = metadata;

Expand Down Expand Up @@ -59,4 +60,5 @@ export const settings = {
},
edit,
save,
variations,
};
23 changes: 23 additions & 0 deletions packages/block-library/src/heading/variations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* WordPress dependencies
*/
import { sprintf, __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import HeadingLevelIcon from './heading-level-icon';

const variations = [ 1, 2, 3, 4, 5, 6 ].map( ( level ) => ( {
name: `heading-${ level }`,
title: sprintf(
/* translators: %d: heading level. */
__( 'Heading %d' ),
level
),
icon: <HeadingLevelIcon level={ level } />,
Copy link
Member

Choose a reason for hiding this comment

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

Aside: @gwwar, if we had better handling for icons, we could keep put those variations in block.json. Well, JS offers loops that make encoding those variations simpler. The downside is that variations aren't exposed on the server.

attributes: { level },
scope: [ 'inserter' ],
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to include isActive to show different titles and icons in the block editor UI?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this can be discussed as well. I intentionally left it out for start, as I thought it was not so much needed -but of course that was a personal opinion 😄

} ) );

export default variations;