-
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
Blocks and Theme Styling Overview #5360
Comments
Please don't forget what value it is in GUI, for font-size: em, px, pt, percent. |
It would be incredibly useful for plugins too, having the information if a given theme chose to style the blocks, in one method from WP core. |
I really like the three separations (style, edit, theme) for style files. This feels like a robust pattern going forward. On the font UI, lets iterate a little on styling with the reset being the same, but that's a minor issue. |
About the font-sizes controls: I've seen a number of tickets here that all use a numeric field (slider etc) for font-size. However that assumes that the user wants to use pixels... and that's just wrong. I haven't used pixels for typography sizes in years, I prefer using |
The value doesn't currently have a unit on purpose. |
Seems like a great approach! Will ask questions later on. |
Hi, I just found your discussion on editor / block styles (typo and color) and wonder, if and when you plan to roll out the function in the plugin. Else is there a possibility for me as a beginner in theme development to try that already? |
I've been thinking about this and had a few questions:
|
Both. An example is the quote style, that has a left border and some color choices. This currently don't apply on the front-end equally.
Probably should be generic enough to apply to any block.
If the theme doesn't opt in into having the default block styles, these won't be loaded. Shouldn't matter what we do with theme-supplied styles in that case. |
I like the separation of stylesheets. My only suggestion would be changing the name of
This makes sense, but my concern is that when G merges into Core, there will be a lot of themes that don't initially inject their styles into the Editor. This will be a big disconnect for users, I think. Is it too difficult to inject the theme styles automatically? I'm sure there's already discussion around this, I'll look for it. |
I wanted to drop some thoughts here since I've been thinking about this lately, and testing some themes with Gutenberg in mind... The separated approach laid out by @mtias seems like a nice balanced way ahead. Theme authors will have the choice as to whether to opt in, or go their own way. That's very WordPress-friendly, in terms of what everyone is used to having. It also lets both the type of themes exist: custom ones, and ones that build on existing Gutenberg structure, styles, etc. I'd also +1 the font and color approach mentioned. It strikes and good balance and gives authors a lot of flexibility. |
I agree that conflict can happen between default styling and plugins/themes that do not quite account for the styling. For instance, I am using the Gutenberg starter theme (and also tried with Fashion Blog theme by Automattic) and noticed that a custom 'spacer' block by Array Themes has this weird gray styling on the front end: https://cloudup.com/cnJovnhpegf It seems like they use So as @davidakennedy mentioned, allowing a plugin or theme to override these default stylings could be preferable to avoid these conflicts. |
I’m really pleased that this is being looked at. Thanks to @karmatosed for pointing the ticket out to me. I think that splitting the styles into more files is a good approach that would alleviate a lot of my concerns with the defaults overriding already existing styles. Thinking further - is there was a way for the proposed theme.css to work in both editor AND the on the front end? If this were possible then perhaps the theme.css could be filtered within the theme (or as a property in add_theme_support), which would provide a simple way for themes to add their custom styles to the editor. I appreciate that there would probably be specificity issues here so don’t know if it would be possible to do with a single stylesheet. Otherwise using SASS a second stylesheet could be made quite easily that achieves the same thing. Regarding the fonts - I really like this as well. It’d be great for themes to be able to select font sizes that fit their modular scale. I love a bit of consistency. I would suggest removing the number and slider. In the demo the number shows 24 - which means 24 pixels. It was mentioned that the numbers are unitless but if you made something 24 rems it would be obscenely large. This could potentially cause issues when switching between themes that use different units. Again, regarding the numbers, users may learn to use a specific number scale (24, 36, 48 for example) with their current theme, and then get confused when they switch to a theme that uses percentages/ rems where the scales are wildly different. If we hide the numbers and stick to the buttons then it will be a simple interface that is more easily transferable between themes. Regarding sizes, I would suggest having a fixed number of sizes. I don’t know what the plan is here, but if you allowed themers to define the number of sizes (eg one theme may define s, m, and l, and another may define x, s, m , l, xl ) then we will have the same issues with theme transferability. As an aside - is there a way to just subscribe to theme related tickets here? |
I don't think that is technically overly complicated as it's de-facto exactly the same what the existing "CSS Class" text input field does.
I do agree with this concern - dropdowns are certainly more user-friendly than an input field for a CSS class, but what you're outlining would still be a lot better. Investigating an approach for block variants in a plugin first appears like a good solution to me. |
I'm having some trouble visualizing this approach — @mrwweb @felixarntz could either of you sketch out what you're thinking? |
A little late to the issue but I agree with a lot of the above commentary. Block transforms feel appropriate for semantic changes, not simple visual changes. The transform API also requires you to know exactly which blocks a block can be transformed into, which is putting a huge burden on plugin developers to test and develop interop with other plugins for something that might just be a simple visual tweak. I also haven't fully tested it, but I imagine there will be additional issues if I have Third Party Quote Block Plugin used on a few posts, but then delete the plugin — does Gutenberg still know how to transform the instances of the Third Party Quote Block in my post_content? Or do I get an error message? Or is it transformed to a generic paragraph or classic block? None of those experiences are really ideal. (And none of this is factoring in block overload… what happens when third party plugins and themes start supporting Gutenberg en masse? Block discoverability is going to be a major issue as more blocks become available, and asking users to keep track of all the variants of a block type in the inserter is just a nightmare.) The sidebar may not be the best place for this, but here's one idea: Themes could register their own "block designs", which consists of a name, a CSS class, and a preview image. |
@chrisvanpatten thanks for that visual, this really plays to my bigger concern of that being in the sidebar. If you think of scale that easily breaks. What other options are there? Are there any applications doing something like this right now we can learn from? |
@karmatosed I'm not sure where else to put it, but I'm certainly open to ideas. |
(To elaborate, I think there will be an issue of scale anywhere it goes — and that's applicable to any point in the UI where plugins can add additional options. I'm not sure if putting it behind a toolbar button is better or worse but I'm certainly open to experimenting with that!) |
Thanks @chrisvanpatten, that visualization helps. Some more examples from other sources: Slideshow block in Weebly Layout blocks in Weebly Section Designs in Wix ADI More design settings in Squarespace |
As promised, here's a couple concepts. I think I like this first one best, placing the drop down with the block definition in the sidebar. It's kind of subtle and prominent at the same time: I also think this is a great example of how powerful something like this can be! It applies 4 styles (background, padding, border, box-shadow) that would be hard to apply any other way but also way overkill for creating unique blocks for. Any interface that allowed setting padding and creating box shadows wouldn't be easy to replicate like this and would be both tedious to use and likely to be used inconsistently from page to page. Another option would be to put the variant selection menu in the inline toolbar: |
@BinaryMoon yes, the original intention of the issue is unrelated to variants and is being worked on — initial implementation should land for 3.0. @mrwweb let's reopen #783 for this conversation, as it's getting a bit away from the purpose of the current issue, and make out a plan before deciding if we can make it into 5.0 or not.
To be clear, I totally agree with this, and I think it's something we should pursue. :) I'm not entirely sure how we would present it — perhaps starting by having the dropdown within the "Advanced" panel is a safe start. One of the problems is that a design principle has been to allow as much as possible to happen in the block directly, with the sidebar being more about sophisticated attributes. This poses a problem for how we deal with variants. Where should they fall? If they are considered useful user-friendly additions (and I'd tend to agree with this) then we should see how they could be incorporated to the block body/toolbar instead of the sidebar. But a dropdown list with the names in the block toolbar doesn't scale too well and can complicate the UI. (Issues with mobile, not immediately visual, etc.) Also, even if technically this is trivial to do, we should look at how we could facilitate the usage of it longer term, because I think it's a good feature to have. @chrisvanpatten I totally agree on the semantic distinction being relevant here. I'd actually use that to make the case that "subheading" should be a separate block, because it's not a purely visual change, it has semantic value to the user. |
Quick note about I tried it with |
@brandonpayton when you have a moment could you look at the above? Thanks! |
I agree with @samikeijonen - I want to include my styles in the editor but I'm having a hard time overriding the default ones. |
Hi @samikeijonen, you're right that it has to do with dependencies. The @mtias do you want us to do anything more to support overriding theme CSS in the editor? |
Thanks @brandonpayton! I opened new issue in #7776 just in case. I feel like replacing the original |
This is an overview of theme related considerations for Gutenberg as gathered after several months of testing and feedback.
WordPress Block Styles vs Theme Styles
During the evolution of Gutenberg we have introduced several blocks with somewhat opinionated styles (quote, pullquote, separator, etc). We have seen how some themes really don't want these — they might conflict with their base styles — while other themes really want to build on top of them (particularly new themes). We have opted to disable the opinionated styles for some of the blocks that map to HTML primitives, like
blockquote
, because almost every theme defines those for themselves and would be tough to accommodate all conflicts. This has meant we have prevented new themes from reusing the styles that appear on the editor for all these elements. We are seeing some vanilla themes that do want these styles and would rather just customize on top of them.This means we are looking at a split between themes that don't want any visual style (not considering structural ones here, like columns, galleries, etc) coming from core blocks and themes that do want these styles as their base. It seems we should figure out a way to accommodate both needs.
Anatomy of a Block's Style
Currently we define block styles in two stylesheets: "style" and "edit". The main problem is that if we want to supply visual styles to some themes, we cannot split them from structural styles that should come for all themes easily. So I am proposing we look at establishing three separations for block styles:
style.scss
are the shared structural styles.edit.scss
are the editor specific styles.theme.scss
are opinionated visual styles.With these separations we can always include the
base
styles for all themes, but maketheme
styles optional. A theme would have to do something likeadd_theme_support( 'wp_block_styles ' )
to load these if they want to. (Bonus points if through the structure oftheme.scss
we could find easier ways for a theme to supply their own styles to the editor. Imagine having a blocks folder under your theme where you can add a css/scss file per block which is used to concatenate into the editor, but I digress.) During build, we should include the visual styles in a separate stylesheet.Previous: #2905
Classes vs Inline Styles
A similar split exists between basic and advanced customization options. We have a couple blocks that have a fair degree of styling possibilities around colors and font sizes. We allow themes to disable custom colors and to register their own already. We are also looking at providing an array of font sizes that would map to classes
is-small-text
,is-regular-text
,is-large-text
, etc, so themes can dynamically set these values. The ability to set custom values is still welcomed for various contexts, so it's looking like the best separation is:For basic we avoid all saved inline styles, and advanced is something that could be disabled by a theme or plugin if necessary.
Colors
Would be registered assigning a name to each color value. The name would be used to construct a
.has-color-{name}
class as well as show a tooltip for accessibility.Applying one of these colors won't generate any inline style. See #5273
Fonts
In the case of fonts, there'll be a set of predefined sizes that would map to classes. The set would be provided as an array of values which would be used to generate the value in the editor, while the only thing saved would be the corresponding class (i.e
is-small-text
,is-regular-text
,is-large-text
,is-larger-text
).The UI would be close to this proposal:
See #5269
This issue will be updated with further details as they come by.
The text was updated successfully, but these errors were encountered: