Skip to content

Commit e0df54a

Browse files
committed
refactor(f-fluid-size): enhance fluid typography function to support growing and shrinking scales
Updated the fluid-size function parameters for clarity and added support for both growing and shrinking scales between breakpoints. Improved documentation for better understanding of the function's usage.
1 parent 61ea8fe commit e0df54a

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

‎src/scss/02-tools/_f-fluid-size.scss‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
*
77
* Converted from source: : https://www.aleksandrhovhannisyan.com/blog/fluid-type-scale-with-css-clamp/
88
*
9-
* 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.
1011
*
1112
* @author Cédric Andrietti
1213
*
13-
* @param $min -> Minimal display size (mobile)
14-
* @param $max -> Maximal display size (Desktop)
14+
* @param $from -> Size at the start breakpoint (mobile)
15+
* @param $to -> Size at the end breakpoint (desktop)
1516
* @param $start -> Start breakpoint
1617
* @param $end -> End breakpoint
1718
*
@@ -22,14 +23,21 @@
2223
* line-height: #{fluid-size(1.05, 1.2)};
2324
* }
2425
*
26+
* // Larger on mobile, smaller on desktop
27+
* .hero {
28+
* padding-top: #{fluid-size(40px, 3px)};
29+
* }
30+
*
2531
*/
2632

2733
@use "sass:map";
2834
@use "sass:math";
2935

30-
@function fluid-size($min, $max, $start: xs, $end: sm) {
36+
@function fluid-size($from, $to, $start: xs, $end: l) {
3137
$start: math.div(map.get($breakpoints, $start), 100);
3238
$end: math.div(map.get($breakpoints, $end), 100);
39+
$lower: math.min($from, $to);
40+
$upper: math.max($from, $to);
3341

34-
@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});
3543
}

0 commit comments

Comments
 (0)