Skip to content
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

[Components - FontSizePicker]: Use incremental sequence of numbers as labels for the available font-sizes at the segmented control (conditionally) #37038

Merged
merged 5 commits into from
Dec 15, 2021

Conversation

ntsekouras
Copy link
Contributor

@ntsekouras ntsekouras commented Dec 1, 2021

Part of #36545

There are only 5 font sizes but the styles sidebar still shows a big dropdown. Make sure Twenty twenty two theme uses the segmented control for font sizes.

Currently the logic for showing the segmented control depends on having at most five font sizes and only if none of them contain css complex values (clamp, var, etc..). This is because on the segmented control we show as labels the actual numeric value of the font size and it's not possible to calculate these dynamic values.

To accommodate use cases where at most five font sizes are available but also contain complex css values, this PR proposes to use an incremental sequence of numbers (1/2/3/4/5) as labels for the available font-sizes automatically. As @jasmussen noted:

Outside of revisiting those default slugs, there's an argument to make that the numbers catch a wider range of options. For better and worse, the numbers just go from small to larger, and need to be (and are) paired with the labels the theme defines.

The previous approach with adding an alias property to font size object is also a convention that could create more confusion to theme developers.

Screen.Recording.2021-12-15.at.10.07.48.AM.mov

Testing instructions

Storybook (npm run storybook:dev)

Change values through the available knobs in With Complex Css Values story

With a block theme

  1. In a block theme you test add to your fontSizes at least one complex css value
  2. Make sure to have at most five font sizes

@github-actions
Copy link

github-actions bot commented Dec 1, 2021

Size Change: +56 B (0%)

Total Size: 1.13 MB

Filename Size Change
build/components/index.min.js 215 kB +56 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 960 B
build/admin-manifest/index.min.js 1.1 kB
build/annotations/index.min.js 2.75 kB
build/api-fetch/index.min.js 2.21 kB
build/autop/index.min.js 2.12 kB
build/blob/index.min.js 459 B
build/block-directory/index.min.js 6.28 kB
build/block-directory/style-rtl.css 1.01 kB
build/block-directory/style.css 1.01 kB
build/block-editor/default-editor-styles-rtl.css 378 B
build/block-editor/default-editor-styles.css 378 B
build/block-editor/index.min.js 140 kB
build/block-editor/style-rtl.css 14.5 kB
build/block-editor/style.css 14.5 kB
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 65 B
build/block-library/blocks/archives/style.css 65 B
build/block-library/blocks/audio/editor-rtl.css 58 B
build/block-library/blocks/audio/editor.css 58 B
build/block-library/blocks/audio/style-rtl.css 111 B
build/block-library/blocks/audio/style.css 111 B
build/block-library/blocks/audio/theme-rtl.css 125 B
build/block-library/blocks/audio/theme.css 125 B
build/block-library/blocks/block/editor-rtl.css 161 B
build/block-library/blocks/block/editor.css 161 B
build/block-library/blocks/button/editor-rtl.css 470 B
build/block-library/blocks/button/editor.css 470 B
build/block-library/blocks/button/style-rtl.css 560 B
build/block-library/blocks/button/style.css 560 B
build/block-library/blocks/buttons/editor-rtl.css 291 B
build/block-library/blocks/buttons/editor.css 291 B
build/block-library/blocks/buttons/style-rtl.css 275 B
build/block-library/blocks/buttons/style.css 275 B
build/block-library/blocks/calendar/style-rtl.css 207 B
build/block-library/blocks/calendar/style.css 207 B
build/block-library/blocks/categories/editor-rtl.css 84 B
build/block-library/blocks/categories/editor.css 83 B
build/block-library/blocks/categories/style-rtl.css 79 B
build/block-library/blocks/categories/style.css 79 B
build/block-library/blocks/code/style-rtl.css 90 B
build/block-library/blocks/code/style.css 90 B
build/block-library/blocks/code/theme-rtl.css 134 B
build/block-library/blocks/code/theme.css 134 B
build/block-library/blocks/columns/editor-rtl.css 210 B
build/block-library/blocks/columns/editor.css 208 B
build/block-library/blocks/columns/style-rtl.css 503 B
build/block-library/blocks/columns/style.css 502 B
build/block-library/blocks/comment-template/style-rtl.css 127 B
build/block-library/blocks/comment-template/style.css 127 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 123 B
build/block-library/blocks/comments-pagination-numbers/editor.css 121 B
build/block-library/blocks/comments-pagination/editor-rtl.css 222 B
build/block-library/blocks/comments-pagination/editor.css 209 B
build/block-library/blocks/comments-pagination/style-rtl.css 235 B
build/block-library/blocks/comments-pagination/style.css 231 B
build/block-library/blocks/cover/editor-rtl.css 546 B
build/block-library/blocks/cover/editor.css 547 B
build/block-library/blocks/cover/style-rtl.css 1.22 kB
build/block-library/blocks/cover/style.css 1.22 kB
build/block-library/blocks/embed/editor-rtl.css 488 B
build/block-library/blocks/embed/editor.css 488 B
build/block-library/blocks/embed/style-rtl.css 417 B
build/block-library/blocks/embed/style.css 417 B
build/block-library/blocks/embed/theme-rtl.css 124 B
build/block-library/blocks/embed/theme.css 124 B
build/block-library/blocks/file/editor-rtl.css 300 B
build/block-library/blocks/file/editor.css 300 B
build/block-library/blocks/file/style-rtl.css 255 B
build/block-library/blocks/file/style.css 255 B
build/block-library/blocks/file/view.min.js 322 B
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB
build/block-library/blocks/freeform/editor.css 2.44 kB
build/block-library/blocks/gallery/editor-rtl.css 966 B
build/block-library/blocks/gallery/editor.css 970 B
build/block-library/blocks/gallery/style-rtl.css 1.63 kB
build/block-library/blocks/gallery/style.css 1.62 kB
build/block-library/blocks/gallery/theme-rtl.css 122 B
build/block-library/blocks/gallery/theme.css 122 B
build/block-library/blocks/group/editor-rtl.css 159 B
build/block-library/blocks/group/editor.css 159 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 B
build/block-library/blocks/group/theme-rtl.css 78 B
build/block-library/blocks/group/theme.css 78 B
build/block-library/blocks/heading/style-rtl.css 114 B
build/block-library/blocks/heading/style.css 114 B
build/block-library/blocks/html/editor-rtl.css 332 B
build/block-library/blocks/html/editor.css 333 B
build/block-library/blocks/image/editor-rtl.css 810 B
build/block-library/blocks/image/editor.css 809 B
build/block-library/blocks/image/style-rtl.css 507 B
build/block-library/blocks/image/style.css 511 B
build/block-library/blocks/image/theme-rtl.css 124 B
build/block-library/blocks/image/theme.css 124 B
build/block-library/blocks/latest-comments/style-rtl.css 284 B
build/block-library/blocks/latest-comments/style.css 284 B
build/block-library/blocks/latest-posts/editor-rtl.css 137 B
build/block-library/blocks/latest-posts/editor.css 137 B
build/block-library/blocks/latest-posts/style-rtl.css 528 B
build/block-library/blocks/latest-posts/style.css 527 B
build/block-library/blocks/list/style-rtl.css 94 B
build/block-library/blocks/list/style.css 94 B
build/block-library/blocks/media-text/editor-rtl.css 266 B
build/block-library/blocks/media-text/editor.css 263 B
build/block-library/blocks/media-text/style-rtl.css 493 B
build/block-library/blocks/media-text/style.css 490 B
build/block-library/blocks/more/editor-rtl.css 431 B
build/block-library/blocks/more/editor.css 431 B
build/block-library/blocks/navigation-link/editor-rtl.css 649 B
build/block-library/blocks/navigation-link/editor.css 650 B
build/block-library/blocks/navigation-link/style-rtl.css 94 B
build/block-library/blocks/navigation-link/style.css 94 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 299 B
build/block-library/blocks/navigation-submenu/editor.css 299 B
build/block-library/blocks/navigation-submenu/view.min.js 343 B
build/block-library/blocks/navigation/editor-rtl.css 1.91 kB
build/block-library/blocks/navigation/editor.css 1.91 kB
build/block-library/blocks/navigation/style-rtl.css 1.71 kB
build/block-library/blocks/navigation/style.css 1.7 kB
build/block-library/blocks/navigation/view.min.js 2.79 kB
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 377 B
build/block-library/blocks/page-list/editor.css 377 B
build/block-library/blocks/page-list/style-rtl.css 172 B
build/block-library/blocks/page-list/style.css 172 B
build/block-library/blocks/paragraph/editor-rtl.css 157 B
build/block-library/blocks/paragraph/editor.css 157 B
build/block-library/blocks/paragraph/style-rtl.css 273 B
build/block-library/blocks/paragraph/style.css 273 B
build/block-library/blocks/post-author/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/style-rtl.css 446 B
build/block-library/blocks/post-comments-form/style.css 446 B
build/block-library/blocks/post-comments/style-rtl.css 507 B
build/block-library/blocks/post-comments/style.css 507 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B
build/block-library/blocks/post-excerpt/editor.css 73 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B
build/block-library/blocks/post-excerpt/style.css 69 B
build/block-library/blocks/post-featured-image/editor-rtl.css 721 B
build/block-library/blocks/post-featured-image/editor.css 721 B
build/block-library/blocks/post-featured-image/style-rtl.css 153 B
build/block-library/blocks/post-featured-image/style.css 153 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 391 B
build/block-library/blocks/post-template/style.css 392 B
build/block-library/blocks/post-terms/style-rtl.css 73 B
build/block-library/blocks/post-terms/style.css 73 B
build/block-library/blocks/post-title/style-rtl.css 80 B
build/block-library/blocks/post-title/style.css 80 B
build/block-library/blocks/preformatted/style-rtl.css 103 B
build/block-library/blocks/preformatted/style.css 103 B
build/block-library/blocks/pullquote/editor-rtl.css 198 B
build/block-library/blocks/pullquote/editor.css 198 B
build/block-library/blocks/pullquote/style-rtl.css 389 B
build/block-library/blocks/pullquote/style.css 388 B
build/block-library/blocks/pullquote/theme-rtl.css 167 B
build/block-library/blocks/pullquote/theme.css 167 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 221 B
build/block-library/blocks/query-pagination/editor.css 211 B
build/block-library/blocks/query-pagination/style-rtl.css 273 B
build/block-library/blocks/query-pagination/style.css 269 B
build/block-library/blocks/query/editor-rtl.css 131 B
build/block-library/blocks/query/editor.css 132 B
build/block-library/blocks/quote/style-rtl.css 187 B
build/block-library/blocks/quote/style.css 187 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/rss/editor-rtl.css 202 B
build/block-library/blocks/rss/editor.css 204 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 165 B
build/block-library/blocks/search/editor.css 165 B
build/block-library/blocks/search/style-rtl.css 397 B
build/block-library/blocks/search/style.css 398 B
build/block-library/blocks/search/theme-rtl.css 64 B
build/block-library/blocks/search/theme.css 64 B
build/block-library/blocks/separator/editor-rtl.css 99 B
build/block-library/blocks/separator/editor.css 99 B
build/block-library/blocks/separator/style-rtl.css 245 B
build/block-library/blocks/separator/style.css 245 B
build/block-library/blocks/separator/theme-rtl.css 172 B
build/block-library/blocks/separator/theme.css 172 B
build/block-library/blocks/shortcode/editor-rtl.css 474 B
build/block-library/blocks/shortcode/editor.css 474 B
build/block-library/blocks/site-logo/editor-rtl.css 772 B
build/block-library/blocks/site-logo/editor.css 772 B
build/block-library/blocks/site-logo/style-rtl.css 165 B
build/block-library/blocks/site-logo/style.css 165 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 84 B
build/block-library/blocks/site-title/editor.css 84 B
build/block-library/blocks/social-link/editor-rtl.css 177 B
build/block-library/blocks/social-link/editor.css 177 B
build/block-library/blocks/social-links/editor-rtl.css 670 B
build/block-library/blocks/social-links/editor.css 669 B
build/block-library/blocks/social-links/style-rtl.css 1.32 kB
build/block-library/blocks/social-links/style.css 1.32 kB
build/block-library/blocks/spacer/editor-rtl.css 307 B
build/block-library/blocks/spacer/editor.css 307 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 471 B
build/block-library/blocks/table/editor.css 472 B
build/block-library/blocks/table/style-rtl.css 481 B
build/block-library/blocks/table/style.css 481 B
build/block-library/blocks/table/theme-rtl.css 188 B
build/block-library/blocks/table/theme.css 188 B
build/block-library/blocks/tag-cloud/style-rtl.css 146 B
build/block-library/blocks/tag-cloud/style.css 146 B
build/block-library/blocks/template-part/editor-rtl.css 560 B
build/block-library/blocks/template-part/editor.css 559 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 87 B
build/block-library/blocks/verse/style.css 87 B
build/block-library/blocks/video/editor-rtl.css 569 B
build/block-library/blocks/video/editor.css 570 B
build/block-library/blocks/video/style-rtl.css 173 B
build/block-library/blocks/video/style.css 173 B
build/block-library/blocks/video/theme-rtl.css 124 B
build/block-library/blocks/video/theme.css 124 B
build/block-library/common-rtl.css 857 B
build/block-library/common.css 856 B
build/block-library/editor-rtl.css 10 kB
build/block-library/editor.css 10 kB
build/block-library/index.min.js 163 kB
build/block-library/reset-rtl.css 474 B
build/block-library/reset.css 474 B
build/block-library/style-rtl.css 10.8 kB
build/block-library/style.css 10.8 kB
build/block-library/theme-rtl.css 672 B
build/block-library/theme.css 677 B
build/block-serialization-default-parser/index.min.js 1.09 kB
build/block-serialization-spec-parser/index.min.js 2.79 kB
build/blocks/index.min.js 46.3 kB
build/components/style-rtl.css 15.5 kB
build/components/style.css 15.5 kB
build/compose/index.min.js 10.9 kB
build/core-data/index.min.js 13.2 kB
build/customize-widgets/index.min.js 11.4 kB
build/customize-widgets/style-rtl.css 1.5 kB
build/customize-widgets/style.css 1.49 kB
build/data-controls/index.min.js 631 B
build/data/index.min.js 7.49 kB
build/date/index.min.js 31.9 kB
build/deprecated/index.min.js 485 B
build/dom-ready/index.min.js 304 B
build/dom/index.min.js 4.5 kB
build/edit-navigation/index.min.js 16 kB
build/edit-navigation/style-rtl.css 3.76 kB
build/edit-navigation/style.css 3.76 kB
build/edit-post/classic-rtl.css 492 B
build/edit-post/classic.css 494 B
build/edit-post/index.min.js 29.4 kB
build/edit-post/style-rtl.css 7.1 kB
build/edit-post/style.css 7.09 kB
build/edit-site/index.min.js 35.5 kB
build/edit-site/style-rtl.css 6.63 kB
build/edit-site/style.css 6.63 kB
build/edit-widgets/index.min.js 16.5 kB
build/edit-widgets/style-rtl.css 4.18 kB
build/edit-widgets/style.css 4.18 kB
build/editor/index.min.js 37.9 kB
build/editor/style-rtl.css 3.78 kB
build/editor/style.css 3.77 kB
build/element/index.min.js 3.29 kB
build/escape-html/index.min.js 517 B
build/format-library/index.min.js 6.58 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.63 kB
build/html-entities/index.min.js 424 B
build/i18n/index.min.js 3.71 kB
build/is-shallow-equal/index.min.js 501 B
build/keyboard-shortcuts/index.min.js 1.8 kB
build/keycodes/index.min.js 1.39 kB
build/list-reusable-blocks/index.min.js 1.72 kB
build/list-reusable-blocks/style-rtl.css 838 B
build/list-reusable-blocks/style.css 838 B
build/media-utils/index.min.js 2.92 kB
build/notices/index.min.js 925 B
build/nux/index.min.js 2.08 kB
build/nux/style-rtl.css 747 B
build/nux/style.css 743 B
build/plugins/index.min.js 1.84 kB
build/primitives/index.min.js 924 B
build/priority-queue/index.min.js 582 B
build/react-i18n/index.min.js 671 B
build/react-refresh-entry/index.min.js 8.44 kB
build/react-refresh-runtime/index.min.js 7.31 kB
build/redux-routine/index.min.js 2.65 kB
build/reusable-blocks/index.min.js 2.22 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 11 kB
build/server-side-render/index.min.js 1.57 kB
build/shortcode/index.min.js 1.49 kB
build/token-list/index.min.js 639 B
build/url/index.min.js 1.9 kB
build/viewport/index.min.js 1.05 kB
build/warning/index.min.js 248 B
build/widgets/index.min.js 7.15 kB
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.04 kB

compressed-size-action

@oandregal
Copy link
Member

Nice! Do we want to provide a default alias for the font sizes declared in Gutenberg's (and core's) theme.json here? I think that'd be a good way to highlight how it can be used.

@ntsekouras
Copy link
Contributor Author

Do we want to provide a default alias for the font sizes declared in Gutenberg's (and core's) theme.json here? I think that'd be a good way to highlight how it can be used.

If we go with the approach to use it only when complex css values are available (see PR's description), there is no need to add alias there as there are only simple css values declared.

@oandregal
Copy link
Member

If we go with the approach to use it only when complex css values are available (see PR's description), there is no need to add alias there as there are only simple css values declared.

Oh, interesting. If the design intention is to show numbers in the segmented control, what if we only allowed numbers in the alias field? The advantage would be that the data the users see is always consistent (numbers) no matter how the theme is set up internally.

Copy link
Contributor

@ciampo ciampo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ntsekouras , thank you for opening this PR!

  • Should we add some unit tests and a Storybook example for this scenario?
  • Would you be able to also add a CHANGELOG entry?

Oh, interesting. If the design intention is to show numbers in the segmented control, what if we only allowed numbers in the alias field? The advantage would be that the data the users see is always consistent (numbers) no matter how the theme is set up internally.

I think that allowing numbers as aliases would create confusion, since the main reason why we need these aliases in the first place is because they need to represent "dynamic" values.

const fontSizesContainComplexValues = fontSizes.some(
( { size } ) => ! isSimpleCssValue( size )
);
const allFontSizesHaveAliases = fontSizes.every(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a though — I wonder if the decision to display an alias should be made for each "font size" independently — i.e.:

  • There are more than 6 presets? Display a select control
  • Less than 6 presets:
    • Display a select control only if at least one font size is not a simple control, and doesn't have an alias either
    • Otherwise, display a toggle group

This mean that, as far as all "complex" values are paired with an alias, we should be able to show a toggle group

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marco's suggestion here matches the preconceived notion I had of how this would work before I read the PR description.

My thinking was that the alias would act as an override or fallback. Something for theme authors to provide when we can't determine a sensible value from the font size.

I can also see the other angle where this could lead to an inconsistent UI. A theme author adds aliases such as XL for complex values but omits aliases for simple ones, resulting in a mixture of numeric and string labels in the segmented control. A similar situation could arise if we wished to use the aliases for hints within the select control.

If we made the decision to display aliases at the individual font size level, it might alleviate the need to plumb through shouldUseAliases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the decision to display an alias should be made for each "font size" independently

I agree with Aaron:

where this could lead to an inconsistent UI. A theme author adds aliases such as XL for complex values but omits aliases for simple ones, resulting in a mixture of numeric and string labels in the segmented control.

Comment on lines 67 to 68
const shouldUseAliases =
fontSizesContainComplexValues && allFontSizesHaveAliases;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if a font size is a "simple" value, but has an associated alias? Should the alias take the precedence?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the initial design with the intention of showing numeric values, I'd say no..

Copy link
Contributor

@aaronrobertshaw aaronrobertshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice @ntsekouras

This tests as advertised for me in both the Storybook and Block Editor. The knobs in the story to automate updating the font size configuration are a nice touch, thanks 👍.

In general, the alias approach looks like a good step forward and might only need a few tweaks as proposed by others.

@@ -65,10 +65,11 @@ If no value exists, this prop defines the starting position for the font size pi

### fontSizes

An array of font size objects. The object should contain properties size, name, and slug.
An array of font size objects. The object should contain properties `size`, `name`, `slug` and can contain `alias` on special use cases described right below.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to ignore this suggestion. It's my attempt to make this read a little better, so it's completely subjective.

Suggested change
An array of font size objects. The object should contain properties `size`, `name`, `slug` and can contain `alias` on special use cases described right below.
An array of font size objects. Each object should contain the properties `size`, `name`, and `slug`. Optionally, `alias` can be included for special use cases as described below.

const fontSizesContainComplexValues = fontSizes.some(
( { size } ) => ! isSimpleCssValue( size )
);
const allFontSizesHaveAliases = fontSizes.every(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marco's suggestion here matches the preconceived notion I had of how this would work before I read the PR description.

My thinking was that the alias would act as an override or fallback. Something for theme authors to provide when we can't determine a sensible value from the font size.

I can also see the other angle where this could lead to an inconsistent UI. A theme author adds aliases such as XL for complex values but omits aliases for simple ones, resulting in a mixture of numeric and string labels in the segmented control. A similar situation could arise if we wished to use the aliases for hints within the select control.

If we made the decision to display aliases at the individual font size level, it might alleviate the need to plumb through shouldUseAliases.

@oandregal
Copy link
Member

I'm preparing the corresponding PR for wp-cli (i18n command) at wp-cli/i18n-command#292

@oandregal
Copy link
Member

I think that allowing numbers as aliases would create confusion, since the main reason why we need these aliases in the first place is because they need to represent "dynamic" values.

I see. I'm still trying to wrap my head around the design direction for this component, so bear with me :) The thought I'm struggling with is that this component displays data differently depending on the theme's internal implementation: sometimes numbers and sometimes letters. It'd be great if we could find a way to show the same type of data. Of course, not a blocker for this PR.

@oandregal
Copy link
Member

If we can land this one quick and then polish the details it'd be helpful to help us land the corresponding wp-cli PR wp-cli/i18n-command#292 (we shouldn't merge that one until this direction is confirmed and merged).

@jasmussen
Copy link
Contributor

jasmussen commented Dec 2, 2021

Thanks for the PR! I'll share some more high level thoughts, that can hopefully be helpful.

What we want to avoid is this:

presets

With only 5 sizes defined, a segmented control would be a much more immediate and convenient control.

Going back to this design and this clarification, it seems like the best path forward is:

  1. If we have basic values (px), show numbers.
  2. If we don't have basic values, show preset size values, S/M/L/XL/XXL.

2 is where it gets difficult. Here's what TT2 offers:

{
	"name": "Small",
	"size": "1rem",
	"slug": "small"
},
{
	"name": "Normal",
	"size": "1.125rem",
	"slug": "normal"
},
{
	"name": "Medium",
	"size": "1.75rem",
	"slug": "medium"
},
{
	"name": "Large",
	"size": "clamp(1.75rem, 3vw, 2.25rem)",
	"slug": "large"
},
{
	"name": "Huge",
	"size": "clamp(2.5rem, 4vw, 3rem)",
	"slug": "huge"
}

On the one hand TT2 might be bordering on too clever with the clamp based values, at the same time: themes can do this, so they will. But we still can't extract numbers from that, at best we'd end up here:

1   1.125    1.75    2.25    3

Those aren't helpful indicators, and might even wrap onto multiple lines.

Question: can we try to force T-shirt sizes, S/M/L/XL/XXL, in sequence? First defined value is "S", 5th define value is "XXL"?

Adding the explicit alias feels like letting the genie out of the bottle, allowing theme authors to add long aliases that cause a segmented control to wrap. Ultimately it might be what we need to do, but it would be nice to first see if the predefined values could work. What do you think?

@ntsekouras
Copy link
Contributor Author

Thanks all the reviews and help here! ❤️

Should we add some unit tests and a Storybook example for this scenario?

@ciampo there is a story for this. Regarding the unit tests, did you have something specific in mind like for taking a snapshot of the rendered html?

Would you be able to also add a CHANGELOG entry?

That will be added yes.

Question: can we try to force T-shirt sizes, S/M/L/XL/XXL, in sequence? First defined value is "S", 5th define value is "XXL"?

Probably no, because even if this should be the right declaration order (smaller->bigger) this is up to the theme and that order is not guaranteed.

Adding the explicit alias feels like letting the genie out of the bottle, allowing theme authors to add long aliases that cause a segmented control to wrap. Ultimately it might be what we need to do, but it would be nice to first see if the predefined values could work. What do you think?

Actually there could be a simpler alternative, not so flexible but then again this PR accommodates more complex use cases from theme developers, who know what they are doing, and also handles the twenty twenty two use case. The approach would be:

  1. If we have at most five font sizes (like now)
  2. If there is at least on complex css value
  3. Extract the first letter of the font sizes (with any necessary extra small checks like no duplicates etc..)

Pros:

  1. No extra property that is used conditionally based on the implementation details
  2. Reduce confusion about when/where the alias should be added

Cons:

  1. Not being able to explicitly set an alias to achieve something like this huge->XL (IMO not a big deal).

I think it's probably better to loose the alias after all, and either go with a first letter(s) approach or even the T-shirt sizes approach from Joen.

What do you think?

@jasmussen
Copy link
Contributor

Extract the first letter of the font sizes (with any necessary extra small checks like no duplicates etc..)

So if I had Small/Normal/Medium/Large/Huge it'd be something like this?

S   N   M   L   H

While I like the idea of starting with simple automation before adding any additional JSON properties, I can't help but feel like those letters don't translate well to sizes in the same way the T-shirt labels do. I understand that a fixed sequence isn't going to be accurate if a developer decides to start with Large as the first one, or even mix and match. That that doesn't seem like a use case to optimize for.

This is not a very strong opinion, but to keep things simple, I'd start with numbers and t-shirt sizes, and then revisit the t-shirt sizes if the fixed sequence turns out to be a problem in practice.

@kjellr
Copy link
Contributor

kjellr commented Dec 2, 2021

For the case of Twenty Twenty-Two, we can change those names to something else if necessary — we were just borrowing the names from Gutenberg when we named those.

@ntsekouras ntsekouras force-pushed the try/add-font-sizes-alias branch from 67558bb to 48fefb5 Compare December 3, 2021 07:01
@kjellr
Copy link
Contributor

kjellr commented Dec 14, 2021

I think we can create a separate issue for the font sizes changes - I'd appreciate it so much if @oandregal or @kjellr did that for explaining the issue in the best possible way.

Sure, I'll open that issue today.

Edit: Done here: #37378

@oandregal
Copy link
Member

oandregal commented Dec 14, 2021

Got an initial PR to update the default font sizes at #37381 I'd appreciate heavy testing to make sure that by doing this, we don't introduce any regressions for normal & huge classes/variables.

Edit: also, I presume we want to update the default font-sizes in 5.9?

@noisysocks noisysocks added the [Priority] High Used to indicate top priority items that need quick attention label Dec 15, 2021
@ntsekouras ntsekouras force-pushed the try/add-font-sizes-alias branch from be498f4 to 897948d Compare December 15, 2021 08:01
@ntsekouras
Copy link
Contributor Author

I just rebased and with a green CI, I'm going to merge this. The next PR to be merged is the one that changes the core presets and that will only leaves a PR that I'll start today for the below:

We supply some default values (as we do today) for four presets. Themes can customize them just by referencing the slug / type.

  • Let's skip the need for themes to provide any sort of name or alias if they want to support the common array.
  • We start with small, medium, large, x-large slugs that themes can supply presets for. (We still support previous enqueues as needed, nothing should break.)

Noting that we will also need the PR from @kjellr to change TwentyTwentyTwo

@ntsekouras ntsekouras changed the title [Components - FontSizePicker]: Add T-shirt aliases to segmented control (conditionally) [Components - FontSizePicker]: Use incremental sequence of numbers as labels for the available font-sizes at the segmented control (conditionally) Dec 15, 2021
@ntsekouras ntsekouras merged commit aac3e86 into trunk Dec 15, 2021
@ntsekouras ntsekouras deleted the try/add-font-sizes-alias branch December 15, 2021 08:48
@github-actions github-actions bot added this to the Gutenberg 12.2 milestone Dec 15, 2021
@mtias
Copy link
Member

mtias commented Dec 15, 2021

Thanks for all the work here, @ntsekouras !

@tellthemachines tellthemachines removed the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Dec 20, 2021
tellthemachines pushed a commit that referenced this pull request Dec 21, 2021
… labels for the available font-sizes at the segmented control (conditionally) (#37038)

* [Components - FontSizePicker]: Add alias option in font sizes

* use `T-shirt` sizes

* add changelog entry

* add unit tests

* use incremental sequence of numbers as labels
noisysocks added a commit that referenced this pull request Jan 4, 2022
…mbers as labels for the available font-sizes at the segmented control (conditionally) (#37038)"

This reverts commit f98ff05.
noisysocks pushed a commit that referenced this pull request Jan 4, 2022
… labels for the available font-sizes at the segmented control (conditionally) (#37038)

* [Components - FontSizePicker]: Add alias option in font sizes

* use `T-shirt` sizes

* add changelog entry

* add unit tests

* use incremental sequence of numbers as labels
@scruffian
Copy link
Contributor

Themes can add new ones beyond 5 and they get the dropdown selector.

The problem with this is that if themes don't follow a standard naming convention, when users switch themes, the additional font-sizes will break. I think it would be good to standardize on a naming convention all themes can use so that if themes do want to add more they will be persisted across themes.

@ntsekouras
Copy link
Contributor Author

The problem with this is that if themes don't follow a standard naming convention, when users switch themes, the additional font-sizes will break.

Wasn't this the case before too? I guess it's the same thing with theme's presets of colors, etc.., no?

@scruffian
Copy link
Contributor

Yes, it was the case before this change and is also an issue with colors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Priority] High Used to indicate top priority items that need quick attention
Projects
None yet
Development

Successfully merging this pull request may close these issues.