-
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
Columns block: reinstate tablet 2 col stacking #41123
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
94a97f9
This change reinstates the tablet breakpoint CSS for the columns bloc…
ramonjd 0d0de91
Added extra comments for clarity
ramonjd 8825883
Testing out an approach similar to the gallery block #38164
ramonjd c4f5415
Lint, lint, lint
ramonjd 1a0456c
Testing with block styles.
ramonjd 37ed4ed
Enqueue styles with priority, following on from https://github.com/Wo…
ramonjd 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { BlockList } from '@wordpress/block-editor'; | ||
import { useContext, createPortal } from '@wordpress/element'; | ||
|
||
export default function GapStyles( { blockGap, clientId } ) { | ||
const styleElement = useContext( BlockList.__unstableElementContext ); | ||
|
||
if ( ! blockGap ) { | ||
return null; | ||
} | ||
|
||
// Check for the possibility of split block gap values. See: https://github.com/WordPress/gutenberg/pull/37736. | ||
const gapValue = typeof blockGap === 'string' ? blockGap : blockGap?.left; | ||
|
||
if ( ! gapValue ) { | ||
return null; | ||
} | ||
|
||
const gap = `#block-${ clientId } { | ||
--wp--style--unstable-columns-gap: ${ gapValue }; | ||
}`; | ||
|
||
const GapStyle = () => { | ||
return <style>{ gap }</style>; | ||
}; | ||
|
||
return gap && styleElement | ||
? createPortal( <GapStyle />, styleElement ) | ||
: null; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
/** | ||
* Server-side rendering of the `core/columns` block. | ||
* | ||
* @package WordPress | ||
*/ | ||
|
||
/** | ||
* Adds a style tag for the --wp--style--unstable-columns-gap var. | ||
* | ||
* The Columns block requires the block's spacing blockGap value in order to calculate the 2 column offset in tablet viewport. | ||
* | ||
* @param array $attributes Attributes of the block being rendered. | ||
* @param string $content Content of the block being rendered. | ||
* @return string The content of the block being rendered. | ||
*/ | ||
function block_core_columns_render( $attributes, $content ) { | ||
$gap_value = _wp_array_get( $attributes, array( 'style', 'spacing', 'blockGap' ), null ); | ||
|
||
if ( ! $gap_value ) { | ||
return $content; | ||
} | ||
|
||
// Skip if gap value contains unsupported characters. | ||
// Regex for CSS value borrowed from `safecss_filter_attr`, and used here | ||
// because we only want to match against the value, not the CSS attribute. | ||
if ( is_array( $gap_value ) ) { | ||
foreach ( $gap_value as $key => $value ) { | ||
$gap_value[ $key ] = $value && preg_match( '%[\\\(&=}]|/\*%', $value ) ? null : $value; | ||
} | ||
} else { | ||
$gap_value = preg_match( '%[\\\(&=}]|/\*%', $gap_value ) ? null : $gap_value; | ||
} | ||
|
||
// The gap value can be a string value or a split top/left value. For the columns we want `left` which equates to gap-column. | ||
// See: https://github.com/WordPress/gutenberg/pull/37736. | ||
if ( is_array( $gap_value ) ) { | ||
$gap_value = isset( $gap_value['left'] ) ? $gap_value['left'] : null; | ||
} | ||
|
||
if ( ! $gap_value ) { | ||
return $content; | ||
} | ||
|
||
$class = wp_unique_id( 'wp-block-columns-' ); | ||
$content = preg_replace( | ||
'/' . preg_quote( 'class="', '/' ) . '/', | ||
'class="' . $class . ' ', | ||
$content, | ||
1 | ||
); | ||
|
||
$style = '.' . $class . '{ --wp--style--unstable-columns-gap: ' . $gap_value . ';}'; | ||
gutenberg_enqueue_block_support_styles( $style, 11 ); | ||
return $content; | ||
} | ||
|
||
/** | ||
* Registers the `core/columns` block on server. | ||
*/ | ||
function register_block_core_columns() { | ||
register_block_type_from_metadata( | ||
__DIR__ . '/columns', | ||
array( | ||
'render_callback' => 'block_core_columns_render', | ||
) | ||
); | ||
} | ||
|
||
add_action( 'init', 'register_block_core_columns' ); |
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
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.
Just jotting down a brain spasm: I was wondering if we should toggle the style off when
isStackedOnMobile !== true
It might cause extra confusion though remembering to toggle it back on.