Skip to content

Commit

Permalink
Make the line height and custom units theme support flags consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Jul 15, 2020
1 parent 4ae9ab1 commit fd9879f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand All @@ -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' );
Expand Down
22 changes: 11 additions & 11 deletions packages/block-editor/src/components/unit-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/hooks/line-height.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ class EditorProvider extends Component {
'__experimentalBlockDirectory',
'__experimentalBlockPatterns',
'__experimentalBlockPatternCategories',
'__experimentalDisableCustomUnits',
'__experimentalEnableCustomLineHeight',
'__experimentalEnableCustomSpacing',
'__experimentalEnableLegacyWidgetBlock',
'__experimentalEnableLinkColor',
Expand All @@ -135,6 +133,8 @@ class EditorProvider extends Component {
'disableCustomColors',
'disableCustomFontSizes',
'disableCustomGradients',
'enableCustomUnits',
'enableCustomLineHeight',
'focusMode',
'fontSizes',
'gradients',
Expand Down

0 comments on commit fd9879f

Please sign in to comment.