Compare commits

...

1 Commits

Author SHA1 Message Date
Liam DeBeasi
86c5f3555e chore(css): remove unit option from font scaling utils 2024-03-25 16:05:31 -04:00

View File

@@ -1,18 +1,19 @@
@use "sass:math";
$baselineSize: 16px !default;
$baselineUnit: 1rem !default;
/**
* Convert a font size to a dynamic font size.
* Fonts that participate in Dynamic Type should use
* dynamic font sizes.
* @param size - The initial font size including the unit (i.e. px or pt)
* @param unit (optional) - The unit to convert to. Use this if you want to
* convert to a unit other than $baselineUnit.
*/
@function dynamic-font($size, $unit: $baselineUnit) {
@return (math.div($size, $baselineSize)) * $unit;
@function dynamic-font($size) {
/**
* Multiplying by 1rem appends the rem unit to the number while keeping the number unaltered.
* Example: 1.25 * 1rem = 1.25rem
*/
@return (math.div($size, $baselineSize)) * 1rem;
}
/**
@@ -20,11 +21,9 @@ $baselineUnit: 1rem !default;
* a maximum font size.
* @param size - The initial font size including the unit (i.e. px or pt)
* @param maxScale - The maximum scale of the font (i.e. 2.5 for a maximum 250% scale).
* @param unit (optional) - The unit to convert the initial font size to. Use this if you want to
* convert to a unit other than $baselineUnit.
*/
@function dynamic-font-max($size, $maxScale, $unit: $baselineUnit) {
$baseScale: dynamic-font($size, $unit);
@function dynamic-font-max($size, $maxScale) {
$baseScale: dynamic-font($size);
$maxScale: $size * $maxScale;
@return min($baseScale, $maxScale);
@@ -35,11 +34,10 @@ $baselineUnit: 1rem !default;
* a minimum font size.
* @param size - The initial font size including the unit (i.e. px or pt)
* @param minScale - The minimum scale of the font (i.e. 0.8 for a minimum 80% scale).
* @param unit (optional) - The unit to convert the initial font size to. Use this if you want to
* convert to a unit other than $baselineUnit.
*/
@function dynamic-font-min($minScale, $size, $unit: $baselineUnit) {
$baseScale: dynamic-font($size, $unit);
@function dynamic-font-min($minScale, $size) {
$baseScale: dynamic-font($size);
$minScale: $size * $minScale;
@return max($minScale, $baseScale);
@@ -51,11 +49,9 @@ $baselineUnit: 1rem !default;
* @param size - The initial font size including the unit (i.e. px or pt)
* @param minScale - The minimum scale of the font (i.e. 0.8 for a minimum 80% scale).
* @param maxScale - The maximum scale of the font (i.e. 2.5 for a maximum 250% scale).
* @param unit (optional) - The unit to convert the initial font size to. Use this if you want to
* convert to a unit other than $baselineUnit.
*/
@function dynamic-font-clamp($minScale, $baseSize, $maxScale, $unit: $baselineUnit) {
$baseScale: dynamic-font($baseSize, $unit);
@function dynamic-font-clamp($minScale, $baseSize, $maxScale) {
$baseScale: dynamic-font($baseSize);
$maxScale: $baseSize * $maxScale;
$minScale: $baseSize * $minScale;