From fd9879fd74bc1395371b49bf3842f2f33897d20d Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Wed, 15 Jul 2020 17:34:25 +0100 Subject: [PATCH] Make the line height and custom units theme support flags consistent --- lib/client-assets.php | 4 ++-- .../src/components/unit-control/index.js | 22 +++++++++---------- .../block-editor/src/hooks/line-height.js | 2 +- .../editor/src/components/provider/index.js | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/client-assets.php b/lib/client-assets.php index e87cb3fd22e360..f4343063f83502 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -655,7 +655,7 @@ function gutenberg_extend_settings_block_patterns( $settings ) { * @return array Filtered editor settings. */ function gutenberg_extend_settings_custom_line_height( $settings ) { - $settings['__experimentalEnableCustomLineHeight'] = get_theme_support( 'experimental-line-height' ); + $settings['enableCustomLineHeight'] = get_theme_support( 'custom-line-height' ); return $settings; } add_filter( 'block_editor_settings', 'gutenberg_extend_settings_custom_line_height' ); @@ -669,7 +669,7 @@ function gutenberg_extend_settings_custom_line_height( $settings ) { * @return array Filtered editor settings. */ function gutenberg_extend_settings_custom_units( $settings ) { - $settings['__experimentalDisableCustomUnits'] = get_theme_support( 'experimental-custom-units' ); + $settings['enableCustomUnits'] = get_theme_support( 'custom-units' ); return $settings; } add_filter( 'block_editor_settings', 'gutenberg_extend_settings_custom_units' ); diff --git a/packages/block-editor/src/components/unit-control/index.js b/packages/block-editor/src/components/unit-control/index.js index 14e2204d55f4da..b6a37665a4f90c 100644 --- a/packages/block-editor/src/components/unit-control/index.js +++ b/packages/block-editor/src/components/unit-control/index.js @@ -2,11 +2,7 @@ * WordPress dependencies */ import { __experimentalUnitControl as BaseUnitControl } from '@wordpress/components'; - -/** - * Internal dependencies - */ -import useEditorFeature from '../use-editor-feature'; +import { useSelect } from '@wordpress/data'; export default function UnitControl( { units: unitsProp, ...props } ) { const units = useCustomUnits( unitsProp ); @@ -36,17 +32,21 @@ function filterUnitsWithSettings( settings = [], units = [] ) { * @return {Array} Filtered units based on settings. */ export function useCustomUnits( unitsProp ) { - const settings = useEditorFeature( '__experimentalDisableCustomUnits' ); - const isDisabled = !! settings; - - // Adjust units based on add_theme_support( 'experimental-custom-units' ); + const settings = useSelect( + ( select ) => + select( 'core/block-editor' ).getSettings().enableCustomUnits, + [] + ); + const isDisabled = ! settings; + + // Adjust units based on add_theme_support( 'custom-units' ); let units; /** * Handle extra arguments for add_theme_support * - * Example: add_theme_support( 'experimental-custom-units', 'rem' ); - * Or: add_theme_support( 'experimental-custom-units', 'px, 'rem', 'em' ); + * Example: add_theme_support( 'custom-units', 'rem' ); + * Or: add_theme_support( 'custom-units', 'px, 'rem', 'em' ); * * Note: If there are unit argument (e.g. 'em'), these units are enabled * within the control. diff --git a/packages/block-editor/src/hooks/line-height.js b/packages/block-editor/src/hooks/line-height.js index 40a3cdb66ef31a..8881fdbbcb17f0 100644 --- a/packages/block-editor/src/hooks/line-height.js +++ b/packages/block-editor/src/hooks/line-height.js @@ -59,7 +59,7 @@ export function useIsLineHeightDisabled( { name: blockName } = {} ) { const isDisabled = useSelect( ( select ) => { const editorSettings = select( 'core/block-editor' ).getSettings(); - return ! editorSettings.__experimentalEnableCustomLineHeight; + return ! editorSettings.enableCustomLineHeight; } ); return ( diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index e224a3ee3c8a7c..2282b0f4a10f59 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -114,8 +114,6 @@ class EditorProvider extends Component { '__experimentalBlockDirectory', '__experimentalBlockPatterns', '__experimentalBlockPatternCategories', - '__experimentalDisableCustomUnits', - '__experimentalEnableCustomLineHeight', '__experimentalEnableCustomSpacing', '__experimentalEnableLegacyWidgetBlock', '__experimentalEnableLinkColor', @@ -135,6 +133,8 @@ class EditorProvider extends Component { 'disableCustomColors', 'disableCustomFontSizes', 'disableCustomGradients', + 'enableCustomUnits', + 'enableCustomLineHeight', 'focusMode', 'fontSizes', 'gradients',