-
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: Allow font sizes to be overridden #57692
Conversation
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
Size Change: +7 B (0%) Total Size: 1.69 MB
ℹ️ View Unchanged
|
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.
Two things:
- Should the array reversal be done in
mergeOrigins()
instead? How are the other global styles handling this? Are other things bugged too? - It seems wasteful to just reverse the array and output everything when we already know that the first one output will always be unused. It's only a handful of bytes that we're saving, but it doesn't seem that much harder to just remove the duplicates.
@@ -104,7 +104,7 @@ function getUniqueFontSizesBySlug( settings ) { | |||
const fontSizes = settings?.typography?.fontSizes; | |||
const mergedFontSizes = fontSizes ? mergeOrigins( fontSizes ) : []; | |||
const uniqueSizes = []; | |||
for ( const currentSize of mergedFontSizes ) { | |||
for ( const currentSize of mergedFontSizes.reverse() ) { |
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 wouldn't use .reverse()
like this. It mutates the array in-place. Having read through mergeOrigins()
, it looks like it returns a new array, so it wouldn't have side-effects here, but it would be better to attach the .reverse()
to mergeOrigins( fontSizes ).reverse()
so the relationship between them is more clear.
Alternatively, if you don't want to mutate the original array, [].toReversed()
has good browser support these days at the cost of more memory usage.
I dont think this is the right approach. |
What?
Allow themes to override the default font sizes.
WIP
Why?
When a theme provides custom font sizes that use the same slugs as the default, the theme ones should override the defaults.
How?
The way that this works is not the right way to do it.
Font sizes get merged from "default" and "theme" into a "custom" attribute. This is then made unique in order, so I have reversed the order so that the theme settings win. I think the way we should do this is to provide both "default" and "theme" to the control and allow it to do a merge based on the key rather than just the order.
Testing Instructions
Screenshots or screencast