-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Global Styles: Allow variations to be filtered by multiple properties #62847
Conversation
update variables add filtering to the default variation add spacing to variation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: -11 kB (-0.63%) Total Size: 1.75 MB
ℹ️ View Unchanged
|
]; | ||
}, [ property, userVariation, variationsFromTheme ] ); | ||
}, [ properties, userVariation, variationsFromTheme ] ); |
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'm not familiar with this code at all but there's something that is probably not right here. If you're using properties as a dependency for a useMemo call, I'm guessing that you expect the same object instance to be returned here if the properties don't change (maybe for some performance reasons), but here it's almost never the case since properties is passed as an inline array, so properties will always trigger a recompute and a new instance returned by useMemo.
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.
Ah yes good point. Would it work to spread the properties in the dependency array, like this?
}, [ properties, userVariation, variationsFromTheme ] ); | |
}, [ ...properties, userVariation, variationsFromTheme ] ); |
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 wouldn't work either, because the size of the properties array might change and I believe it's not allowed in these react hooks to have a variable size.
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.
What if we convert the array to a string?
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.
It would work I think.
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.
Done in ea0be03
… can compare them accurately
I'm not familiar enough with this part of the code to do a full review here. I'll let others chime in. |
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 couldn't see any regressions in the editor - between trunk and this PR the style variations in TT4 are the same in both the Site Editor sidebar (view mode) and the global styles inspector. 👍🏻
The change makes sense to me - extracting several properties at a time.
Looks like the unit tests need to be updated.
...ges/edit-site/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js
Outdated
Show resolved
Hide resolved
...ges/edit-site/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js
Outdated
Show resolved
Hide resolved
...ges/edit-site/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js
Outdated
Show resolved
Hide resolved
...ges/edit-site/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js
Outdated
Show resolved
Hide resolved
...ges/edit-site/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js
Outdated
Show resolved
Hide resolved
...ges/edit-site/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js
Outdated
Show resolved
Hide resolved
); | ||
|
||
return ( | ||
JSON.stringify( variationWithProperty?.styles ) === | ||
JSON.stringify( variationWithProperties?.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.
Optional, but also available is areGlobalStyleConfigsEqual
const { areGlobalStyleConfigsEqual } = unlock(
blockEditorPrivateApis
);
...
return areGlobalStyleConfigsEqual( variationWithProperties, variation);
…eme-style-variations-by-property.js Co-authored-by: Ramon <[email protected]>
…eme-style-variations-by-property.js Co-authored-by: Ramon <[email protected]>
…eme-style-variations-by-property.js Co-authored-by: Ramon <[email protected]>
…eme-style-variations-by-property.js Co-authored-by: Ramon <[email protected]>
Thanks for the review! I have updated the tests, hopefully this is good to go :) |
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.
Thanks for the updates @scruffian 🙇🏻
Tests well for me
…WordPress#62847) * Global Styles: Include spacing rules as part of typography variations update variables add filtering to the default variation add spacing to variation * Global Styles: Allow presets to use more than one property * treat the properties in the dependency array as a string so Object.is can compare them accurately * Update packages/edit-site/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js Co-authored-by: Ramon <[email protected]> * Update packages/edit-site/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js Co-authored-by: Ramon <[email protected]> * Update packages/edit-site/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js Co-authored-by: Ramon <[email protected]> * Update packages/edit-site/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js Co-authored-by: Ramon <[email protected]> * update docs * use areGlobalStyleConfigsEqual * update tests --------- Co-authored-by: Ramon <[email protected]> Co-authored-by: scruffian <[email protected]> Co-authored-by: youknowriad <[email protected]> Co-authored-by: ramonjd <[email protected]>
What?
This updates several functions to allow presets to incorporate several properties.
Why?
This was originally proppsed as part of #62709, and was also part of #62741. It's not clear what direction we want to go with this, but this code maintains the same functionality while adding flexibility by allowing you to provide an array to these functions rather than a string.
How?
Update several functions to accept an array rather than a string.
Testing Instructions