-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add padding control to the Global Styles sidebar #27154
Conversation
Size Change: +195 B (0%) Total Size: 1.28 MB
ℹ️ View Unchanged
|
b258cbe
to
4eeab8b
Compare
4eeab8b
to
be27842
Compare
@jorgefilipecosta this is ready for feedback/review. |
Hi @nosolosw I'm not able to see the padding control UI. Not sure if I'm missing something, or if we had a regression. |
return ( | ||
<PanelBody title={ __( 'Spacing' ) }> | ||
<BoxControl | ||
values={ paddingValues } |
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.
One way this global-level control is different from the block-level control is that the global-level doesn't use the visualizer to highlight the padding changes. The block-level control has a hold of the current block being edited, which is not true for the global-level control. A potential nice follow-up for this would be to highlight all the blocks of the given type being edited (in this case, group, or cover, etc).
de66ab3
to
86f72fe
Compare
@jorgefilipecosta I've rebased this branch and tested with a brand new site: latest WP core environment, latest TT1-blocks (note that it was renamed recently), and this branch for the Gutenberg plugin. It still works as expected for me. Throwing out some random ideas in case it helps:
🤔 I can't think of anything else apart from the above at the moment. If none of the above works, I'm happy to help debug this. |
$value = self::get_property_value( $context['styles'], $metadata['value'] ); | ||
// Some properties can be shorthand properties, meaning that | ||
// they contain multiple values instead of a single one. | ||
if ( self::has_properties( $metadata ) ) { |
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.
We are producing styles like:
.wp-block-group {
padding-top: 5px;
padding-right: 5px;
padding-bottom: 5px;
padding-left: 5px;
}
Could we be smart and output something like "padding: 5px" in these cases? To avoiding sending unrequited bytes over the wire?
I guess we can use a "padding" property every time all for properties are set and the same behavior can be applied to margins borders etc.
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'd be nice, can we get this in in a follow-up?
Thank you for helping me fix my local test issues @nosolosw! I'm now able to test the adding panels on global styles. |
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.
Hi @nosolosw,
We also need to update the escaping to recognize values with multiple properties otherwise we may throw warnings.
gutenberg/lib/class-wp-theme-json.php
Line 507 in 69bf4e6
$result = safecss_filter_attr( "$name: $value" ); |
2c1907e
to
0850d16
Compare
Rebased to get the latest PRs merged and fixed this. |
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.
Everything worked well on my tests. I guess we just need to fix the safecss_filter_attr argument issue before the merge.
if ( is_array( $value ) ) { | ||
$result = array(); | ||
foreach ( $value as $subproperty => $subvalue ) { | ||
$result_subproperty = safecss_filter_attr( "$name: $subvalue" ); |
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.
We are calling safecss_filter_attr with things like:
string(21) "background-color: 8px"
string(22) "background-color: 50px"
string(21) "background-color: 8px"
string(21) "background-color: 9px"
Possible to test by setting a user padding and adding var_dump( "$name: $subvalue" );
before safecss_filter_attr filter call.
$name = 'background-color';
if ( 'gradient' === $property ) {
$name = 'background';
}
Name is always background-color or background we need to make sure the name also accounts for the padding properties.
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.
This is intentional, safecss_filter_attr does not check fine-grained semantics of the declaration, it only has 3 cases: 1) the value is fine (does not contain slashes, parenthesis, etc), 2) the value can contain gradients if the property is allowed to have gradients according to kses, and 3) the value can contain URL data if the property is considered safe for that. As per properties, as long they're is in the allowed list, things are fine.
Via theme.json we output more properties than the allowed by the kses function, for example, link color (a CSS Custom Property). I thought the current approach was simpler and equally robust than transforming every property to its CSS form except for link color, which we'd need to transform to another thing.
How do you feel about this?
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.
This PR doesn't change this behavior so went ahead and merge it. We can continue to discuss whether this is how we want it to behave.
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 thought the current approach was simpler and equally robust than transforming every property to its CSS form except for link color, which we'd need to transform to another thing.
How do you feel about this?
Hi @nosolosw, I think we need to update and use the correct CSS properties because using just two hardcoded properties is not something expected. E.g: A plugin may change to allow using filter safecss_filter_attr_allow_css a specific CSS only on a specific property, and with this approach, we don't respect what the plugin wants to do.
I'm doing some more testing, it seems like I'm running into some errors, and want to understand why (it may be due to old user theme.json before 0850d16). Leaving a comment so this isn't merged until that. |
50d7b93
to
8f428c3
Compare
Rebased and tested fresh and everything is fine. |
Depends on #27099
This PR adds the spacing panel to the Global Styles sidebar, so if any block declares support for it (at the moment of writing this, only group and cover) it'll be shown at the global level as well.
How to test
Test that the padding controls work in the site editor:
Test that the padding controls still work it the post editor: