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

Manage CSS for Global Styles #20290

Merged
merged 49 commits into from
May 21, 2020
Merged

Conversation

oandregal
Copy link
Member

@oandregal oandregal commented Feb 18, 2020

Continues work from: #19883 #20047
See larger picture at #22296

This PR explores a way in which we can "manage CSS" for global styles. Instead of writing CSS directly, themes would provide their design choices for blocks. Gutenberg will generate a CSS that merges core, themes, and user preferences into one.

How this works?

Let's take an existing pattern such as "Hero Two Columns" and try to convert it to "global styles format":

Screenshot from 2020-05-14 10-53-26

Via theme.json, themes would register the design tokens they want for blocks:

{
    "blocks": {
        "core/heading/h1": {
            "color": "var(--wp--preset--color--primary)",
            "font-size": "calc(1px * var(--wp--preset--font-size--huge))"
        },
        "core/heading/h4": {
            "color": "var(--wp--preset--color--secondary)",
            "font-size": "var(--wp--preset--font-size--normal)"
        },
        "core/paragraph": {
            "color": "var(--wp--preset--color--quaternary)",
            "font-size": "calc(1px * var(--wp--preset--font-size--normal))"
        }
    }
}

Note the use of CSS variables to set the values of the properties. These come from the color and font-size presets that the theme has defined in functions.php. They'll come from the theme.json at some point, but at the moment we pull them from the existing presets #22076

add_theme_support( 'editor-color-palette', array(
    array(
        'name'  => __( 'Primary', 'global-styles' ),
        'slug'  => 'primary',
        'color' => 'rgb(131, 12, 8)',
    ),
    array(
        'name'  => __( 'Secondary', 'global-styles' ),
        'slug'  => 'secondary',
        'color' => 'rgb(60, 12, 15)',
    ),
    array(
        'name'  => __( 'Tertiary', 'global-styles' ),
        'slug'  => 'tertiary',
        'color' => 'rgb(209, 207, 203)',
    ),
    array(
        'name'  => __( 'Quaternary', 'global-styles' ),
        'slug'  => 'quaternary',
        'color' => 'rgb(30, 30, 30)',
    ),
) );

add_theme_support( 'editor-font-sizes', array(
    array(
        'name' => __( 'Primary', 'global-styles' ),
        'size' => 16,
        'slug' => 'normal'
    ),
    array(
        'name' => __( 'Secondary', 'global-styles' ),
        'size' => 32,
        'slug' => 'big'
    ),
    array(
        'name' => __( 'Tertiary', 'global-styles' ),
        'size' => 60,
        'slug' => 'huge'
    )
) );

The output will be:

/* These CSS Custom Properties come from the presets. */
 :root {
    --wp--preset--color--primary: rgb(131, 12, 8);
    --wp--preset--color--secondary: rgb(60, 12, 15);
    --wp--preset--color--tertiary: rgb(209, 207, 203);
    --wp--preset--color--quaternary: rgb(30, 30, 30);
    --wp--preset--font-size--normal: 16;
    --wp--preset--font-size--big: 32;
    --wp--preset--font-size--huge: 60;
    /* gradient presets from core, because the theme didn't declare any */
}

h1 {
    color: var(--wp--preset--color--primary);
    font-size: calc(1px * var(--wp--preset--font-size--huge));
}
h4 {
    color: var(--wp--preset--color--secondary);
    font-size: var(--wp--preset--font-size--normal);
}
p {
    color: var(--wp--preset--color--quaternary);
    font-size: calc(1px * var(--wp--preset--font-size--normal));
}

Note that, at the moment, the mapping from keys to selectors (core => :root, core/paragraph => p, etc) is hardcoded in global-styles.php. This needs evolving in a different PR and be taken from the block registry.

How to test

  1. Make sure it works:
  • Enable the FSE experiment.
  • Install and activate the demo theme available here (or create your own taking that as an inspiration).
  • Load the site in the front-end. Verify that what you see is the pattern like above.
  1. Make sure it takes different values
  • Modify the theme settings so the output is different. For example, in the demo theme, go to functions.php and modify the preset values. As an example, copy the these ones for the color palette:
add_theme_support( 'editor-color-palette', array(
    array(
        'name'  => __( 'Primary', 'global-styles' ),
        'slug'  => 'primary',
        'color' => 'rgb(232, 123, 29)',
    ),
    array(
        'name'  => __( 'Secondary', 'global-styles' ),
        'slug'  => 'secondary',
        'color' => 'rgb(104, 82, 3)',
    ),
    array(
        'name'  => __( 'Tertiary', 'global-styles' ),
        'slug'  => 'tertiary',
        'color' => 'rgb(243, 236, 227)',
    ),
    array(
        'name'  => __( 'Quaternary', 'global-styles' ),
        'slug'  => 'quaternary',
        'color' => 'rgb(0, 0, 0)',
    ),
) );

You should see instead:

Screenshot from 2020-05-14 11-02-08

  1. Make sure it doesn't take unsupported properties.
  • Try adding an unsupported property in the theme.json. For example, add a text-shadow to the h1:
{
    "blocks": {
        "core/heading/h1": {
            "color": "var(--wp--preset--color--primary)",
            "font-size": "calc(1px * var(--wp--preset--font-size--huge))",
            "text-shadow": "2px 2px #FF0000"
        },
        "core/heading/h4": {
            "color": "var(--wp--preset--color--secondary)",
            "font-size": "var(--wp--preset--font-size--normal)"
        },
        "core/paragraph": {
            "color": "var(--wp--preset--color--quaternary)",
            "font-size": "calc(1px * var(--wp--preset--font-size--normal))"
        }
    }
}
  • Open the dev tools of your browser of choice and verify that the #global-styles-inline-css embedded stylesheet doesn't contain any text-shadow property.

@oandregal oandregal self-assigned this Feb 18, 2020
@oandregal oandregal added the Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json label Feb 18, 2020
@oandregal
Copy link
Member Author

oandregal commented Feb 18, 2020

When reviewing this, note that you should omit the 67c3079 commit. That's part of #20273 that I've only inlined here so it's easier to test.

lib/global-styles.php Outdated Show resolved Hide resolved
@ItsJonQ
Copy link

ItsJonQ commented Feb 19, 2020

@nosolosw Haiii!!! 👋

Apologies for the late reply! My day was pretty packed yesterday and didn't get me many opportunities for code things. I did review this update early and let it marinate throughout the day.

These are my thoughts :)

I think we need a .wp-gs environment...

...or a mechanism that provides a scoping feature. The reason is that if the selectors are too generic, the styles will apply to unintended parts within Gutenberg:

Screen Shot 2020-02-18 at 9 03 06 PM

(Notice Site Editor at the top and Inspector on the side. These have been affected by the heading styles)

With a .wp-gs environment selector, we can better control the styles within Gutenberg. It's less applicable on the front-end of the user's site ✌️

Nested Block Styles

This was a tough one! By specifying custom selectors, I think (I may be wrong) it makes it more difficult to apply styles from a "container" block when we need to support nesting.

I think keeping the variables at the :root, and declaring custom values at DOM nodes, allows for predictable scoping to work (Bonus: It also follows the cascading model of CSS variables).

<ContainerBlock>
  <InnerBlock />
  <InnerBlock />
</ContainerBlock>
:root {
  --wp--core-paragraph: black;
}
.ContainerBlock {
  --wp--core-paragraph: red;
}
.InnerBlock {
  color: var(--wp--core-paragraph);
}

The above should allow for nesting to work nicely.

However, if the CSS variables were injected at a custom selector (as the original "root"), example:

.ContainerBlock {
  --wp--core-paragraph: red;
}
.InnerBlock {
  --wp--core-paragraph: black;
}

The customization at the Container level would not take effect.


Those are the only 2 thoughts I had with your recent exploration :).
I think it was a great effort 🙏 .

I can't put my finger on it... but there's something to the custom selectors feature that I really like. I think maybe useful and powerful later on as we continue to explore and expand Global Styles

@oandregal
Copy link
Member Author

oandregal commented Feb 20, 2020

We need a .wp-gs environment.

Certainly, we need to scope the styles within the editor. How about using the existing editor-styles-wrapper? At the moment the selector generator harcodes the values, but it can be easily taught how to add any wrapper we want.

Nested Block Styles

A few things here!

  • I think we should have all variables within :root, definitely. However, this proposal is about enqueuing some extra classes if and only if the theme adds the custom selectors. If they aren't declared, the classes won't be enqueued.

  • Your example looks fantastic to evaluate. My thinking is that it is a matter of education and what authors want to do. They'll be still required to know CSS best practices, the cascade, etc. There's no difference from CSS here. I think we can be mindful of the selectors we offer, but we're limited by how CSS works and the current state of blocks. A potential source of headaches is going to be the blocks that don't have a class we can use to target them (ex: there is no .wp-block-paragraph class, so the p selector is going to potentially interfere with the paragraphs in other blocks, no matter you use CSS or the style system). My point is that you have the same problem if you write CSS:

body { /* container */
  color: black;
}
p { /* inner block */
  color: red;
}

The example you shared also highlights the importance of focused selectors. My current thinking is that core should come with pre-defined selectors for each block and that selectors for third-party blocks should also be created when a block is registered. Theme authors would have them ready to use. Beyond those, it's on the authors to register the selectors they need at convenience -- I'm thinking of highly specific selectors like "target cite within a blockquote".

Finally, and perhaps the biggest issue I see with this proposal is how would we surface this to users? They are a few open questions here: how do we detect and expose in the UI the custom areas that are modifiable? Should users only be able to tweak the custom areas themes have declared or all the ones available? etc. I've seen the expectation that the system is able to do this (here, here, and here), so I guess is something that needs figuring out at the design level?

@oandregal oandregal force-pushed the try/global-styles-target-selectors branch from e3b98b9 to bc34183 Compare February 27, 2020 10:44
@oandregal
Copy link
Member Author

Updated this to work with the global-style theme changes at WordPress/theme-experiments#22 and to use the scoped class .wp-site-blocks that is present with the FSE experiment enabled.

@github-actions
Copy link

github-actions bot commented Feb 27, 2020

Size Change: +278 kB (25%) 🚨

Total Size: 1.11 MB

Filename Size Change
build/annotations/index.js 3.62 kB +1 B
build/block-directory/index.js 6.93 kB +339 B (4%)
build/block-directory/style-rtl.css 790 B +26 B (3%)
build/block-directory/style.css 791 B +27 B (3%)
build/block-editor/index.js 105 kB +678 B (0%)
build/block-library/editor-rtl.css 7.22 kB -36 B (0%)
build/block-library/editor.css 7.22 kB -35 B (0%)
build/block-library/index.js 119 kB +1.11 kB (0%)
build/block-library/style-rtl.css 7.48 kB -5 B (0%)
build/block-library/style.css 7.48 kB -3 B (0%)
build/block-serialization-default-parser/index.js 1.88 kB +1 B
build/blocks/index.js 48.1 kB +1 B
build/components/index.js 182 kB +264 B (0%)
build/components/style-rtl.css 17.1 kB +35 B (0%)
build/components/style.css 17.1 kB +34 B (0%)
build/core-data/index.js 11.4 kB -8 B (0%)
build/data-controls/index.js 1.29 kB -2 B (0%)
build/data/index.js 8.42 kB -6 B (0%)
build/date/index.js 5.47 kB -4 B (0%)
build/dom/index.js 3.11 kB +10 B (0%)
build/edit-navigation/index.js 6.6 kB +1.01 kB (15%) ⚠️
build/edit-navigation/style-rtl.css 857 B +239 B (27%) 🚨
build/edit-navigation/style.css 856 B +239 B (27%) 🚨
build/edit-post/index.js 302 kB +274 kB (90%) 🆘
build/edit-post/style-rtl.css 12.2 kB -31 B (0%)
build/edit-post/style.css 12.2 kB -31 B (0%)
build/edit-site/index.js 12.8 kB +762 B (5%) 🔍
build/edit-widgets/index.js 7.73 kB -742 B (9%)
build/edit-widgets/style-rtl.css 4.59 kB -102 B (2%)
build/edit-widgets/style.css 4.59 kB -102 B (2%)
build/editor/index.js 44.3 kB -6 B (0%)
build/format-library/index.js 7.64 kB +6 B (0%)
build/hooks/index.js 2.13 kB -1 B
build/i18n/index.js 3.56 kB -1 B
build/is-shallow-equal/index.js 711 B -1 B
build/keyboard-shortcuts/index.js 2.51 kB -2 B (0%)
build/keycodes/index.js 1.94 kB +1 B
build/list-reusable-blocks/index.js 3.13 kB -1 B
build/media-utils/index.js 5.29 kB -1 B
build/plugins/index.js 2.56 kB +1 B
build/primitives/index.js 1.5 kB +2 B (0%)
build/redux-routine/index.js 2.85 kB +3 B (0%)
build/rich-text/index.js 14.8 kB +1 B
build/server-side-render/index.js 2.68 kB -5 B (0%)
build/url/index.js 4.02 kB +2 B (0%)
build/wordcount/index.js 1.17 kB -1 B
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.02 kB 0 B
build/api-fetch/index.js 3.39 kB 0 B
build/autop/index.js 2.83 kB 0 B
build/blob/index.js 620 B 0 B
build/block-editor/style-rtl.css 10.8 kB 0 B
build/block-editor/style.css 10.8 kB 0 B
build/block-library/theme-rtl.css 683 B 0 B
build/block-library/theme.css 685 B 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/compose/index.js 6.68 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/edit-site/style-rtl.css 5.22 kB 0 B
build/edit-site/style.css 5.22 kB 0 B
build/editor/editor-styles-rtl.css 425 B 0 B
build/editor/editor-styles.css 428 B 0 B
build/editor/style-rtl.css 5.07 kB 0 B
build/editor/style.css 5.08 kB 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/style-rtl.css 502 B 0 B
build/format-library/style.css 502 B 0 B
build/html-entities/index.js 622 B 0 B
build/list-reusable-blocks/style-rtl.css 226 B 0 B
build/list-reusable-blocks/style.css 226 B 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 616 B 0 B
build/nux/style.css 613 B 0 B
build/priority-queue/index.js 789 B 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.28 kB 0 B
build/viewport/index.js 1.84 kB 0 B
build/warning/index.js 1.14 kB 0 B

compressed-size-action

lib/global-styles.php Outdated Show resolved Hide resolved
lib/global-styles.php Outdated Show resolved Hide resolved
@oandregal oandregal added the [Status] In Progress Tracking issues with work in progress label Apr 2, 2020
@oandregal oandregal force-pushed the try/global-styles-target-selectors branch from bc34183 to 86e956b Compare April 7, 2020 12:19
lib/global-styles.php Outdated Show resolved Hide resolved
lib/global-styles.php Outdated Show resolved Hide resolved
packages/block-library/src/heading/block.json Outdated Show resolved Hide resolved
lib/global-styles.php Outdated Show resolved Hide resolved
lib/global-styles.php Outdated Show resolved Hide resolved
lib/global-styles.php Outdated Show resolved Hide resolved
@oandregal oandregal changed the title Try to target specific selectors for Global Styles Manage CSS selectors for Global Styles May 12, 2020
@oandregal oandregal force-pushed the try/global-styles-target-selectors branch from 73fbff2 to c6ec6b2 Compare May 12, 2020 10:12
@oandregal oandregal marked this pull request as ready for review May 12, 2020 11:19
@oandregal
Copy link
Member Author

Pushed the changes that adapted this to the theme.json schema discussed in this thread.

Copy link
Member

@jorgefilipecosta jorgefilipecosta left a comment

Choose a reason for hiding this comment

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

Hi @nosolosw,
What if we include in this PR mechanism setting the default lineHeight from the paragraph (a direct property) and link color in a paragraph (a CSS var). Currently, this PR is focusing on colors/gradients/font sizes/settings; we already have a PR focusing on colors #21490 (and can be easily extended for font sizes and gradients) and a PR focusing on settings #22291. It would be nice if this one included the end to end cycle for setting lineHeight and including the theme.json mechanism for link color.

lib/global-styles.php Show resolved Hide resolved
@oandregal
Copy link
Member Author

oandregal commented May 15, 2020

What if we include in this PR mechanism setting the default lineHeight from the paragraph (a direct property) and link color in a paragraph (a CSS var).

I'd like to keep the scope of this PR under control, but I'm happy to work on the link color thing if nobody has owned them yet when I get to it.

Note that, when this PR lands, theme authors can already set any property that has been declared via implicit atts at the block level (color, font-size, and line-height). I didn't use line-height in the demo theme but you already can! The next step I'd like to prepare is how to we make this automatic: so when a block declares an implicit property at the block level, it can already be used at the global level removing the need for maintaining this list. It also touches the block registration bit I've mentioned here (see tasks section).

We cannot use the full preset schema, including names,
because our tooling is not able to internationalize the names
from the theme.json file, we can use the final format for them.
Copy link
Member

@jorgefilipecosta jorgefilipecosta left a comment

Choose a reason for hiding this comment

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

Hi @nosolosw nice work here the engine seems to be in a good shape 👍

I think we may be able to discard the global property.

Currently, we can change the styles of a group block using:

	"core/group": {
		"styles": {
			"color": "blue",
			"font-size": "14"
		}
		"presets": {
			color:
			gradient:
		}
	}

In the future if we add nested selectors I imagine the shape would look like this:

	"core/group": {
		"styles": {
			"color": "blue",
			"font-size": "14"
		},
		"presets": {
			color:
			gradient:
		},
		"core/paragraph": {
			"styles": {
				"color": "blue",
				"font-size": "14"
			}
		}
	}

I imagine the global styles should mirror that shape for the group and just assume a :root selector.
So the shape of global styles would be:

{
		"styles": {
			"color": "blue",
			"font-size": "14"
		},
		"presets": {
			color:
			gradient:
		},
		"core/paragraph": {
			"styles": {
				"color": "blue",
				"font-size": "14"
			}
		}
}

While currently, it is:

{
		global: {
			"styles": {
				"color": "blue",
				"font-size": "14"
			},
			"presets": {
				color:
				gradient:
			}
		},
		"core/paragraph": {
			"styles": {
				"color": "blue",
				"font-size": "14"
			}
		}
}

lib/global-styles.php Outdated Show resolved Hide resolved
lib/global-styles.php Outdated Show resolved Hide resolved
lib/global-styles.php Outdated Show resolved Hide resolved
Copy link
Member

@jorgefilipecosta jorgefilipecosta left a comment

Choose a reason for hiding this comment

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

I am not able to output styles for the blocks e.g:

p {
  color: red;
}

But I am not being able to output global styles like:

:root {
  color: red;
}

Using:

{
	"global": {
		"styles": {
			"color": "red"
		}
	}
}

How can I output the global styles?

Copy link
Member

@jorgefilipecosta jorgefilipecosta left a comment

Choose a reason for hiding this comment

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

It seems we may have a bug in the merging mechanism.
If I add the following styles as core defaults:

	"core/paragraph": {
		"styles": {
			"color": "blue",
			"font-size": "14"
		}
	}

And the following styles in theme.json:

	"core/paragraph": {
		"styles": {
			"color": "red"
		}
	}

The result is:

p {
	color: red;
}

I think the result should be:

p {
	color: red;
	"font-size": "14"
}

@oandregal
Copy link
Member Author

@jorgefilipecosta that's really good feedback that I'm processing right now and I'll ping you when this is ready for the next round.

Wanted to comment on a few general things to keep the conversation going while I act on feedback:

I think we may be able to discard the global property.

I'd like to keep this conversation in the thread about theme.json structure. I've already responded there.

It seems we may have a bug in the merging mechanism.

I'd say this is a bug on the expectations for this feature! What I'm saying is that it works as I made it to. However, my expectations may need re-adjustment, I was actually on the fence about how that should work.

My rationale for the current behavior was that it works like the presets: if the theme provides a preset/style/etc, core defaults are discarded. Your comment made me realize that the expectations for styles and presets are different:

  • presets: discard all the leaf items if the theme provides a preset (how it works now in PHP land as well).
  • styles: like CSS itself, the leaf items are merged and origins override (user overrides theme, theme overrides core) as you were expecting.

- presets: each preset category (color, font-size, gradients) override each other
- styles: leaf items override each other
- features: leaf items override each other
@oandregal
Copy link
Member Author

@jorgefilipecosta I've implemented your suggestions, this is ready for the next round.

There's this bit of feedback about the global: { styles: { ... } } section. At the moment, it is not allowed to output custom styles that are bound to the document (:root, body, or another selector, that should be open for discussion). I think that's a nice thing to have and one that I'd expect theme authors to demand, perhaps. Technically, it's straightforward to do, but I'm unsure which properties should we allow. I'm happy to add that list if we have it, but I also think that'd be a nice follow-up PR if theme authors demand it. I'm eager to get this in their hands to gather feedback as soon as possible! This PR has become unwelcoming to them after all the nitty-gritty details we had to discuss, refactors, and changes, so we're missing here that kind of feedback 😅

Copy link
Member

@jorgefilipecosta jorgefilipecosta left a comment

Choose a reason for hiding this comment

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

Nice work, the problems I identified were addressed and things seem to be working as expected.
I don't see any blocker.
I think we as follow up we should see how can we remove the hardcoded map of blocks and how we can output truly global styles(in this PR can only output styles to a specific block).
There is also a question of how can themes target multiple blocks? In CSS one would do p, h1 {...} Should we also accept comma-separated selectors?

@oandregal oandregal merged commit 1425211 into master May 21, 2020
@oandregal oandregal deleted the try/global-styles-target-selectors branch May 21, 2020 08:00
@github-actions github-actions bot added this to the Gutenberg 8.2 milestone May 21, 2020
@oandregal
Copy link
Member Author

Thanks all for the reviews, patience, and ideas to improve this PR. To recap, this advanced the use of experimental-theme.json by themes at the framework level. It added:

  • The ability to add presets (color, font-size, gradients) via the theme.json file.
  • Declare a set of "managed CSS" for some blocks, to match what a user can do in the editor.

Note that this is still experimental and needs iteration in many areas. The fact that people can play now with it will help us to gather more feedback and adjust accordingly.

@oandregal
Copy link
Member Author

Initial docs for this (and related PRs) at #22518

@jffng
Copy link
Contributor

jffng commented May 21, 2020

Very excited to see this land!

Are the presets and "managed CSS" loaded into the editor as of this PR? I'm only seeing them enqueued to the front-end at the moment.

Editor Front-end
Screen Shot 2020-05-21 at 10 59 05 AM Screen Shot 2020-05-21 at 10 57 54 AM

@oandregal
Copy link
Member Author

They are since a couple of hours ago (since #22520 landed). You may have an older master version, perhaps?

@oandregal
Copy link
Member Author

Ah, I now see that your comment is from 2h ago as well! Definitely update master :)

@jffng
Copy link
Contributor

jffng commented May 21, 2020

I tried this out and in general it's working as described! 👏

Some comments / questions specifically on how this is formatted today, please let me know if there's a better way to direct this:

Presets

  • Will only certain presets be transformed to CSS custom properties? I.e. what happens when I set presets on blocks? Having the ability to leverage these variables in your styles felt like the biggest benefit to me.
  • Regarding global presets, what's the benefit to supplying those in the config vs functions.php, given that the names cannot be translated?

Styles

  • This is really great, as long as Gutenberg can guarantee that the styles declared here affect blocks predictably. It's slightly awkward to declare, but not totally foreign and I understand the value.
  • In terms of what CSS to support next, I think it'd be important to see font-family and background, following by some kind of support for spacing rules to really stress test how this cascades and create an expressive demo.

Features

  • Granted this isn't ready yet, features and presets have an overlap that I'm having trouble understanding. Is the idea for features to allow for block settings to be enabled/disabled only?

@oandregal
Copy link
Member Author

oandregal commented May 22, 2020

First, let me say that I've just merged initial documentation for this. Unfortunately, it isn't visible in the handbook just yet because it is only updated in every WordPress release now. In case it needs some clarification, etc, perhaps this would be a good place to comment.

Presets

  • All are transformed into CSS Custom Properties, so they can be used in stylesheets already. At the moment, you can only define presets at the global level, although in the future you'll be able to define a different color preset for a particular block; for example, a different color palette within the group block. Is that what you were thinking? do you have in mind any other use cases?

  • functions.php vs theme.json: at the moment, for a production theme, you have to use functions.php to make sure the presets are translated. The reason we added presets in theme.json early is to gather feedback about the spec, and to communicate that we expect presets to be absorbed by it as well. It's exciting to see how this "managed" CSS approach would solve a few issues that we have currently with both custom presets and default ones.

Styles: 👍

Features:

  • features & preset: that's a point that was discussed as well and there's no clear winner yet. That's why I feel it's important we shipped something to gather feedback from real usage.

  • mmm, I don't see why we should be limited to enable/disable states: if there's a feature in the editor that requires more info, it seems to me that we should be able to encode it. Anyone that comes to mind and would be particularly interesting?

@jorgefilipecosta
Copy link
Member

Hi @nosolosw I noticed that when we set a text color the style shape on the block is {"style":{"color":{"text":"#2a9dce"}}}. To set the text color in this PR one does {"styles":{"color":#2a9dce}}. As part of the link color work I will probably update the work on this PR to be compliment with the style shape at the block level.

@oandregal
Copy link
Member Author

@jorgefilipecosta we certainly need to consolidate all the things (block.json, block atts, theme.json)! :)

As a general rule, I think it'd be good for velocity to have focused PRs that do one thing. The link color property (which has a lot to discuss about) could be perhaps split in two: add it to the block level + add it to the theme.json. We could have another to consolidate the shape of different things, etc.

@oandregal
Copy link
Member Author

@jffng as part of bringing some clarity to all we've been doing in the block style system I've created #22700 to keep track of the style properties of the blocks we plan to work on (and the ones already available at the block level and at the global styles level).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Status] In Progress Tracking issues with work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants