Skip to content
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

Expose layout values from theme.json as css-variables #30081

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
$style = '';
if ( $content_size || $wide_size ) {
$style = ".wp-container-$id > * {";
$style .= 'max-width: ' . esc_html( $all_max_width_value ) . ';';
$style .= '--wp--layout--content-size:' . esc_html( $all_max_width_value ) . ';';
$style .= '--wp--layout--wide-size:' . esc_html( $wide_max_width_value ) . ';';
$style .= 'max-width: var(--wp--layout--content-size);';
$style .= 'margin-left: auto !important;';
$style .= 'margin-right: auto !important;';
$style .= '}';

$style .= ".wp-container-$id > .alignwide { max-width: " . esc_html( $wide_max_width_value ) . ';}';
$style .= ".wp-container-$id > .alignwide { max-width: var(--wp--layout--wide-size); }";

$style .= ".wp-container-$id .alignfull { max-width: none; }";
}
Expand Down
11 changes: 8 additions & 3 deletions packages/block-editor/src/components/block-list/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,19 @@ export function LayoutStyle( { selector, layout = {} } ) {
let style =
!! contentSize || !! wideSize
? `
${ selector } {
--wp--layout--content-size: ${ contentSize ?? wideSize };
--wp--layout--wide-size: ${ wideSize ?? contentSize };
}

${ appendSelectors( selector, '> *' ) } {
max-width: ${ contentSize ?? wideSize };
max-width: var(--wp--layout--content-size);
margin-left: auto !important;
margin-right: auto !important;
}

${ appendSelectors( selector, '> [data-align="wide"]' ) } {
max-width: ${ wideSize ?? contentSize };
${ appendSelectors( selector, '> [data-align="wide"]' ) } {
max-width: var(--wp--layout--wide-size);
}

${ appendSelectors( selector, '> [data-align="full"]' ) } {
Expand Down