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

Allow disabling custom font sizes using theme.json config #25038

Merged
merged 2 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion lib/edit-site-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ function gutenberg_edit_site_init( $hook ) {

$settings = array(
'alignWide' => get_theme_support( 'align-wide' ),
'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ),
'imageSizes' => $available_image_sizes,
'isRTL' => is_rtl(),
'maxUploadFileSize' => $max_upload_size,
Expand Down
3 changes: 3 additions & 0 deletions lib/experimental-default-theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@
},
"gradient": {
"custom": true
},
"fontSize": {
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 think in other places we use font-size but it was inconsistent with other properties on the file, so I chose fontSize instead. cc @jorgefilipecosta

Copy link
Member

Choose a reason for hiding this comment

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

I think the only place we use kebab-case for this is in the font-size preset, for historical reasons. I agree we should update that as well and join team camelCase everywhere.

"custom": true
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,12 @@ function gutenberg_experimental_global_styles_get_editor_features( $config ) {
}
$features['global']['gradient']['custom'] = false;
}
if ( get_theme_support( 'disable-custom-font-sizes' ) ) {
if ( ! isset( $features['global']['fontSize'] ) ) {
$features['global']['fontSize'] = array();
}
$features['global']['fontSize']['custom'] = false;
}

return $features;
}
Expand Down Expand Up @@ -656,6 +662,7 @@ function gutenberg_experimental_global_styles_settings( $settings ) {
// Unsetting deprecated settings defined by Core.
unset( $settings['disableCustomColors'] );
unset( $settings['disableCustomGradients'] );
unset( $settings['disableCustomFontSizes'] );

return $settings;
}
Expand Down
1 change: 0 additions & 1 deletion lib/navigation-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ function gutenberg_navigation_init( $hook ) {
}

$settings = array(
'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ),
'imageSizes' => $available_image_sizes,
'isRTL' => is_rtl(),
'maxUploadFileSize' => $max_upload_size,
Expand Down
1 change: 0 additions & 1 deletion lib/widgets-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ function gutenberg_widgets_init( $hook ) {

$settings = array_merge(
array(
'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ),
'imageSizes' => $available_image_sizes,
'isRTL' => is_rtl(),
'maxUploadFileSize' => $max_upload_size,
Expand Down
1 change: 0 additions & 1 deletion packages/block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@ _Properties_
- _availableLegacyWidgets_ `Array`: Array of objects representing the legacy widgets available.
- _colors_ `Array`: Palette colors
- _fontSizes_ `Array`: Available font sizes
- _disableCustomFontSizes_ `boolean`: Whether or not the custom font sizes are disabled
- _imageEditing_ `boolean`: Image Editing settings set to false to disable.
- _imageSizes_ `Array`: Available image sizes
- _maxWidth_ `number`: Max width to constraint resizing
Expand Down
34 changes: 23 additions & 11 deletions packages/block-editor/src/components/font-sizes/font-size-picker.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
/**
* WordPress dependencies
*/
import { FontSizePicker } from '@wordpress/components';
import { withSelect } from '@wordpress/data';
import { FontSizePicker as BaseFontSizePicker } from '@wordpress/components';
import { useSelect } from '@wordpress/data';

export default withSelect( ( select ) => {
const { disableCustomFontSizes, fontSizes } = select(
'core/block-editor'
).getSettings();
/**
* Internal dependencies
*/
import useEditorFeature from '../use-editor-feature';

function FontSizePicker( props ) {
const fontSizes = useSelect(
( select ) => select( 'core/block-editor' ).getSettings().fontSizes,
[]
);
const disableCustomFontSizes = ! useEditorFeature( 'fontSize.custom' );

return (
<BaseFontSizePicker
{ ...props }
fontSizes={ fontSizes }
disableCustomFontSizes={ disableCustomFontSizes }
/>
);
}

return {
disableCustomFontSizes,
fontSizes,
};
} )( FontSizePicker );
export default FontSizePicker;
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const deprecatedFlags = {
settings.disableCustomGradients === undefined
? undefined
: ! settings.disableCustomGradients,
'fontSize.custom': ( settings ) =>
settings.disableCustomFontSizes === undefined
? undefined
: ! settings.disableCustomFontSizes,
};

/**
Expand Down
1 change: 0 additions & 1 deletion packages/block-editor/src/store/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export const PREFERENCES_DEFAULTS = {
* @property {Array} availableLegacyWidgets Array of objects representing the legacy widgets available.
* @property {Array} colors Palette colors
* @property {Array} fontSizes Available font sizes
* @property {boolean} disableCustomFontSizes Whether or not the custom font sizes are disabled
* @property {boolean} imageEditing Image Editing settings set to false to disable.
* @property {Array} imageSizes Available image sizes
* @property {number} maxWidth Max width to constraint resizing
Expand Down