Skip to content

Commit d3d6e4b

Browse files
committed
refactor(f-fluid-size): enhance fluid typography function to support growing and shrinking scales
1 parent ce60c30 commit d3d6e4b

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
@use "../01-abstract/variables" as *;
2+
@use "f-strip-units" as *;
3+
14
/**
25
* Fluid size
36
*
47
* Converted from source: : https://www.aleksandrhovhannisyan.com/blog/fluid-type-scale-with-css-clamp/
58
*
6-
* Convert value px to fluid typography and spacing using clamp
9+
* Convert value px to fluid typography and spacing using clamp.
10+
* Supports both growing and shrinking scales between breakpoints.
711
*
812
* @author Cédric Andrietti
913
*
10-
* @param $min -> Minimal display size (mobile)
11-
* @param $max -> Maximal display size (Desktop)
14+
* @param $from -> Size at the start breakpoint (mobile)
15+
* @param $to -> Size at the end breakpoint (desktop)
1216
* @param $start -> Start breakpoint
1317
* @param $end -> End breakpoint
1418
*
@@ -19,16 +23,21 @@
1923
* line-height: #{fluid-size(1.05, 1.2)};
2024
* }
2125
*
26+
* // Larger on mobile, smaller on desktop
27+
* .hero {
28+
* padding-top: #{fluid-size(40px, 3px)};
29+
* }
30+
*
2231
*/
2332

2433
@use "sass:map";
2534
@use "sass:math";
26-
@use "../00-variables/config" as *;
27-
@use "../02-functions/strip-units" as *;
2835

29-
@function fluid-size($min, $max, $start: 7xs, $end: md) {
36+
@function fluid-size($from, $to, $start: xs, $end: l) {
3037
$start: math.div(map.get($breakpoints, $start), 100);
3138
$end: math.div(map.get($breakpoints, $end), 100);
39+
$lower: math.min($from, $to);
40+
$upper: math.max($from, $to);
3241

33-
@return clamp(#{$min}, #{$min} + (1vw - #{$start}px) / #{$end - $start} * #{strip-units($max - $min)}, #{$max});
42+
@return clamp(#{$lower}, #{$from} + (1vw - #{$start}px) / #{$end - $start} * #{strip-units($to - $from)}, #{$upper});
3443
}

0 commit comments

Comments
 (0)