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
183 changes: 183 additions & 0 deletions docs/designers-developers/developers/block-api/block-supports.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,79 @@ supports: {
}
```

## color

- Type: `Object`
- Default value: null
- Subproperties:
- `background`: type `boolean`, default value `false`
- `gradient`: type `boolean`, default value `false`
- `text`: type `boolean`, default value `false`

This value signals that a block supports some of the CSS style properties related to color. When it does, the block editor will show UI controls for the user to set their values.

The controls for background and text will source their colors from the `editor-color-palette` [theme support](https://developer.wordpress.org/block-editor/developers/themes/theme-support/#block-color-palettes), while the gradient's from `editor-gradient-presets` [theme support](https://developer.wordpress.org/block-editor/developers/themes/theme-support/#block-gradient-presets).

```js
supports: {
background: true, // Enable background color UI control.
gradient: true, // Enable gradients UI control.
text: true, // Eneble text color UI control.
}
```

When the block declares support for a specific color property, the attributes definition is extended to include some attributes.

- `style`: attribute of `object` type with no default assigned. This is added when any of support color properties are declared. It stores the custom values set by the user. The block can apply a default style by specifying its own `style` attribute with a default e.g.:

```js
attributes: {
style: {
type: 'object',
default: {
color: {
background: 'value',
gradient: 'value',
text: 'value'
}
}
}
}
```

- When `background` support is declared: it'll be added a new `backgroundColor` attribute of type `string` with no default assigned. It stores the preset values set by the user. The block can apply a default background color by specifying its own attribute with a default e.g.:

```js
attributes: {
backgroundColor: {
type: 'string',
default: 'some-value',
}
}
```

- When `gradient` support is declared: it'll be added a new `gradient` attribute of type `string` with no default assigned. It stores the preset values set by the user. The block can apply a default text color by specifying its own attribute with a default e.g.:

```js
attributes: {
gradient: {
type: 'string',
default: 'some-value',
}
}
```

- When `text` support is declared: it'll be added a new `textColor` attribute of type `string` with no default assigned. It stores the preset values set by the user. The block can apply a default text color by specifying its own attribute with a default e.g.:

```js
attributes: {
textColor: {
type: 'string',
default: 'some-value',
}
}
```

## customClassName

- Type: `boolean`
Expand Down Expand Up @@ -108,6 +181,50 @@ supports: {
}
```

## fontSize

- Type: `boolean`
- Default value: `false`

This value signals that a block supports the font-size CSS style property. When it does, the block editor will show an UI control for the user to set its value.

The values shown in this control are the ones declared by the theme via the `editor-font-sizes` [theme support](https://developer.wordpress.org/block-editor/developers/themes/theme-support/#block-font-sizes), or the default ones if none is provided.

```js
supports: {
// Enable UI control for font-size.
fontSize: true,
}
```

When the block declares support for `fontSize`, the attributes definition is extended to include two new attributes: `fontSize` and `style`:

- `fontSize`: attribute of `string` type with no default assigned. It stores the preset values set by the user. The block can apply a default fontSize by specifying its own `fontSize` attribute with a default e.g.:

```js
attributes: {
fontSize: {
type: 'string',
default: 'some-value',
}
}
```

- `style`: attribute of `object` type with no default assigned. It stores the custom values set by the user. The block can apply a default style by specifying its own `style` attribute with a default e.g.:

```js
attributes: {
style: {
type: 'object',
default: {
typography: {
fontSize: 'value'
}
}
}
}
```

## html

- Type: `boolean`
Expand Down Expand Up @@ -136,6 +253,35 @@ supports: {
}
```

## lineHeight

- Type: `boolean`
- Default value: `false`

This value signals that a block supports the line-height CSS style property. When it does, the block editor will show an UI control for the user to set its value if [the theme declares support](/docs/designers-developers/developers/themes/theme-support.md#supporting-custom-line-heights).

```js
supports: {
// Enable UI control for line-height.
lineHeight: true,
}
```

When the block declares support for `lineHeight`, the attributes definition is extended to include a new attribute `style` of `object` type with no default assigned. It stores the custom value set by the user. The block can apply a default style by specifying its own `style` attribute with a default e.g.:

```js
attributes: {
style: {
type: 'object',
default: {
typography: {
lineHeight: 'value'
}
}
}
}
```

## multiple

- Type: `boolean`
Expand Down Expand Up @@ -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.


- Type: `Object`
- Default value: null
- Subproperties:
- `padding`: type `boolean`, default value `false`

This value signals that a block supports some of the CSS style properties related to spacing. When it does, the block editor will show UI controls for the user to set their values, if [the theme declares support](/docs/designers-developers/developers/themes/theme-support.md##cover-block-padding).

```js
supports: {
padding: true, // Enable padding color UI control.
}
```

When the block declares support for a specific spacing property, the attributes definition is extended to include some attributes.

- `style`: attribute of `object` type with no default assigned. This is added when `padding` support is declared. It stores the custom values set by the user. The block can apply a default style by specifying its own `style` attribute with a default e.g.:

```js
attributes: {
style: {
type: 'object',
default: {
spacing: {
padding: {
top: 'value',
right: 'value',
bottom: 'value',
left: 'value'
}
}
}
}
}
```