-
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
Add shortName
property to FontSize Preset to override t-shirt size label
#46586
Conversation
If a fontSize preset defines a shortName property and the property is between 1 and 3 characters long this shortName will get displayed instead of the tshirt size value. This of course only applies if there are fewer than 6 font size presets were defined in which case the FontSizePicker shows the full name in the SelectControl instead.
For my local testing I updated the {
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 2,
"settings": {
"appearanceTools": true,
"layout": {
"contentSize": "840px",
"wideSize": "1100px"
},
"typography": {
"fontSizes": [
{
"name": "XSmall",
"size": "12px",
"slug": "xsmall",
"shortName": "XS"
},
{
"name": "Custom",
"size": "12px",
"slug": "custom",
"shortName": "CC"
},
{
"name": "Large",
"size": "12px",
"slug": "large"
}
]
}
},
"patterns": [ "short-text-surrounded-by-round-images", "partner-logos" ]
} |
fontSize.shortName && | ||
hasValidShortName( fontSize.shortName ) |
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.
fontSize.shortName && | |
hasValidShortName( fontSize.shortName ) | |
hasValidShortName( fontSize?.shortName ) |
Suggestion: The hasValidShortName
will return false if short name is undefined.
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.
@Mamaduka the reason I added back in the duplicate check is that TypeScript is complaining about it for whatever reason... See https://github.com/WordPress/gutenberg/actions/runs/3706287491/jobs/6281315087
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 just noticed it. Sorry about that. Let's revert for now, and maybe more TS-savvy people can help us here.
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.
Reverted in dc9fdd4
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 should work to remove this so long as hasValidShortName
's argument type is string | undefined
.
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.
Yeah for whatever reason that doesn't work for me. As per your later comment, I now removed the | undefined
type from the function and kept the duplicate check inline.
packages/components/src/font-size-picker/font-size-picker-toggle-group.tsx
Outdated
Show resolved
Hide resolved
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 unfamiliar with this component, but the code looks good to me 👍
Probably @noisysocks or @ramonjd can provide better feedback here.
P.S. I think it's a missed opportunity not to call the new property the shirtName
😄
Thanks for the great PR, @fabiankaegy ! I have confirmed that it generally works correctly. It works correctly with 39317f4f9a6d7be2098a530f49eef0cd.mp4I think the idea of short names of 3 characters or less being considered correct is great, but it may cause text wrapping in non-English languages. I think this is probably because the width of a single letter varies from language to language. One possible approach is to either allow only alphabetical characters or reduce the left and right padding. |
@jasmussen |
…le-group.tsx Co-authored-by: George Mamadashvili <georgemamadashvili@gmail.com>
@t-hamano Thanks for your detailed testing! I was concerned about non-Latin characters and how they would relate to the t-shirt sizing. I'm curious, how does the UI currently treat the t-shirt sizes? Are they not translated and shown as |
…ker-toggle-group.tsx" This reverts commit 49ec766.
packages/components/src/font-size-picker/font-size-picker-toggle-group.tsx
Outdated
Show resolved
Hide resolved
*/ | ||
export function hasValidShortName( shortName: string | undefined ): boolean { | ||
return ( | ||
typeof shortName === '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.
Is this check necessary? Is it possible to pass e.g. a number to shortName
? I thought theme.json
was validated against the schema but could be wrong.
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.
Makes sense. cc. @glendaviesnz as he added the original T-shirt size feature. |
I think it was @ramonjd actually, and I copied it for spacing sizes, but it was subsequently removed from there. |
Co-authored-by: Robert Anderson <robert@noisysocks.com>
…x length validation
Hey folks, catching up! I really appreciate the attention to detail and motivation for flexibility that is driving the work here, and seeing the collaboration is inspiring. I would, however, caution that when we add a new API like this, we have to be extra careful, and increase our confidence more than usual, before we land it. It's orders of magnitude easier to add an API than it is to remove one. In this case, there are a couple of flags that suggest we need a bit of a wider take, to boost that confidence (CC: @WordPress/gutenberg-core):
As is, my personal take is that the intent behind this PR is right (thank you), but the execution of the API is likely to have a number of side effects and ultimately might lead to bad experiences. In that light, it might be more useful to enable the dropdown with a prop change. What do you think? |
Wouldn't it be more appropriate to call the new property gutenberg/packages/components/src/font-size-picker/font-size-picker-toggle-group.tsx Lines 32 to 33 in 30a4d86
L32 could be easily transformed into the following, which is consistent with what L33 already does: label={ fontSize.label || T_SHIRT_ABBREVIATIONS[ index ] }
aria-label={ fontSize.name || T_SHIRT_NAMES[ index ] } once the new This naming would make it more intuitive. |
Closing this PR in favor of another solution that can be used to force the dropdown. Thanks for all the discussion :) |
What?
Add a new
shortName
property which can optionally be added to any FontSize Preset intheme.json
which gets used instead of hardcoded t-shirt size inFontSizePicker
Why?
As outlined in #44245 there are several usecases where font sizes may not be following the t-shirt size scale. When you for example start with
XS
and make your way from there. Or have multiple small variants you want to be able to better control the labels that get used for the various custom font size options.Closing: #44245
How?
By adding a new optional
shortName
property to font size presets.Testing Instructions
shortName
defined in it'stheme.json
.Testing Instructions for Keyboard
Screenshots or screencast