-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add new grid layout type #4625
Add new grid layout type #4625
Changes from all commits
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 |
---|---|---|
|
@@ -34,6 +34,7 @@ function wp_register_layout_support( $block_type ) { | |
* | ||
* @since 5.9.0 | ||
* @since 6.1.0 Added `$block_spacing` param, use style engine to enqueue styles. | ||
* @since 6.3.0 Added grid layout type. | ||
* @access private | ||
* | ||
* @param string $selector CSS selector. | ||
|
@@ -287,6 +288,44 @@ function wp_get_layout_style( $selector, $layout, $has_block_gap_support = false | |
); | ||
} | ||
} | ||
} elseif ( 'grid' === $layout_type ) { | ||
if ( ! empty( $layout['columnCount'] ) ) { | ||
$layout_styles[] = array( | ||
'selector' => $selector, | ||
'declarations' => array( 'grid-template-columns' => 'repeat(' . $layout['columnCount'] . ', minmax(0, 1fr))' ), | ||
); | ||
} else { | ||
$minimum_column_width = ! empty( $layout['minimumColumnWidth'] ) ? $layout['minimumColumnWidth'] : '12rem'; | ||
|
||
$layout_styles[] = array( | ||
'selector' => $selector, | ||
'declarations' => array( 'grid-template-columns' => 'repeat(auto-fill, minmax(min(' . $minimum_column_width . ', 100%), 1fr))' ), | ||
); | ||
} | ||
|
||
if ( $has_block_gap_support && isset( $gap_value ) ) { | ||
$combined_gap_value = ''; | ||
$gap_sides = is_array( $gap_value ) ? array( 'top', 'left' ) : array( 'top' ); | ||
|
||
foreach ( $gap_sides as $gap_side ) { | ||
$process_value = is_string( $gap_value ) ? $gap_value : _wp_array_get( $gap_value, array( $gap_side ), $fallback_gap_value ); | ||
// Get spacing CSS variable from preset value if provided. | ||
if ( is_string( $process_value ) && str_contains( $process_value, 'var:preset|spacing|' ) ) { | ||
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. Won't 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. Looks like array(
'top' => '12px', // column
'left' => '11px', // row
) So I think the extra string check makes sense if we're fetching the value of 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. Checking if $combined_gap_value .= "$process_value " 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 logic is repeated for the flex layout type, so might also be worth looking into separately and fixing all instances together. 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. Oh sorry, I didn't make it down to I'm pretty sure the assumption is "yes", it's a string, so the extra check is probably redundant (?) I guess folks could add anything as a style value in theme.json (and they probably do), even if it's contrary to the theme.json schema rules. |
||
$index_to_splice = strrpos( $process_value, '|' ) + 1; | ||
$slug = _wp_to_kebab_case( substr( $process_value, $index_to_splice ) ); | ||
$process_value = "var(--wp--preset--spacing--$slug)"; | ||
} | ||
$combined_gap_value .= "$process_value "; | ||
} | ||
$gap_value = trim( $combined_gap_value ); | ||
|
||
if ( null !== $gap_value && ! $should_skip_gap_serialization ) { | ||
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. I don't think Although I see this is how it's done elsewhere in the file. If it can't be 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. Agreed, better look into cleaning all the checks up at once in a separate issue. |
||
$layout_styles[] = array( | ||
'selector' => $selector, | ||
'declarations' => array( 'gap' => $gap_value ), | ||
); | ||
} | ||
} | ||
} | ||
|
||
if ( ! empty( $layout_styles ) ) { | ||
|
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.
Need
@since
annotationThere 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.
Oh, thanks! I forget about them half the time 😅