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

Make the custom spacing theme support flag and block support API stable #25788

Merged
merged 1 commit into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/designers-developers/developers/themes/theme-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ The settings section has the following structure and default values:
"palette": [ ... ], /* color presets, as in add_theme_support('editor-color-palette', ... ) */
},
"spacing": {
"customPadding": false, /* true to opt-in, as in add_theme_support('experimental-custom-spacing') */
"customPadding": false, /* true to opt-in, as in add_theme_support('custom-spacing') */
"units": [ "px", "em", "rem", "vh", "vw" ], /* filter values, as in add_theme_support('custom-units', ... ) */
},
"typography": {
Expand Down
6 changes: 3 additions & 3 deletions docs/designers-developers/developers/themes/theme-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,12 @@ To make the content resize and keep its aspect ratio, the `<body>` element needs
add_theme_support( 'responsive-embeds' );
```

## Experimental — Cover block padding
## Cover block padding

Using the Gutenberg plugin (version 8.3 or later), Cover blocks can provide padding controls in the editor for users. This is off by default, and requires the theme to opt in by declaring support:
Some blocks can provide padding controls in the editor for users. This is off by default, and requires the theme to opt in by declaring support:

```php
add_theme_support('experimental-custom-spacing');
add_theme_support('custom-spacing');
```

## Experimental — Link color control
Expand Down
2 changes: 1 addition & 1 deletion lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ function gutenberg_experimental_global_styles_get_theme_support_settings() {
}
$theme_settings['global']['settings']['typography']['customLineHeight'] = true;
}
if ( get_theme_support( 'experimental-custom-spacing' ) ) {
if ( get_theme_support( 'custom-spacing' ) ) {
if ( ! isset( $theme_settings['global']['settings']['spacing'] ) ) {
$theme_settings['global']['settings']['spacing'] = array();
}
Expand Down
11 changes: 8 additions & 3 deletions packages/block-editor/src/hooks/padding.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { __ } from '@wordpress/i18n';
import { Platform } from '@wordpress/element';
import { hasBlockSupport } from '@wordpress/blocks';
import { getBlockSupport } from '@wordpress/blocks';
import { __experimentalBoxControl as BoxControl } from '@wordpress/components';

/**
Expand All @@ -12,7 +12,12 @@ import { __experimentalBoxControl as BoxControl } from '@wordpress/components';
import { cleanEmptyObject } from './utils';
import { useCustomUnits } from '../components/unit-control';

export const PADDING_SUPPORT_KEY = '__experimentalPadding';
export const SPACING_SUPPORT_KEY = 'spacing';

const hasPaddingSupport = ( blockName ) => {
const spacingSupport = getBlockSupport( blockName, SPACING_SUPPORT_KEY );
return spacingSupport && spacingSupport.padding !== false;
};

/**
* Inspector control panel containing the line height related configuration
Expand All @@ -30,7 +35,7 @@ export function PaddingEdit( props ) {

const units = useCustomUnits();

if ( ! hasBlockSupport( blockName, PADDING_SUPPORT_KEY ) ) {
if ( ! hasPaddingSupport( blockName ) ) {
return null;
}

Expand Down
10 changes: 5 additions & 5 deletions packages/block-editor/src/hooks/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import { createHigherOrderComponent } from '@wordpress/compose';
*/
import { COLOR_SUPPORT_KEY, ColorEdit } from './color';
import { TypographyPanel, TYPOGRAPHY_SUPPORT_KEYS } from './typography';
import { PADDING_SUPPORT_KEY, PaddingEdit } from './padding';
import { SPACING_SUPPORT_KEY, PaddingEdit } from './padding';
import SpacingPanelControl from '../components/spacing-panel-control';

const styleSupportKeys = [
...TYPOGRAPHY_SUPPORT_KEYS,
COLOR_SUPPORT_KEY,
PADDING_SUPPORT_KEY,
SPACING_SUPPORT_KEY,
];

const hasStyleSupport = ( blockType ) =>
Expand Down Expand Up @@ -148,16 +148,16 @@ export const withBlockControls = createHigherOrderComponent(
( BlockEdit ) => ( props ) => {
const { name: blockName } = props;

const hasPaddingSupport = hasBlockSupport(
const hasSpacingSupport = hasBlockSupport(
blockName,
PADDING_SUPPORT_KEY
SPACING_SUPPORT_KEY
);

return [
<TypographyPanel key="typography" { ...props } />,
<ColorEdit key="colors" { ...props } />,
<BlockEdit key="edit" { ...props } />,
hasPaddingSupport && (
hasSpacingSupport && (
<SpacingPanelControl key="spacing">
<PaddingEdit { ...props } />
</SpacingPanelControl>
Expand Down
4 changes: 3 additions & 1 deletion packages/block-library/src/cover/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
"anchor": true,
"align": true,
"html": false,
"__experimentalPadding": true
"spacing": {
"padding": true
}
}
}
4 changes: 3 additions & 1 deletion packages/block-library/src/group/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"gradients": true,
"link": true
},
"__experimentalPadding": true
"spacing": {
"padding": true
}
}
}