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 line height and custom units theme support flags consistent #23964

Merged
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
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' );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was hesitant whether to call this "line-height" or "custom-line-height" I went with custom for consistency with other theme support flags (units, spacing).

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