Skip to content

Commit

Permalink
Allowing for an explicit false value in the fluid font size propert…
Browse files Browse the repository at this point in the history
…y to bypass fluid calculations for a specific font.
  • Loading branch information
ramonjd committed Jul 28, 2022
1 parent e3136a4 commit 0d2d286
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
4 changes: 4 additions & 0 deletions lib/block-supports/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ function gutenberg_get_typography_font_size_value( $preset, $should_use_fluid_ty
// Font sizes.
$fluid_font_size_settings = isset( $preset['fluid'] ) ? $preset['fluid'] : null;

if ( false === $fluid_font_size_settings ) {
return $preset['size'];
}

// Try to grab explicit min and max fluid font sizes.
$minimum_font_size_raw = isset( $fluid_font_size_settings['min'] ) ? $fluid_font_size_settings['min'] : null;
$maximum_font_size_raw = isset( $fluid_font_size_settings['max'] ) ? $fluid_font_size_settings['max'] : null;
Expand Down
26 changes: 22 additions & 4 deletions phpunit/block-supports/typography-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,24 @@ function test_gutenberg_get_typography_font_size_value( $font_size_preset, $shou
*/
public function data_generate_font_size_preset_fixtures() {
return array(
'default_return_value' => array(
'default_return_value' => array(
'font_size_preset' => array(
'size' => '28px',
),
'should_use_fluid_typography' => false,
'expected_output' => '28px',
),

'return_fluid_value' => array(
'default_return_value_when_fluid_is_false' => array(
'font_size_preset' => array(
'size' => '28px',
'fluid' => false,
),
'should_use_fluid_typography' => true,
'expected_output' => '28px',
),

'return_fluid_value' => array(
'font_size_preset' => array(
'size' => '1.75rem',
),
Expand All @@ -251,7 +260,16 @@ public function data_generate_font_size_preset_fixtures() {
'expected_output' => 'clamp(21px, 1.3125rem + ((1vw - 7.68px) * 2.524), 42px)',
),

'return_size_with_invalid_fluid_units' => array(
'return_default_fluid_values_with_null_value' => array(
'font_size_preset' => array(
'size' => '28px',
'fluid' => null,
),
'should_use_fluid_typography' => true,
'expected_output' => 'clamp(21px, 1.3125rem + ((1vw - 7.68px) * 2.524), 42px)',
),

'return_size_with_invalid_fluid_units' => array(
'font_size_preset' => array(
'size' => '10em',
'fluid' => array(
Expand All @@ -263,7 +281,7 @@ public function data_generate_font_size_preset_fixtures() {
'expected_output' => '10em',
),

'return_fluid_clamp_value' => array(
'return_fluid_clamp_value' => array(
'font_size_preset' => array(
'size' => '28px',
'fluid' => array(
Expand Down
3 changes: 2 additions & 1 deletion schemas/json/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@
"type": "string"
},
"fluid": {
"type": "object",
"description": "Specifics the minimum and maximum font size value of a fluid font size. Set to `false` to bypass fluid calculations and use the static `size` value.",
"type": [ "object", "boolean" ],
"properties": {
"min": {
"description": "A min font size for fluid font size calculations in px, rem or em.",
Expand Down

0 comments on commit 0d2d286

Please sign in to comment.