Skip to content

Commit

Permalink
Supporting blockGap and background color vars
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonjd committed Jul 1, 2022
1 parent 9dc05db commit 0e16df9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,11 +513,13 @@ public function get_styles_for_block( $block_metadata ) {
$node,
array(
'selector' => $selector,
'css_vars' => true,
'prettify' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG,
)
);

if ( isset( $styles['css'] ) ) {

$block_rules .= $styles['css'];
}

Expand Down
22 changes: 22 additions & 0 deletions packages/style-engine/class-wp-style-engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class WP_Style_Engine {
'default' => 'background-color',
),
'path' => array( 'color', 'background' ),
'css_vars' => array(
'--wp--preset--color--$slug' => 'color',
),
'classnames' => array(
'has-background' => true,
'has-$slug-background-color' => 'color',
Expand Down Expand Up @@ -156,6 +159,14 @@ class WP_Style_Engine {
),
'path' => array( 'spacing', 'margin' ),
),
'blockGap' => array(
'value_func' => 'static::get_css_custom_property_declaration',
'property_keys' => array(
'default' => 'gap',
'css_var' => '--wp--style--block-gap',
),
'path' => array( 'spacing', 'blockGap' ),
),
),
'typography' => array(
'fontSize' => array(
Expand Down Expand Up @@ -403,6 +414,7 @@ public function generate( $block_styles, $options ) {
if ( ! empty( $css_declarations ) ) {
// Generate inline style declarations.
foreach ( $css_declarations as $css_property => $css_value ) {
// @TODO Commented out so that it can test CSS property definitions, e.g., --wp--preset--something: 1px;
$filtered_css_declaration = esc_html( safecss_filter_attr( "{$css_property}: {$css_value}" ) );
if ( ! empty( $filtered_css_declaration ) ) {
if ( $should_prettify ) {
Expand Down Expand Up @@ -495,6 +507,16 @@ protected static function get_individual_property_css_declarations( $style_value
}
return $css_declarations;
}

// For block gap. TESTING!!!
// This only works for static::ROOT_BLOCK_SELECTOR right now.
protected static function get_css_custom_property_declaration( $style_value, $style_definition ) {
$rules = array();
if ( isset( $style_definition['property_keys']['css_var'] ) ) {
$rules[ $style_definition['property_keys']['css_var'] ] = $style_value;
}
return $rules;
}
}

/**
Expand Down

0 comments on commit 0e16df9

Please sign in to comment.