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

Document the supports style properties that were deemed stable during 5.6 cycle #26771

Merged
merged 12 commits into from
Nov 10, 2020

Conversation

oandregal
Copy link
Member

@oandregal oandregal commented Nov 6, 2020

This documents how blocks declare support for some style properties -color, font size, spacing, line height- that were deemed stabled during the WordPress 5.6 release cycle.

Note that:

  • the properties prepended with __experimental are not documented, as they are still in the experimental phase.
  • the color.link property is no longer marked as experimental but still requires experimental theme support, so this hasn't been documented either.

@oandregal oandregal self-assigned this Nov 6, 2020
@oandregal oandregal added [Feature] Block API API that allows to express the block paradigm. [Type] Developer Documentation Documentation for developers labels Nov 6, 2020
@oandregal
Copy link
Member Author

oandregal commented Nov 6, 2020

Cross-posting #24422 for visibility: it'd be great to use the existing block.json data to show which blocks support each property here. This data lives now in this document which is sourced manually, so it's prone to be outdated (it already is as it doesn't have info about spacing, for example) https://developer.wordpress.org/block-editor/developers/themes/theme-json/#styles

@github-actions
Copy link

github-actions bot commented Nov 6, 2020

Size Change: +1.32 kB (0%)

Total Size: 1.21 MB

Filename Size Change
build/annotations/index.js 3.77 kB -8 B (0%)
build/api-fetch/index.js 3.42 kB -30 B (0%)
build/autop/index.js 2.83 kB -3 B (0%)
build/block-directory/index.js 8.71 kB -12 B (0%)
build/block-editor/index.js 133 kB +266 B (0%)
build/block-editor/style-rtl.css 11.2 kB -35 B (0%)
build/block-editor/style.css 11.1 kB -36 B (0%)
build/block-library/editor-rtl.css 8.91 kB -108 B (1%)
build/block-library/editor.css 8.91 kB -99 B (1%)
build/block-library/index.js 147 kB +293 B (0%)
build/block-library/style-rtl.css 8.1 kB +136 B (1%)
build/block-library/style.css 8.1 kB +139 B (1%)
build/block-serialization-default-parser/index.js 1.87 kB -9 B (0%)
build/block-serialization-spec-parser/index.js 3.06 kB -41 B (1%)
build/blocks/index.js 48 kB -173 B (0%)
build/components/index.js 171 kB -463 B (0%)
build/components/style.css 15.3 kB +2 B (0%)
build/compose/index.js 9.87 kB +63 B (0%)
build/core-data/index.js 14.8 kB +2.22 kB (15%) ⚠️
build/data-controls/index.js 821 B +49 B (5%) 🔍
build/data/index.js 8.74 kB -31 B (0%)
build/date/index.js 31.8 kB -13 B (0%)
build/deprecated/index.js 769 B +1 B
build/dom/index.js 4.45 kB -2 B (0%)
build/edit-navigation/index.js 11.1 kB -48 B (0%)
build/edit-post/index.js 306 kB -1 B
build/edit-post/style-rtl.css 6.43 kB +28 B (0%)
build/edit-post/style.css 6.42 kB +27 B (0%)
build/edit-site/index.js 22.6 kB +139 B (0%)
build/edit-site/style-rtl.css 3.95 kB +40 B (1%)
build/edit-site/style.css 3.95 kB +41 B (1%)
build/edit-widgets/index.js 26.3 kB -8 B (0%)
build/edit-widgets/style-rtl.css 3.16 kB +34 B (1%)
build/edit-widgets/style.css 3.16 kB +33 B (1%)
build/editor/editor-styles-rtl.css 476 B -4 B (0%)
build/editor/editor-styles.css 478 B -4 B (0%)
build/editor/index.js 42.5 kB -264 B (0%)
build/element/index.js 4.62 kB -28 B (0%)
build/format-library/index.js 6.86 kB -845 B (12%) 👏
build/hooks/index.js 2.16 kB -4 B (0%)
build/keyboard-shortcuts/index.js 2.52 kB +1 B
build/keycodes/index.js 1.94 kB -1 B
build/list-reusable-blocks/index.js 3.1 kB -5 B (0%)
build/media-utils/index.js 5.31 kB -24 B (0%)
build/notices/index.js 1.77 kB -14 B (0%)
build/nux/index.js 3.4 kB -20 B (0%)
build/plugins/index.js 2.56 kB +1 B
build/priority-queue/index.js 789 B -2 B (0%)
build/redux-routine/index.js 2.84 kB -8 B (0%)
build/reusable-blocks/index.js 3.05 kB -6 B (0%)
build/rich-text/index.js 13.4 kB +158 B (1%)
build/shortcode/index.js 1.69 kB -2 B (0%)
build/url/index.js 4.06 kB +1 B
build/viewport/index.js 1.83 kB -3 B (0%)
build/warning/index.js 1.14 kB +1 B
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/blob/index.js 665 B 0 B
build/block-directory/style-rtl.css 943 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-library/theme-rtl.css 792 B 0 B
build/block-library/theme.css 793 B 0 B
build/components/style-rtl.css 15.3 kB 0 B
build/dom-ready/index.js 571 B 0 B
build/edit-navigation/style-rtl.css 881 B 0 B
build/edit-navigation/style.css 885 B 0 B
build/editor/style-rtl.css 3.85 kB 0 B
build/editor/style.css 3.85 kB 0 B
build/escape-html/index.js 735 B 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/html-entities/index.js 623 B 0 B
build/i18n/index.js 3.57 kB 0 B
build/is-shallow-equal/index.js 712 B 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/primitives/index.js 1.43 kB 0 B
build/server-side-render/index.js 2.77 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/wordcount/index.js 1.22 kB 0 B

