From e3ac83254a071622fd20eb3a7c8c69d962b82a13 Mon Sep 17 00:00:00 2001 From: ramonjd Date: Thu, 28 Jul 2022 15:27:47 +1000 Subject: [PATCH] Updating site editor presets --- lib/block-supports/typography.php | 1 + .../global-styles/test/typography-utils.js | 25 +++++++++++++++++++ .../global-styles/typography-utils.js | 5 ++++ 3 files changed, 31 insertions(+) diff --git a/lib/block-supports/typography.php b/lib/block-supports/typography.php index d5e35f40fb4851..8cfeda2b0641b5 100644 --- a/lib/block-supports/typography.php +++ b/lib/block-supports/typography.php @@ -378,6 +378,7 @@ function gutenberg_get_typography_font_size_value( $preset, $should_use_fluid_ty // Font sizes. $fluid_font_size_settings = isset( $preset['fluid'] ) ? $preset['fluid'] : null; + // A font size has explicitly bypassed fluid calculations. if ( false === $fluid_font_size_settings ) { return $preset['size']; } diff --git a/packages/edit-site/src/components/global-styles/test/typography-utils.js b/packages/edit-site/src/components/global-styles/test/typography-utils.js index 2306e61522f07e..cbc0fe53a3390d 100644 --- a/packages/edit-site/src/components/global-styles/test/typography-utils.js +++ b/packages/edit-site/src/components/global-styles/test/typography-utils.js @@ -15,6 +15,17 @@ describe( 'typography utils', () => { typographySettings: undefined, expected: '28px', }, + // Should return non-fluid value when fluid is `false`. + { + preset: { + size: '28px', + fluid: false, + }, + typographySettings: { + fluid: true, + }, + expected: '28px', + }, // Should return fluid value. { preset: { @@ -38,6 +49,20 @@ describe( 'typography utils', () => { expected: 'clamp(21px, 1.3125rem + ((1vw - 7.68px) * 2.524), 42px)', }, + + // Should return default fluid values with null values. + { + preset: { + size: '28px', + fluid: null, + }, + typographySettings: { + fluid: true, + }, + expected: + 'clamp(21px, 1.3125rem + ((1vw - 7.68px) * 2.524), 42px)', + }, + // Should return size with invalid fluid units. { preset: { diff --git a/packages/edit-site/src/components/global-styles/typography-utils.js b/packages/edit-site/src/components/global-styles/typography-utils.js index 53c782da0697af..464021dfa0b9fc 100644 --- a/packages/edit-site/src/components/global-styles/typography-utils.js +++ b/packages/edit-site/src/components/global-styles/typography-utils.js @@ -35,6 +35,11 @@ export function getTypographyFontSizeValue( preset, typographySettings ) { const DEFAULT_SCALE_FACTOR = 1; // Font sizes. + // A font size has explicitly bypassed fluid calculations. + if ( false === preset?.fluid ) { + return defaultSize; + } + const fluidFontSizeSettings = preset?.fluid || {}; // Try to grab explicit min and max fluid font sizes.