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

Add a high-level intro to styles in the block editor #38208

Merged
merged 49 commits into from
Feb 3, 2022
Merged

Conversation

oandregal
Copy link
Member

@oandregal oandregal commented Jan 25, 2022

This PR adds a new document to the handbook: a high-level intro to how styles work in the block editor.

It points to the relevant reference guides and tutorials for readers to dig deeper into each one of the ideas presented. It's aimed to block authors and people working in the block editor project. It intentionally tries to avoid block editor jargon and it doesn't presume any knowledge by the reader, other than a familiarity with the block editor and what a block is.

It needs to be complemented with a couple of new tutorials, to be done in separate PRs. Namely, one that explains how to use block supports, both for static and dynamic blocks. Related #38210

Feedback

Read the doc here.

At the moment, I'm particularly interested in hearing what people think of the general structure and the block styles section. Does this work as a general intro? Anything people find missing? I expect further explanations and code deep downs to be developed in the tutorials.

TODO

Follow-up PRs (up for grabs):

  • Find a place for some implementation utils (functions to get styles from attributes in "skip serialization" mode) see comment.
  • Find a place for documenting how "Editor Styles" work and how the theme-provided styles get loaded in the editor. Also: classic.css and reset.css. See comment.

@oandregal oandregal self-assigned this Jan 25, 2022
@oandregal oandregal added [Type] Developer Documentation Documentation for developers CSS Styling Related to editor and front end styles, CSS-specific issues. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi labels Jan 25, 2022
@oandregal oandregal changed the title Add a high-level overview of how styles work in the block editor Add a high-level document of how styles work in the block editor Jan 25, 2022
@oandregal oandregal changed the title Add a high-level document of how styles work in the block editor Add a high-level intro to styles in the block editor Jan 25, 2022
@youknowriad youknowriad self-requested a review January 25, 2022 12:43
@ivan-ottinger
Copy link
Contributor

Thank you for working on the new docs. I appreciate it.

While I cannot officially review this PR (as I don't have the rights to do that), here are a couple of things that came to my mind while reading the proposed text:

  • I like the structure; from a perspective of someone who is just getting into styling blocks, the sections sharing details on Supports API are quite helpful
  • I wonder if it would make sense to add some info on how to approach working with older blocks that don't have block.json available;
  • There are a couple of functions in Gutenberg, e.g. __experimentalGetSpacingClassesAndStyles() that can be helpful when we build custom blocks, but it is not clear if this API is going to stay or not

A couple of tiny typos (in an improvised suggestion markdown :) )

waswere:

- Since the introduction of the block editor in WordPress 5.0, there was tools for the users to "add styles" to specific blocks.
+ Since the introduction of the block editor in WordPress 5.0, there were tools for the users to "add styles" to specific blocks.

Extra the:

- The linked proposal is exploring a different way to serialize the user changes: instead of each block support serializing its own data (for example, classes such as has-small-font-size, has-green-color) the idea is the the block would get a single class instead (for example, wp-style-UUID) and the contents of that class will be generated in the server by WordPress.
+ The linked proposal is exploring a different way to serialize the user changes: instead of each block support serializing its own data (for example, classes such as has-small-font-size, has-green-color) the idea is the block would get a single class instead (for example, wp-style-UUID) and the contents of that class will be generated in the server by WordPress.

And again, thanks so much!


In essence, these are the essential mechanics a block author needs to care about for their block to be able to be styled by the user. While this can be done completely manually, there's an API that automates this process for common style needs: Block Supports.

#### Block Supports API
Copy link
Member Author

@oandregal oandregal Jan 25, 2022

Choose a reason for hiding this comment

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

Sharing feedback I've got privately:

  1. Some folks shared interest in going deep down into how this works: the filters in use, pointing directly to the code where this happens, etc.
  2. Point to the existence of some functions useful in "skip serialization" mode (__experimentalUseColorProps, __experimentalUseBorderProps, __experimentalGetSpacingClassesAndStyles, etc).

I'll incorporate something for the second point directly in this PR.

As for the 1st point. My first instinct was to keep this doc as approachable as possible to block authors, so they don't feel that they need to know how the internals of this API work to implement their blocks. That shouldn't be a requirement. I also understand how that would be useful for core contributors. I'd like to hear thoughts on this, especially from other folks new to this area or that have interacted with this lately.

Copy link
Contributor

Choose a reason for hiding this comment

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

I felt that the "styles" document might not be the right place to expand on how block supports work. Would it be better if in this document block supports are treated just like any "local/serializable" style and just link to their document for block authors that want to know more about them?

Copy link
Contributor

Choose a reason for hiding this comment

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

I read the content here for block supports and it does make a lot of sense and have value but maybe it's better moved to the block supports document itself.

Copy link
Member

Choose a reason for hiding this comment

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

Would it be better if in this document block supports are treated just like any "local/serializable" style and just link to their document for block authors that want to know more about them?

This sounds like a good idea. Block supports are still in development, so the docs might need a roomy home.

It's probably still relevant to this doc to emphasise that many block supports add inline styles to block containers, and that they're rendered to the page with the block.

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 won't add any further to "how block supports" work and the utility functions in use. This can be done in a different PR and probably can go in the block supports docs.

docs/explanations/architecture/styles.md Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Show resolved Hide resolved

In essence, these are the essential mechanics a block author needs to care about for their block to be able to be styled by the user. While this can be done completely manually, there's an API that automates this process for common style needs: Block Supports.

#### Block Supports API
Copy link
Contributor

Choose a reason for hiding this comment

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

I felt that the "styles" document might not be the right place to expand on how block supports work. Would it be better if in this document block supports are treated just like any "local/serializable" style and just link to their document for block authors that want to know more about them?


In essence, these are the essential mechanics a block author needs to care about for their block to be able to be styled by the user. While this can be done completely manually, there's an API that automates this process for common style needs: Block Supports.

#### Block Supports API
Copy link
Contributor

Choose a reason for hiding this comment

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

I read the content here for block supports and it does make a lot of sense and have value but maybe it's better moved to the block supports document itself.

- From UI controls to HTML markup
- Block Supports API
- Current limits of the Block Supports API
3. User-provided Global Styles
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need a chapter about "Editor Styles" and how all these theme provided styles get loaded in the editor as well? (in addition to classic.css and reset.css) or is this specifically about frontend?

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 see this doc as a "map to the main subsystems" someone needs to be aware of, so not about the frontend. I've added a todo task in the issue description to consider this once the global styles section has a draft.

Copy link
Member Author

Choose a reason for hiding this comment

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

Upon re-reading the whole document, I think the v1 doesn't need to cover this.