compressed-size-action

@oandregal
Copy link
Member Author

oandregal commented Nov 6, 2020

A prospective text for the block supports dev note:

Blocks can declare support for style properties

WordPress 5.6 introduces a new API for blocks to declare support for some style properties via the supports section of its block.json file. When they do, the block editor will automatically show a UI control for the user to set those values.

supports: {
    color: {
        background: true, // Enable background color UI control.
        gradient: true, // Enable gradient color UI control.
        text: true // Enable text color UI control.
    },
    fontSize: true, // Enable font size UI control.
    lineHeight: true // Enable line height UI control.
}

For some of these properties, the active theme may need to opt-in for them to be enabled. That's the case of lineHeight, for example.

How it works

When the user interacts with the controls, they will automatically attach the style value to the wrapper element of the block. This works as it did before:

  • If the control offers some preset values and the user selects one of them, a class will be attached with the name .has-<value>-<preset-category> (i.e.: has-normal-font-size).
  • If the user selects a custom value, it'll be attached as part of the style attribute of the wrapper.

Note that these are attached to the wrapper element of the block, so it works best with blocks that follow the newest apiVersion (see related dev note).

The UI controls that present users with a set of preset values, take them from the corresponding theme supports:

In depth

When blocks declare support for a style property, they also gain additional block attributes. These can also be used to set default values:

attributes: {
    backgroundColor: {
        type: 'string',
        default: 'value',
    },
    gradient: {
        type: 'string',
        default: 'value',
    },
    textColor: {
        type: 'string',
        default: 'value',
    },
    fontSize: {
        type: 'string',
        default: 'value'
    },
    style: {
        type: 'Object',
        default: {
            color: {
                background: 'value',
                gradient: 'value',
                link: 'value',
                text: 'value'
            },
            typography: {
                fontSize: 'value',
                lineHeight: 'value',
            }
        }
    }
}

The attributes backgroundColor, gradient, textColor, and fontSize hold any preset values the user has selected. When the user sets a custom value instead, these are stored in the corresponding key within the style attribute. Check out the documentation for more details.

@oandregal
Copy link
Member Author

@youknowriad feel free to edit directly the comment with text for the dev note.

@@ -163,3 +309,40 @@ supports: {
reusable: false
}
```

## spacing
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this stable? I mean the block support is stable but I'm not sure we have a stable way to enable the UI for themes.

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like it is, as per #25788

Copy link
Member Author

@oandregal oandregal Nov 10, 2020

Choose a reason for hiding this comment

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

Oh, however, that requires global styles to pass the setting down to the block editor. I guess that was what you were thinking of? Should we add back at least the comments in the theme support docs about this only working for the plugin?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a comment about the things that require theme support to work 67dd1c5

Copy link
Member Author

Choose a reason for hiding this comment

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

Prepared #26859 to tweak the docs and signal that custom-spacing theme support still requires the plugin to work.

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.

Great update thanks :)

@youknowriad
Copy link
Contributor

youknowriad commented Nov 9, 2020

@nosolosw the dev note is great, I think we need to clarify the "requirements". Meaning these only apply to the block wrapper and that it's better used in conjunction with apiVersion: 2

I'm not sure we need to detail the block attributes in the dev note but maybe a link to the block supports documentation at the end could be helpful.

@oandregal oandregal merged commit 6561ba0 into master Nov 10, 2020
@oandregal oandregal deleted the add/docs-style-properties branch November 10, 2020 16:23
@github-actions github-actions bot added this to the Gutenberg 9.4 milestone Nov 10, 2020
@oandregal
Copy link
Member Author

@youknowriad tweaked a bit the dev note adding a longer intro and explaining how it works. How does it look?

@youknowriad
Copy link
Contributor

Awesome. Now that I think about it, it's probably a good idea to expand on the dynamic blocks support for this get_block_wrapper_attributes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Type] Developer Documentation Documentation for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants