-
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
Global Styles: Only use single property variations as color/type presets #62469
Conversation
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: -147 B (-0.01%) Total Size: 1.76 MB
ℹ️ View Unchanged
|
@scruffian, according to the specification...
...shouldn't there be just one preset corresponding to the only color-only variation in TT4 (Onyx)? At least this is the behavior I would expect |
The other one is the default, so you can switch back to it. |
That was my guess, yes. I understand the need to reset to the default colors. However, I find this mechanism 'not immediately easy to grasp' in its current form. Are there other approaches (from a UI perspective) to 'un-apply' the preset that could be used here? I think this whole feature would be a bit easier to understand if there was only as many presets available as the ones generated from color-only variations (or typography-only variations). But maybe this is just me. I'll let others chime in and share their feedback. |
I think this approach is fine. It just looks strange in TT4 due to the way the style variations were originally built. Ideally, TT4 would have more dedicated color-only style variations to demonstrate this feature, or the Onyx style variation could be updated with an additional superfluous setting to disable the color-only palette generation. |
cc @jasmussen for a design perspective |
I think it's fine that the first one is the default. I'd rather update TT4 with more colors than opt the theme out of this completely. It's a symptom of how many theme variations are built (to be color only). |
It would be a nice marketing highlight as well. "With WordPress 6.6, the Twenty Twenty-Four theme has been updated to include X new color palettes..." |
@@ -51,14 +51,12 @@ export function removePropertyFromObject( object, property ) { | |||
* A convenience wrapper for `useThemeStyleVariationsByProperty()` that fetches the current theme style variations, |
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.
Since useThemeStyleVariationsByProperty
is deleted, this comment and the file names should probably be updated.
@@ -71,27 +69,26 @@ export function useCurrentMergeThemeStyleVariationsWithUserConfig( { | |||
}; | |||
}, [] ); | |||
const { user: baseVariation } = useContext( GlobalStylesContext ); | |||
const clondedBaseVariation = cloneDeep( baseVariation ); |
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.
Typo.
const clondedBaseVariation = cloneDeep( baseVariation ); | |
const clonedBaseVariation = cloneDeep( baseVariation ); |
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.
Actually, I don't think there's any reason to do a deep merge here. mergeBaseAndUserConfigs
uses deepmerge
which doesn't mutate the original object.
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.
Since I fixed a bug in ba440bd, I think we do need the clone again..
const variationsWithSinglePropertyAndBase = variationsFromTheme | ||
.filter( ( variation ) => { | ||
return isVariationWithSingleProperty( variation, property ); | ||
} ) | ||
.map( ( variation ) => { | ||
return mergeBaseAndUserConfigs( clondedBaseVariation, variation ); | ||
} ); |
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.
Move this inside the useMemo
. As it is now, the useMemo
is just pure overhead because this is creating a new array every time.
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!
I found a bug in this - the default variation doesn't contain any other user settings, so when I select it, everything is reset, not just the colors. |
@ajlende thanks for the review, I think I fixed all the issues :) |
...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 isVariationWithSingleProperty( variation, property ); | ||
} ) | ||
.map( ( variation ) => { | ||
return mergeBaseAndUserConfigs( baseVariation, variation ); |
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.
Should this be using the clonedBaseVariation
? If removePropertyFromObject
mutates the argument, then the old code below is merging the one without the property.
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.
Yes you're right, great catch. We want to apply only the typography styles from the variation, not include the ones from the base. I updated the PR and renamed a few variables too for clarity.
…eme-style-variations-by-property.js Co-authored-by: Alex Lende <alex+github.com@lende.xyz>
…eme-style-variations-by-property.js Co-authored-by: Alex Lende <alex+github.com@lende.xyz>
2c48f57
to
b3388de
Compare
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.
LGTM 👍
…ets (WordPress#62469) * Global Styles: Only use single property variations as color/type presets * remove unused code * remove unused code * remove unused code * update comment * fix typo * Add the user settings to the base variation * Update packages/edit-site/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js Co-authored-by: Alex Lende <alex+github.com@lende.xyz> * Update packages/edit-site/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js Co-authored-by: Alex Lende <alex+github.com@lende.xyz> * Remove the property from the user variation before merginng it with the new variation * apply the name to the correct object --------- Co-authored-by: Alex Lende <alex+github.com@lende.xyz> Co-authored-by: scruffian <scruffian@git.wordpress.org> Co-authored-by: jasmussen <joen@git.wordpress.org> Co-authored-by: ajlende <ajlende@git.wordpress.org> Co-authored-by: juanmaguitar <juanmaguitar@git.wordpress.org> Co-authored-by: ndiego <ndiego@git.wordpress.org> Co-authored-by: richtabor <richtabor@git.wordpress.org> Co-authored-by: colorful-tones <colorful-tones@git.wordpress.org>
Is this 6.6 related? Should it be backported? |
Yes, I believe it should be. Can you confirm @richtabor and @scruffian? |
Yes sorry it should be |
…ets (#62469) * Global Styles: Only use single property variations as color/type presets * remove unused code * remove unused code * remove unused code * update comment * fix typo * Add the user settings to the base variation * Update packages/edit-site/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js Co-authored-by: Alex Lende <alex+github.com@lende.xyz> * Update packages/edit-site/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js Co-authored-by: Alex Lende <alex+github.com@lende.xyz> * Remove the property from the user variation before merginng it with the new variation * apply the name to the correct object --------- Co-authored-by: Alex Lende <alex+github.com@lende.xyz> Co-authored-by: scruffian <scruffian@git.wordpress.org> Co-authored-by: jasmussen <joen@git.wordpress.org> Co-authored-by: ajlende <ajlende@git.wordpress.org> Co-authored-by: juanmaguitar <juanmaguitar@git.wordpress.org> Co-authored-by: ndiego <ndiego@git.wordpress.org> Co-authored-by: richtabor <richtabor@git.wordpress.org> Co-authored-by: colorful-tones <colorful-tones@git.wordpress.org>
I just cherry-picked this PR to the wp/6.6-rc-1 branch to get it included in the next release: dbd9830 |
…ets (#62469) * Global Styles: Only use single property variations as color/type presets * remove unused code * remove unused code * remove unused code * update comment * fix typo * Add the user settings to the base variation * Update packages/edit-site/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js Co-authored-by: Alex Lende <alex+github.com@lende.xyz> * Update packages/edit-site/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js Co-authored-by: Alex Lende <alex+github.com@lende.xyz> * Remove the property from the user variation before merginng it with the new variation * apply the name to the correct object --------- Co-authored-by: Alex Lende <alex+github.com@lende.xyz> Co-authored-by: scruffian <scruffian@git.wordpress.org> Co-authored-by: jasmussen <joen@git.wordpress.org> Co-authored-by: ajlende <ajlende@git.wordpress.org> Co-authored-by: juanmaguitar <juanmaguitar@git.wordpress.org> Co-authored-by: ndiego <ndiego@git.wordpress.org> Co-authored-by: richtabor <richtabor@git.wordpress.org> Co-authored-by: colorful-tones <colorful-tones@git.wordpress.org>
What?
In this PR we change the behaviour of color and typography presets so that we use only variations that contain nothing but that specific property.
Why?
This reduces the impact of the change to introduce color and typography presets as it means that only variations that target a specific property are used.
How?
Filter out all variations unless they contain only a specific variation.
Testing Instructions
Screenshots or screencast
Before:
After: