Skip to content

Commit

Permalink
Try to inject text alignment styles after global styles
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano committed Jun 20, 2024
1 parent dd717b3 commit 3b093ca
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
21 changes: 21 additions & 0 deletions lib/block-supports/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,22 @@ function gutenberg_get_typography_font_size_value( $preset, $settings = array()
return $preset['size'];
}

function gutenberg_output_typography_styles() {
foreach ( array( 'left', 'center', 'right' ) as $alignment ) {
gutenberg_style_engine_get_styles(
array(
'typography' => array(
'textAlign' => $alignment,
),
),
array(
'selector' => ".has-text-align-{$alignment}",
'context' => 'block-supports',
)
);
}
}

// Register the block support.
WP_Block_Supports::get_instance()->register(
'typography',
Expand All @@ -621,3 +637,8 @@ function gutenberg_get_typography_font_size_value( $preset, $settings = array()
remove_filter( 'render_block', 'wp_render_typography_support' );
}
add_filter( 'render_block', 'gutenberg_render_typography_support', 10, 2 );

if ( function_exists( 'wp_output_typography_styles' ) ) {
remove_action( 'enqueue_block_assets', 'wp_output_typography_styles' );
}
add_filter( 'enqueue_block_assets', 'gutenberg_output_typography_styles', 9 );
16 changes: 0 additions & 16 deletions packages/block-library/src/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,6 @@
font-size: var(--wp--preset--font-size--huge);
}

// Text alignments.
// Increase specificity so that styles applied via the global styles can be overridden in block instances.
:root .has-text-align-center {
text-align: center;
}

:root .has-text-align-left {
/*rtl:ignore*/
text-align: left;
}

:root .has-text-align-right {
/*rtl:ignore*/
text-align: right;
}

// This tag marks the end of the styles that apply to editing canvas contents and need to be manipulated when we resize the editor.
#end-resizable-editor-section {
display: none;
Expand Down
6 changes: 6 additions & 0 deletions packages/style-engine/class-wp-style-engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ final class WP_Style_Engine {
),
'path' => array( 'typography', 'lineHeight' ),
),
'textAlign' => array(

Check warning on line 270 in packages/style-engine/class-wp-style-engine.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Array double arrow not aligned correctly; expected 6 space(s) between "'textAlign'" and double arrow, but found 7.
'property_keys' => array(
'default' => 'text-align',
),
'path' => array( 'typography', 'textAlign' ),
),
'textColumns' => array(
'property_keys' => array(
'default' => 'column-count',
Expand Down

0 comments on commit 3b093ca

Please sign in to comment.