Skip to content

Conversation

@oandregal
Copy link
Member

@oandregal oandregal commented Jun 15, 2020

Implements #23111

This PR adds a new preset for line-height that themes can use similar to how they use colors, font-sizes, and gradients. It also adds the ability to reset user-defined values.

UI footprint

2006-16-line-height-control

Interaction

2006-16-line-height-control

Test

  • Using TwentyTwenty (or any other theme that doesn't opt-out from this), make sure that the controls work as expected and the values are the defaults.
  • Using a theme that adds line-height presets (you can use this demo theme https://github.com/nosolosw/global-styles-theme/pull/11), make sure the controls work as expected and the values are the ones added by the theme (for the demo theme, they'll be "Tight", "Normal", "Breathe").

Follow-ups

@oandregal oandregal self-assigned this Jun 15, 2020
@oandregal oandregal added [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Enhancement A suggestion for improvement. labels Jun 15, 2020
@oandregal oandregal requested a review from ItsJonQ June 15, 2020 17:55
@oandregal oandregal changed the title Add/preset line height Add preset for line-height and use it in the UI controls Jun 15, 2020
@github-actions
Copy link

github-actions bot commented Jun 15, 2020

Size Change: +313 B (0%)

Total Size: 1.12 MB

Filename Size Change
build/block-editor/index.js 106 kB +155 B (0%)
build/block-editor/style-rtl.css 10.8 kB +77 B (0%)
build/block-editor/style.css 10.8 kB +75 B (0%)
build/editor/index.js 44.8 kB +6 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.62 kB 0 B
build/api-fetch/index.js 3.4 kB 0 B
build/autop/index.js 2.83 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 7.27 kB 0 B
build/block-directory/style-rtl.css 955 B 0 B
build/block-directory/style.css 955 B 0 B
build/block-library/editor-rtl.css 7.85 kB 0 B
build/block-library/editor.css 7.86 kB 0 B
build/block-library/index.js 129 kB 0 B
build/block-library/style-rtl.css 8.02 kB 0 B
build/block-library/style.css 8.02 kB 0 B
build/block-library/theme-rtl.css 749 B 0 B
build/block-library/theme.css 751 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 48.1 kB 0 B
build/components/index.js 195 kB 0 B
build/components/style-rtl.css 15.9 kB 0 B
build/components/style.css 15.9 kB 0 B
build/compose/index.js 9.6 kB 0 B
build/core-data/index.js 11.4 kB 0 B
build/data-controls/index.js 1.29 kB 0 B
build/data/index.js 8.45 kB 0 B
build/date/index.js 5.47 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 3.17 kB 0 B
build/edit-navigation/index.js 8.26 kB 0 B
build/edit-navigation/style-rtl.css 1.04 kB 0 B
build/edit-navigation/style.css 1.04 kB 0 B
build/edit-post/index.js 303 kB 0 B
build/edit-post/style-rtl.css 5.6 kB 0 B
build/edit-post/style.css 5.6 kB 0 B
build/edit-site/index.js 16.6 kB 0 B
build/edit-site/style-rtl.css 3.13 kB 0 B
build/edit-site/style.css 3.13 kB 0 B
build/edit-widgets/index.js 9.33 kB 0 B
build/edit-widgets/style-rtl.css 2.54 kB 0 B
build/edit-widgets/style.css 2.54 kB 0 B
build/editor/editor-styles-rtl.css 486 B 0 B
build/editor/editor-styles.css 487 B 0 B
build/editor/style-rtl.css 3.82 kB 0 B
build/editor/style.css 3.82 kB 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 7.72 kB 0 B
build/format-library/style-rtl.css 561 B 0 B
build/format-library/style.css 562 B 0 B
build/hooks/index.js 2.13 kB 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/is-shallow-equal/index.js 710 B 0 B
build/keyboard-shortcuts/index.js 2.51 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.13 kB 0 B
build/list-reusable-blocks/style-rtl.css 537 B 0 B
build/list-reusable-blocks/style.css 537 B 0 B
build/media-utils/index.js 5.29 kB 0 B
build/notices/index.js 1.79 kB 0 B
build/nux/index.js 3.4 kB 0 B
build/nux/style-rtl.css 681 B 0 B
build/nux/style.css 676 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/primitives/index.js 1.5 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/rich-text/index.js 14 kB 0 B
build/server-side-render/index.js 2.68 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.28 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.85 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@oandregal oandregal added the [Status] In Progress Tracking issues with work in progress label Jun 16, 2020
{ slug: 'full', name: __( 'Full Size' ) },
],

lineHeight: [
Copy link
Member Author

Choose a reason for hiding this comment

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

If the theme doesn't provide any, which defaults do we want here?

Copy link
Member Author

Choose a reason for hiding this comment

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

@jasmussen @kjellr @mapk this PR implements presets for line-height, as per #23111 I was wondering if you had any suggestions for line-height defaults.

Copy link
Contributor

@MichaelArestad MichaelArestad Jun 17, 2020

Choose a reason for hiding this comment

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

EDIT: I see what you mean by default. I would go with:

small: 1 - will be the height of the text. If you make it smaller, weird things can happen when wrapping or next to other text.
regular: 1.2 - nice
large: 1.5 or 1.6 work well.

Will users be able to set a custom value as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I would make sure those values are unitless if they aren't already: line-height: 1.2;

const { keyCode } = event;

if ( keyCode === ZERO && ! isDefined ) {
if ( keyCode === ZERO ) {
Copy link
Member Author

Choose a reason for hiding this comment

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

What this code does is that when the user types a 0, the whole line-height value is reset to 0. This is a nice little detail! However, I also wonder: this is preventing the user from introducing any value that includes a 0, as it'll be reset. Examples of values a user is not able to introduce: "10", "1.05", etc. Unless there's something that I'm missing I presume this restriction should be removed.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ItsJonQ what do you think of this? can we remove this logic?

Copy link

Choose a reason for hiding this comment

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

I believe so!! We'll be able to remove the manual keyDown handling once we migrate to using <NumberControl />

Copy link
Member Author

Choose a reason for hiding this comment

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

So I've removed the existing handleOnKeyDown logic in 98b1468 and this seems to work fine for me as it is. At least I don't know how to break it! This is what I tried: click the arrow up/down, keyboard interactions (both starting with an existing value and with no value).

@oandregal oandregal removed the [Status] In Progress Tracking issues with work in progress label Jun 16, 2020
@oandregal oandregal marked this pull request as ready for review June 16, 2020 12:16
Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

How does the preset gets applied? Inline style, class, CSS variables?

Should we use the last one (CSS vars) as it seems like the approach we want to ultimately adopt for all presets?

* @return array Filtered editor settings.
*/
function gutenberg_add_line_height_presets( $settings ) {
list( $editor_line_height ) = (array) get_theme_support( 'editor-line-height' );
Copy link
Contributor

Choose a reason for hiding this comment

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

do you think we should add new theme support or just rely on theme.json?

My opinion for the moment is that we should stop adding new theme supports and focus on making theme.json good enough.

Copy link
Member Author

Choose a reason for hiding this comment

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

I like the sound of what you say, however, I worry about what we'll ship to WordPress 5.5 -- once there, it's difficult to change. For context, this is the full picture of style attributes:

Style prop Status Opt-in / Opt-out How it works What presets it uses
Existing styles (font-size, color, gradient). Released to core, stable. Opt-out via disable-custom-{preset-name} Presets: classes / Custom: inline styles with raw values Each style prop defines its own preset.
line-height Plugin-only, stable. Opt-out via disable-custom-line-height Presets & Custom: inline styles with raw values None yet (this PR adds line-height presets).
padding Plugin-only, experimental. Opt-in via experimental-custom-spacing Presets & Custom: inline styles with raw values. None yet. WIP at #23176
units (for padding) Plugin-only, experimental. Opt-in via experimental-custom-units N/A N/A
link color Plugin-only, experimental. Opt-in via experimental-link-color Presets: inline styles with css variables / Custom: inline styles with raw values Uses color's preset.

I'd be open to not adding presets for padding via the conventional mechanism (add_theme_support) because it's experimental, but, unfortunately, I think we need to add them for line-height so themes can add their own.

Copy link
Member Author

@oandregal oandregal Jun 16, 2020

Choose a reason for hiding this comment

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

Also for context! I only have a bit more than a week of work before 5.5 beta and my goals are: 1) adding presets for line-height & padding, 2) consolidating the way style attributes are stored in the markup, 3) prepare core patches.

For 2, I wanted to engage you and @ItsJonQ in a convo after this PR. The link color mechanism (always inline styles: CSS vars for presets, raw values for custom) works for how we use it today, and gives us a nice method to tweak the values. However, I'm concerned about how that would work for the color status (visited, active, hover). I don't see how we can implement them using inline styles (I had this convo with Jorge as well).

Copy link
Member Author

Choose a reason for hiding this comment

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

efe4c26 exposes the line-height preset as CSS variables like the rest of preset categories do.

Copy link

@ItsJonQ ItsJonQ left a comment

Choose a reason for hiding this comment

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

🎉 @nosolosw Thanks for working on this! It looks good to me :)

I think a good (near) future enhancement would be to replace the <TextControl /> with <NumberControl />. NumberControl should take care of a lot of intricate interactions as well as value parsing/handling. Some of the logic that was refactored in this PR (that you pointed out) attempted to do some of these things with <TextControl />.

Maybe we can do this with the FontSize controls as well :)

(For the future! For now, this PR is 👍 !)

@oandregal oandregal added the Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json label Jun 16, 2020
oandregal added a commit that referenced this pull request Jun 16, 2020
@oandregal oandregal force-pushed the add/preset-line-height branch from 98b1468 to ddf1c2f Compare June 17, 2020 08:00
oandregal added a commit that referenced this pull request Jun 17, 2020
@oandregal oandregal force-pushed the add/preset-line-height branch from ddf1c2f to 735ff9b Compare June 17, 2020 12:41
}
],
"line-height": [
{ "slug": "small", "value": 0.8 },
Copy link
Member

Choose a reason for hiding this comment

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

Labels are missing, it will become an issue sooner than later.

@jasmussen
Copy link
Contributor

Thank you for your work, this is really cool.

In looking at this, I'm reminded that the design tools are going to multiply many-fold and eventually take up a great deal of space in the sidebar. Even with just two controls, we're up to a lot:

Screenshot 2020-06-18 at 09 14 14

I've worked a bit with Q on some mockups for design tool improvements, that emphasize compactness so as to actually fit multiple:

Padding control, icon only

Here's a mockup showing only color and spacing controls in the sidebar, and I've done my best to make it compact — and even here, it takes up a ton of space:

Color controls, opens inline

While we can probably ship with the preset as is, as it mimics the font size field, we should start to think about what we can do to compactify these things.

Common to all the design tools I've sketched for Q so far, is that they all take up exactly 36px height in a horizontal line, or 72px if they are "big", like the expanded spacing controls. I don't love the following, but it's an idea that emphasizes the same collapsing that happens to the color swatches:

Typography

In most editors, I'd seek out a much more traditional layout for these tools, something like

[Times New Roman]
[Regular  ▼]  [18px]

... but the combination of these being mostly theme-controlled presets with the custom input being optional makes it more related to Figma style presets, which has helped inspire these.

I would love your thoughts on this as a general pattern, before we move too fast. And nice work Andrés!

@oandregal
Copy link
Member Author

While we can probably ship with the preset as is, as it mimics the font size field, we should start to think about what we can do to compactify these things.

Q and I talked yesterday about the padding PR and accomodating presets over there also requires some thought to make it compact. Given that context and the other engineering issues that adding presets require us to do (thread), this is an area best explored with no rush.

I'm going to close the PR to make sure it doesn't get accidentally merged and changing my focus for a bit. We can always reopen if this is a useful first step after 5.5. Please, be welcome to continue the design convo here if it's a useful venue!

@oandregal oandregal closed this Jun 18, 2020
@oandregal oandregal deleted the add/preset-line-height branch June 18, 2020 11:09
@mtias
Copy link
Member

mtias commented Jun 18, 2020

I don't think presets like "small, medium, large" work very well either for most of these controls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants