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: Migrate to the new textAlign block support #60763

Open
26 tasks
t-hamano opened this issue Apr 16, 2024 · 0 comments
Open
26 tasks

Block Library: Migrate to the new textAlign block support #60763

t-hamano opened this issue Apr 16, 2024 · 0 comments
Labels
[Package] Block library /packages/block-library [Type] Enhancement A suggestion for improvement.

Comments

@t-hamano
Copy link
Contributor

t-hamano commented Apr 16, 2024

What problem does this address?

Over 20 core blocks have attributes and UI implemented for each block to control the text-align style. For example, it looks like the following.

block.json
{
	"$schema": "https://schemas.wp.org/trunk/block.json",
	"apiVersion": 3,
	"name": "core/heading",
	"title": "Heading",
	"attributes": {
		"textAlign": {
			"type": "string"
		}
	}
}
edit.js
import {
	AlignmentControl,
	BlockControls,
	useBlockProps,
} from '@wordpress/block-editor';

function Edit( { attributes, setAttributes } ) {
	const { textAlign } = attributes;
	return (
		<>
			<BlockControls group="block">
				<AlignmentControl
					value={ textAlign }
					onChange={ ( nextAlign ) => {
						setAttributes( { textAlign: nextAlign } );
					} }
				/>
			</BlockControls>
			<div { ...useBlockProps() } />
		</>
	);
}

These are all almost the same implementations and feel redundant.

What is your proposed solution?

In #59531, textAlign is added as block support. I believe that we can gradually migrate to this block support.

Below is a list of blocks that provide attributes and UI to control text-aligin.

  • core/button
  • core/comment-author-name
  • core/comment-content
  • core/comment-edit-link
  • core/comment-reply-link
  • core/comment-title
  • core/heading
  • core/paragraph: Note that the attribute is named "align" and not "textAlign".
  • core/post-author: This might not be necessary as Deprecate 'Post author' block #55352 is considering deprecating this block.
  • core/post-author-biography
  • core/post-author-name
  • core/post-comments-count
  • core/post-comments-form
  • core/post-comments-link
  • core/post-date
  • core/post-excerpt
  • core/post-navigation-link
  • core/post-terms
  • core/post-time-to-read
  • core/post-title
  • core/pullquote
  • core/query-title
  • core/site-tagline
  • core/site-title
  • core/term-description
  • core/verse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Block library /packages/block-library [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

1 participant