-
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
Open
akasunil
wants to merge
21
commits into
trunk
Choose a base branch
from
add/post-navigation-link-border-support
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a02df3f
Add border support to post mavigation block
akasunil f331538
Add box sizing style to post navigation link block
akasunil e9fff19
Return empty if the adjacent post is unavailable
akasunil 6baaa15
Update comment text
akasunil de7485c
Merge branch 'trunk' of personal.github.com:WordPress/gutenberg into …
akasunil 700f22c
Add spacing support to post navigation link
akasunil d9d51b7
Merge branch 'trunk' of personal.github.com:WordPress/gutenberg into …
akasunil 4c25d1a
Merge branch 'trunk' of personal.github.com:WordPress/gutenberg into …
akasunil 6aa39df
Revert changes of render function
akasunil 0551091
Add selectors for border and spacing support
akasunil a14512f
Merge branch 'trunk' of personal.github.com:WordPress/gutenberg into …
akasunil c46823f
Remove styles from empty post navigation link element
akasunil f15548f
Merge branch 'trunk' of github.com:WordPress/gutenberg into add/post-…
akasunil 311f5d8
Skip serialization of border and spacing support
akasunil 6404d13
Apply border and spacing support manully
akasunil 3fca4e4
Merge branch 'trunk' of github.com:WordPress/gutenberg into add/post-…
akasunil b0fdd00
Update comment texts
akasunil 8dcec4d
Fix coding standards
akasunil c656936
Merge branch 'trunk' of github.com:WordPress/gutenberg into add/post-…
akasunil b027a57
Fix inline support style issue
akasunil 2654826
Merge branch 'trunk' of github.com:WordPress/gutenberg into add/post-…
akasunil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,9 +30,15 @@ function render_block_core_post_navigation_link( $attributes, $content ) { | |
if ( isset( $attributes['textAlign'] ) ) { | ||
$classes .= " has-text-align-{$attributes['textAlign']}"; | ||
} | ||
|
||
$support_styles = block_core_post_navigation_link_get_border_and_spacing_attributes( $attributes ); | ||
$classes .= ! empty( $support_styles['class'] ) ? " {$support_styles['class']}" : ''; | ||
|
||
// Get the wrapper attributes. | ||
$wrapper_attributes = get_block_wrapper_attributes( | ||
array( | ||
'class' => $classes, | ||
'style' => $support_styles['style'], | ||
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. This will throw a warning when a block instance doesn't have padding or border styles. |
||
) | ||
); | ||
// Set default values. | ||
|
@@ -123,6 +129,80 @@ function render_block_core_post_navigation_link( $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. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.