-
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
Block Support: Add font style and weight options with combined UI #26444
Block Support: Add font style and weight options with combined UI #26444
Conversation
@jasmussen Hope you don't mind I started a fresh PR for this. When you get the chance can you take a look at the new control combining font style and weight options? I'm not sure if it needs separators between the groups of weight/style combos. Also, should it be 100% width or do you see it potentially fitting in alongside other options? |
Nice. This is what I see: The names are all-caps, due to this rule it appears: It seems that rule was intended for menu subheadings, but is a little wide-reaching. Suffice to say, the fonts should not be all-caps, and should be the usual Other than that, this is working well, and feels obvious. 👍 👍 |
I've updated the control's styling so the items:
Thanks for all the feedback. I think this is getting close now 🙂 |
ca28824
to
66805f0
Compare
I've rebased this to pull in the latest changes in approach to registering/applying block support. I think this just needs a review now to move forward. |
This is cool: I think you should sync up with @karmatosed per the opportunity outlined in #26572 (comment), it looks like you're both touching the same files, and the color, font size, all caps styles that are currently inherited, probably shouldn't be inherited at all. |
I'm glad you're happy so far with the combined weight/style dropdown.
Agreed. Those styles appear to be applied when they shouldn't be. I was hoping to be able to take a look at where they are actually used and tweak the CSS accordingly. I will probably do that via a separate PR though. |
By the way, can you add a separator between the regular and italic weights? It's not super necessary but would be nice. |
I initially thought it could do with a separator in there as well although I didn't find an obvious option to do that. Now, it's been brought up, I'll take another look at it next week. My main issue was making sure that I wasn't adding another option that users could interact with or would impede accessibility. If anyone has any suggestions for doing this with a |
The separator should not block this PR. |
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.
66805f0
to
8633766
Compare
I've rebased and resolved conflicts for this however it will need another round of rebasing and resolving conflicts after #26059 is merged. |
3d07a0a
to
9066ca9
Compare
Adds both font style and font weight block support options. The UI for both are combined into a single dropdown. The inline styles generated via this feature leverage CSS variables.
9066ca9
to
5eaf4fc
Compare
React Native test failures here look unrelated to this PR, so moving ahead on merge as others have passed. |
Hey there @apeatling 👋 How did you conclude that the React Native test failures are unrelated to this PR? Because they are indeed breaking React Native. You can see here that this PR is the first one breaking the React Native tests on master branch. Do you think there is a way we can make it easier to spot that a PR will be breaking React Native in the future? |
I'd like to denote that because of the high amount of code sharing between the web and mobile client (a good thing 🎉) it's not easy to tell if a change will affect the native client just by looking at the code, or seeing that there are no |
A fix PR is |
@@ -161,6 +161,54 @@ | |||
"size": 42 | |||
} | |||
], | |||
"fontStyles": [ |
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.
Previously @mtias referred to the intention of not having more presets for now, besides the one for the font family. Would you be able to confirm if that's still the case @mtias?
In the fontStyles and fontWeights I'm not sure if presets bring much value. I guess it may make sense that the themes define for a given font family the weights and styles that are available because depending on the font family one font-weight may be loaded or not, but that may be discussed as part of font loading API.
I guess for font-weight and style we can use normal inline styles without presets e.g: "font-weight: 900;".
name: | ||
styleSlug === 'normal' | ||
? weightName | ||
: `${ weightName } ${ styleName }`, |
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 guess it may make sense to use sprintf and our translated function __ for i18n, depending on the locale it may make sense to change the order of weightName and styleName.
@@ -50,6 +50,7 @@ | |||
"html": false, | |||
"inserter": true, | |||
"fontSize": true, | |||
"__experimentalFontAppearance": true, |
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.
Font appearance is not something that is normally referred to. It was a UI decision to join them. But that decision may be changed in the future. For example, we may receive feedback to separate into weight and style using a different UI like buttons or to integrate additional typography settings into weight and style. I guess it would also make sense for a block to allow style selection without font-weight or the contrary. To me it feels like exposing the concept of font appearance as part of the block API is a restriction. What if we individually exposed fontWeight and fontStyle in block.json, the design may still join them in a single UI control. Depending on what is enabled, we would show some of the options.
@@ -50,6 +50,7 @@ | |||
"html": false, | |||
"inserter": true, | |||
"fontSize": true, | |||
"__experimentalFontAppearance": true, |
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.
Would it make sense to expand this to other blocks e.g: Site Title, Post Title, buttons?
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 just adds the controls at the block level, to keep things consistent I will try to follow up with a PR that adds the UI at the global styles level.
Sorry about this! We had fixed up a bunch of tests breaking, as well as rebased to fix some others that were breaking project wide. The breaking tests didn't seem related, at least from looking at the test result, but we may have been biased by all the previous breaking tests. What we can do in the future is ping someone specific to check first, if we know who the best person is. |
Thanks for the context @apeatling 🙇.
Going forward, if you encounter any React Native test failures feel free to ping @hypest or @Tug, and they can make sure the appropriate people are looped in. |
// presetStyle are the actual typography styles that should be given to onChange. | ||
presetStyle: { | ||
fontStyle: `var:preset|font-style|${ styleSlug }`, | ||
fontWeight: `var:preset|font-weight|${ weightSlug }`, |
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.
The other control components with presets that we have:
packages/block-editor/src/components/colors-gradients/control.js
packages/block-editor/src/components/font-family/index.js
packages/block-editor/src/components/font-sizes/font-size-picker.js
Don't handle the different ways a value should be stored, if a preset is used or not. They just receive a value, and a set of possible values (for UI purposes) and allow them to change the value. They are not aware of CSS vars etc..
}, | ||
{ | ||
"name": "Bold", | ||
"slug": "700" |
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.
In the other presets we use different keys for slug and value. This approach is using the same keys for both. The idea of presets is we can change the value and the places using a given slug will automatically all use the new value. If we use the slug for the value the main objective of the preset is not accomplished as one can not change the value without changing the slug.
The inline style we store ends up containing the value anyway var:preset|font-weight|100
. I guess removing presents from the fontWeight and fontStyle and just using values is the way 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.
In the other presets we use different keys for slug and value.
I can definitely update the presets to use both slug and value. It just seemed odd to me having both the slug and the value the same for the most part.
The inline style we store ends up containing the value anyway var:preset|font-weight|100. I guess removing presents from the fontWeight and fontStyle and just using values is the way to go.
The benefit I saw in using the presets that could be defined via the theme.json was that it also provided a means to customize the available styles or weights.
@aaronrobertshaw @apeatling this PR landed without documentation. I've prepared a fix for it at #26891 |
Description
After feedback and discussion around adding block support for font styles ( #26050 ), it was decided to add support for both font styles and font weights, then combine the UI controls for them.
Changes Included
How has this been tested?
Manually tested using navigation block.
Test Instructions
var()
and CSS variables relating to the selection made.Screenshots
Types of changes
Enhancement
Next Steps
class-block-supported-styles-test.php
if needed after approach confirmed.Checklist: