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

Style engine: return declarations in array response #42307

Merged
merged 1 commit into from
Jul 11, 2022

Conversation

ramonjd
Copy link
Member

@ramonjd ramonjd commented Jul 11, 2022

What?

This PR adds uncompiled CSS declarations to the return values of get_block_supports_styles so that consumers can use the array values (if they want)

Props to @andrewserong for the idea over at #42085 (review)

Why?

Consumers might want to access parsed declarations but not necessarily the compiled version.

Parsed declarations will have already converted var:preset|slug values to var(--wp--preset--slug).

Real world use case: #42085 (review)

How?

As well as the compiled CSS, wp_style_engine_get_block_supports_styles() will return the array of css declarations as stored in WP_Style_Engine_CSS_Declarations.

wp_style_engine_get_block_supports_styles( 
    array(
        'border' => array(
            'bottom' => array(
                'color'  => 'var:preset|color|terrible-lizard',
            ),
        ),
    )
);

/* Returns:
array(
    'css'          => 'border-bottom-color: var(--wp--preset--color--terrible-lizard);',
    'declarations' => array(
        'border-bottom-color' => 'var(--wp--preset--color--terrible-lizard)',
    ),
)
*/

Testing Instructions

npm run test-unit-php /var/www/html/wp-content/plugins/gutenberg/packages/style-engine/phpunit/class-wp-style-engine-test.php

@ramonjd ramonjd self-assigned this Jul 11, 2022
@ramonjd ramonjd added [Package] Style Engine /packages/style-engine [Type] Enhancement A suggestion for improvement. labels Jul 11, 2022
Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, tests are passing, and smoke tested quickly that it doesn't break anything.

Thanks for putting this together so quickly!

…pports_styles` so that consumers can use the array values (if they want)

Updated tests
@ramonjd ramonjd force-pushed the add/style-engine-return-uncompiled-declarations branch from 72611a3 to 0a3bde8 Compare July 11, 2022 06:08
@ramonjd ramonjd merged commit 8abbcb5 into trunk Jul 11, 2022
@ramonjd ramonjd deleted the add/style-engine-return-uncompiled-declarations branch July 11, 2022 07:02
@github-actions github-actions bot added this to the Gutenberg 13.7 milestone Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Style Engine /packages/style-engine [Type] Enhancement A suggestion for improvement.
Projects
Status: 🏆 Done
Development

Successfully merging this pull request may close these issues.

2 participants