"How styles are enqueued into the editor" is a whole new topic that needs to cover a lot of ground by itself: add_editor_style(...), add_theme_support('editor-styles'), add_theme_support('wp-block-styles'), reset.css/classic.css, the iframe, add_filter( 'enqueue_block_editor_assets', ...` and probably some other things I've forgotten. Some of this is already mentioned on theme support.

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

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

Thanks for putting this together @oandregal! This reads really well to me, and nicely covers some of the main areas we're hoping to address with the style engine. Thanks for linking through to the relevant issues, too (and nicely articulating the issue of complex blocks like the Table block 🙇).

I hope you don't mind, but I've added a few suggestions, mostly for copy-editing things (typos and grammar), but otherwise it's looking really good to me! (There's a few instances of an before UI that I've switched to ausually if the vowel sounds like a y when read aloud, it should be a).

Since it's documentation, I'd be in favour of seeing what we can get in in the shorter-term and follow up with additions as we need to in follow-up PRs. Also CC: @aaronrobertshaw and @ramonjd for visibility since they've been looking at block supports and style engine things quite a bit recently, too 🙂

docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
@aaronrobertshaw aaronrobertshaw self-requested a review January 27, 2022 05:55
@ramonjd
Copy link
Member

ramonjd commented Jan 27, 2022

This is a fantastic start, thanks for taking the time to document your knowledge on this.

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.

Thank you very much for working on this @oandregal, it is greatly appreciated 👍

I think @andrewserong has covered most of the wording related tweaks that could improve things. So I'll limit my comments below to a couple of clarifications that might help avoid some points of confusion I've seen pop up regularly around the block supports API.

Lastly, the level of knowledge this is being aimed at is great. I think it will be tremendously useful for those starting to look closer in this area. Well done!

docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
@oandregal
Copy link
Member Author

Pushed a draft for the global styles section so we have a first v1 for this document. Would welcome reviews for this new section.

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.

The new section on Global Styles reads well to me 👍

I've left some minor comments and suggestions regarding fixing small typos or tiny improvements to wording.

Thanks again for writing this up. I'm sure it will help lots of people.

docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
@oandregal oandregal marked this pull request as ready for review February 2, 2022 09:22
oandregal and others added 9 commits February 2, 2022 10:22
Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
@oandregal
Copy link
Member Author

Feedback has been incorporated and this is now ready for landing.

Copy link
Contributor

@ntsekouras ntsekouras left a comment

Choose a reason for hiding this comment

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

This is great @oandregal! Thanks for working on this!

I've left minor comments and I'm going to pre approve because I think we can land and iterate more if needed. My only small concern is whether the block supports section really belongs here.


- the [WordPress templates](https://developer.wordpress.org/themes/basics/template-files/) provided by the theme, either via PHP (classic theme) or via HTML templates (block theme) ([learn more](https://developer.wordpress.org/themes/block-themes/#differences-and-similarities-between-classic-themes-and-block-themes) about the differences)
- the [blocks](https://developer.wordpress.org/block-editor/reference-guides/core-blocks/) and patterns in use that come with a predefined structure (HTML markup)
- the user modifications to the content: adding content, transforming existing content (convert a given paragraph into a heading), or modifying it (attaching a class or inline styles to a block)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're talking about final, it feels to me okay not to mention transforming.

docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
docs/explanations/architecture/styles.md Outdated Show resolved Hide resolved
oandregal and others added 14 commits February 2, 2022 14:22
Co-authored-by: Nik Tsekouras <ntsekouras@outlook.com>
Co-authored-by: Nik Tsekouras <ntsekouras@outlook.com>
Co-authored-by: Nik Tsekouras <ntsekouras@outlook.com>
Co-authored-by: Nik Tsekouras <ntsekouras@outlook.com>
Co-authored-by: Nik Tsekouras <ntsekouras@outlook.com>
Co-authored-by: Nik Tsekouras <ntsekouras@outlook.com>
Co-authored-by: Nik Tsekouras <ntsekouras@outlook.com>
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.

I think that's a great addition.

@oandregal oandregal merged commit 8a3b7fd into trunk Feb 3, 2022
@oandregal oandregal deleted the add/styles-intro branch February 3, 2022 09:26
@github-actions github-actions bot added this to the Gutenberg 12.6 milestone Feb 3, 2022
@oandregal
Copy link
Member Author

These are things that are not covered by this PR but folks mentioned that could be useful to have in some place:

  • Find a place for some implementation utils (functions to get styles from attributes in "skip serialization" mode) (see).
  • Find a place for documenting how "Editor Styles" work and how the theme-provided styles get loaded in the editor. Also: classic.css and reset.css. See.

I don't plan to work on them at the moment, but wanted to give them visibility in case anyone has the bandwidth/interest.

@gziolo
Copy link
Member

gziolo commented Feb 3, 2022

Excellent work, this is going to be super helpful for both contributors and extenders ❤️

@andrewserong
Copy link
Contributor

Great work @oandregal, thanks again for adding in the extra documentation, +1 to the above comment, it's going to be really helpful for folks 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CSS Styling Related to editor and front end styles, CSS-specific issues. [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Developer Documentation Documentation for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants