-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fluid Typography: Try adding a ceiling to the calculated minimum font size #49247
Changes from 4 commits
357f5ad
519eba4
6fdd51f
72a5feb
09ad429
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -516,6 +516,14 @@ function gutenberg_get_typography_font_size_value( $preset, $should_use_fluid_ty | |
) | ||
); | ||
|
||
// Sets a ceiling for the minimum font size. | ||
$minimum_font_size_ceiling = gutenberg_get_typography_value_and_unit( | ||
'64px', | ||
array( | ||
'coerce_to' => $preferred_size['unit'], | ||
) | ||
); | ||
|
||
// Don't enforce minimum font size if a font size has explicitly set a min and max value. | ||
if ( ! empty( $minimum_font_size_limit ) && ( ! $minimum_font_size_raw && ! $maximum_font_size_raw ) ) { | ||
/* | ||
|
@@ -540,6 +548,12 @@ function gutenberg_get_typography_font_size_value( $preset, $should_use_fluid_ty | |
if ( ! $minimum_font_size_raw ) { | ||
$calculated_minimum_font_size = round( $preferred_size['value'] * $default_minimum_font_size_factor, 3 ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah linear doesn't appear to cut it. Maybe we need a plot a growth curve so that I'm no expert by the way, but I can try to play around with equations to see if we can get a good fit. Simple exponential growth seems to work okay as well, e.g.,
It seems to scale better when the scale factor is bumped from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Oh, very cool idea! Feel free to commit to this branch or fork if you think it'd help for us to have multiple approaches on the go. I reckon a non-linear curve is a good thing to try out 👍 I should have a bit of time before the end of the week to have a play with this if you don't beat me to it! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! I'll have a play this week. 🍺 |
||
|
||
// Ensure calculated minimum font size is not greater than the ceiling. | ||
// This is to prevent the font size from being too large in smaller viewports. | ||
if ( $calculated_minimum_font_size > $minimum_font_size_ceiling['value'] ) { | ||
$calculated_minimum_font_size = $minimum_font_size_ceiling['value']; | ||
} | ||
|
||
// Only use calculated min font size if it's > $minimum_font_size_limit value. | ||
if ( ! empty( $minimum_font_size_limit ) && $calculated_minimum_font_size <= $minimum_font_size_limit['value'] ) { | ||
$minimum_font_size_raw = $minimum_font_size_limit['value'] . $minimum_font_size_limit['unit']; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think this could be added up near the default var declarations? E.g.,
$minimum_font_size_ceiling = '64px';
?That way we can open it up for theme.json config later (if we decide that's a good thing to do of course!)