-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Post Navigation Link: Add border and spacing block support #64258
base: trunk
Are you sure you want to change the base?
Changes from all commits
a02df3f
f331538
e9fff19
6baaa15
de7485c
700f22c
d9d51b7
4c25d1a
6aa39df
0551091
a14512f
c46823f
f15548f
311f5d8
6404d13
3fca4e4
b0fdd00
8dcec4d
c656936
b027a57
2654826
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,11 +30,7 @@ function render_block_core_post_navigation_link( $attributes, $content ) { | |
if ( isset( $attributes['textAlign'] ) ) { | ||
$classes .= " has-text-align-{$attributes['textAlign']}"; | ||
} | ||
$wrapper_attributes = get_block_wrapper_attributes( | ||
array( | ||
'class' => $classes, | ||
) | ||
); | ||
|
||
// Set default values. | ||
$format = '%link'; | ||
$link = 'next' === $navigation_type ? _x( 'Next', 'label for next post link' ) : _x( 'Previous', 'label for previous post link' ); | ||
|
@@ -116,13 +112,98 @@ function render_block_core_post_navigation_link( $attributes, $content ) { | |
$content = $get_link_function( $format, $link ); | ||
} | ||
|
||
$support_styles = block_core_post_navigation_link_get_border_and_spacing_attributes( $attributes ); | ||
$classes .= ! empty( $support_styles['class'] ) ? " {$support_styles['class']}" : ''; | ||
Comment on lines
+115
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the editor side flagged above, this change doesn't take into account that the border support can apply color CSS classes e.g. The result is the issue raised in my last review is still present. |
||
|
||
// Get the wrapper attributes. | ||
$wrapper_attributes = get_block_wrapper_attributes( | ||
array( | ||
'class' => $classes, | ||
'style' => ! empty( $content ) && $support_styles['style'] ? $support_styles['style'] : '', | ||
) | ||
); | ||
|
||
return sprintf( | ||
'<div %1$s>%2$s</div>', | ||
$wrapper_attributes, | ||
$content | ||
); | ||
} | ||
|
||
/** | ||
* Generates class names and styles to apply the border and spacing support styles for | ||
* the Post Navigation Link block. | ||
* | ||
* @since 6.7.0 | ||
* | ||
* @param array $attributes The block attributes. | ||
* @return array The border and spacing related classnames and styles for the block. | ||
*/ | ||
function block_core_post_navigation_link_get_border_and_spacing_attributes( $attributes ) { | ||
$border_styles = array(); | ||
$sides = array( 'top', 'right', 'bottom', 'left' ); | ||
|
||
// Border radius. | ||
if ( isset( $attributes['style']['border']['radius'] ) ) { | ||
$border_styles['radius'] = $attributes['style']['border']['radius']; | ||
} | ||
|
||
// Border style. | ||
if ( isset( $attributes['style']['border']['style'] ) ) { | ||
$border_styles['style'] = $attributes['style']['border']['style']; | ||
} | ||
|
||
// Border width. | ||
if ( isset( $attributes['style']['border']['width'] ) ) { | ||
$border_styles['width'] = $attributes['style']['border']['width']; | ||
} | ||
|
||
// Border color. | ||
$preset_color = array_key_exists( 'borderColor', $attributes ) ? "var:preset|color|{$attributes['borderColor']}" : null; | ||
$custom_color = $attributes['style']['border']['color'] ?? null; | ||
$border_styles['color'] = $preset_color ? $preset_color : $custom_color; | ||
|
||
// Individual border styles e.g. top, left etc. | ||
foreach ( $sides as $side ) { | ||
$border = $attributes['style']['border'][ $side ] ?? null; | ||
$border_styles[ $side ] = array( | ||
'color' => isset( $border['color'] ) ? $border['color'] : null, | ||
'style' => isset( $border['style'] ) ? $border['style'] : null, | ||
'width' => isset( $border['width'] ) ? $border['width'] : null, | ||
); | ||
} | ||
|
||
// Individual padding styles e.g. top, left etc. | ||
$padding_style = array(); | ||
foreach ( $sides as $side ) { | ||
$padding_style[ $side ] = $attributes['style']['spacing']['padding'][ $side ] ?? null; | ||
} | ||
|
||
// Individual margin styles e.g. top, left etc. | ||
$margin_style = array(); | ||
foreach ( $sides as $side ) { | ||
$margin_style[ $side ] = $attributes['style']['spacing']['margin'][ $side ] ?? null; | ||
} | ||
|
||
$styles = wp_style_engine_get_styles( | ||
array( | ||
'border' => $border_styles, | ||
'spacing' => array( | ||
'padding' => $padding_style, | ||
'margin' => $margin_style, | ||
), | ||
) | ||
); | ||
$attributes = array(); | ||
if ( ! empty( $styles['classnames'] ) ) { | ||
$attributes['class'] = $styles['classnames']; | ||
} | ||
if ( ! empty( $styles['css'] ) ) { | ||
$attributes['style'] = $styles['css']; | ||
} | ||
return $attributes; | ||
} | ||
|
||
/** | ||
* Registers the `core/post-navigation-link` block on the server. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only applies styles from the border and spacing props. Border support can define CSS classes to apply as well e.g.
has-border-color
etc.You can see this in action in the editor if you apply a border to the Group block. An example that maintains the classes from
useBorderProps
can be seen in the Avatar block.One option would be to pass
borderProps.className
etc in as classes for theuseBlockProps
call here.The reason this doesn't present visually in the editor is that the border block support forces inline styles for the colors in the event that a theme doesn't correctly load their color stylesheets in the editor. Even still, we should maintain parity between the frontend and editor for classes wherever possible.