-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Style engine: support nested CSS rules (or CSS containers) #58797
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
Conversation
|
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ phpunit/style-engine/class-wp-style-engine-css-rules-container-test.php ❔ lib/load.php ❔ phpunit/style-engine/class-wp-style-engine-css-rules-store-test.php ❔ phpunit/style-engine/class-wp-style-engine-processor-test.php ❔ phpunit/style-engine/style-engine-test.php |
|
Size Change: 0 B Total Size: 1.71 MB ℹ️ View Unchanged
|
9208e2a to
975eb35
Compare
# Clean up after rebase Clean up after rebase
Ensuring we can add rule objects to store Tests new container class
b540eb6 to
08211cc
Compare
ramonjd
left a comment
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.
Still testing.
Does "container" make sense? It can apply to CSS nesting, at-rules etc
|
|
||
| /** | ||
| * Holds, sanitizes, processes and prints CSS declarations for the Style Engine. | ||
| * Holds, sanitizes, processes and prints CSS rules for the Style Engine. |
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.
Aside from this copy update, these changes just revert those in #58867
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.
New class with a similar interface to WP_Style_Engine_CSS_Rule
This is intentional so that the relevant getter class methods such as get_css/selector can be called where there is a collection of rules + nested rules, e.g., in a single store.
Also so WP_Style_Engine_CSS_Rule doesn't need to care about whether its nested or not, which is the same as the declarations class, and can take care of its own output.
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.
TODO - WP_Style_Engine_CSS_Rules_Container should extend WP_Style_Engine_CSS_Rule, or even look into adding WP_Style_Engine_CSS_Rules_Container methods to WP_Style_Engine_CSS_Rule itself.
I'd say the former to maintain separation of concerns.
Reason being, with nested CSS, the container rule should also be able to have declarations.
This can be handled by the existing API, indicated by passing a container and not a selector:
wp_style_engine_get_stylesheet_from_css_rules(
array(
'container' => 'fieldset',
'declarations' => array( .... )
),
array(
'container' => 'fieldset',
'container' => 'textarea',
'declarations' => array( .... )
)
)
/*
Output:
fieldset {
...declarations;
textarea {
...declarations;
}
}
*/ 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.
I can't seem to unit test this using $this->expectNotice();
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.
Bumps the indent count for nested rules
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.
If the selector is a string create a CSS_Rule. This is legacy behaviour. Containers should be passed as already instantiated.
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.
That's a mouthful.
Store combines existing rules Store combines
f3e82d7 to
081de82
Compare
|
Flaky tests detected in 1737f72. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7860556773
|
| } | ||
|
|
||
| if ( $container ) { | ||
| $new_rule = new WP_Style_Engine_CSS_Rules_Container( $container, $new_rule ); |
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.
A WP_Style_Engine_CSS_Rules_Container also allows us to limit the depth of nested rules to 1
Does the CSS spec have a name for these? |
That's a good question. I haven't found anything really striking so far, other than Maybe "nested-rule" is the closest to the spec I can find. |
In MDN the closest I could find was either "nested" or "conditional group rules" under at-rules... also a bit of a mouthful! |
Edit: or just "parent" |
|
Naming's always hard! I think I lean slightly toward |
|
This was just an experiment. Closing in favour of: |
In progress... this PR will be pared back to satisfy the minimum requirements of #58867. I'm coding "ahead" to validate the approach 😁
What?
Proposed refactor as a follow up to #58867, from which all the ideas flow. Props to @tellthemachines
Provide an API to generate nested CSS rules, e.g.,
Expressed in PHP:
Features:
TODO
@containerqueries) See: Add/try/style engine nested rules explosion/add/grid child spans #58919Why?
To provide a base-line way to add nested rules.
How?
Creating a
WP_Style_Engine_CSS_Rules_Containerthat storesWP_Style_Engine_CSS_Ruleobjects and outputs nested CSS.Accepting a
containervalue in the public API functions of:wp_style_engine_get_stylesheet_from_css_rules()wp_style_engine_get_styles()Testing Instructions
npm run test:unit:php:base -- --group style-engineTesting Instructions for Keyboard
Screenshots or screencast