Skip to content

Commit

Permalink
Use variables for typography
Browse files Browse the repository at this point in the history
  • Loading branch information
Studio384 committed Jul 22, 2022
1 parent 968959d commit aa274ac
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions scss/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
}
}

@mixin rfs($min-font-size, $max-font-size) {
@mixin rfs($min-font-size, $max-font-size, $heading) {
$rfs-min-vw-rem: calc((#{ $rfs-min-vw } / 16) * 1rem);
$rfs-rise: #{ $max-font-size - $min-font-size };
$rfs-run: calc((#{ $rfs-max-vw } / 16) - (#{ $rfs-min-vw } / 16));
Expand All @@ -53,5 +53,5 @@
$max-font-size-rem: calc(#{ $max-font-size } * 1rem);
$fluid-font-size-rem: calc(#{ $rfs-slope } * (100vw - #{ $rfs-min-vw-rem }) + #{ $min-font-size-rem });

font-size: clamp($min-font-size-rem, $fluid-font-size-rem, $max-font-size-rem);
--fs-#{$heading}: #{ clamp($min-font-size-rem, $fluid-font-size-rem, $max-font-size-rem) };
}
8 changes: 3 additions & 5 deletions scss/_typography.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// Heading, and heading classes
@each $heading, $font-size in $font-sizes-heading {
#{$heading} {
@include rfs(map-get($font-size, "min"), map-get($font-size, "max"));
font-size: var(--fs-#{$heading});
}
}

Expand Down Expand Up @@ -54,8 +54,7 @@

// Text
.lead {
@include rfs(map-get($font-size-lead, "min"), map-get($font-size-lead, "max"));

font-size: var(--fs-lead);
font-weight: 600;
}

Expand All @@ -67,8 +66,7 @@ small,
// Marketing classes
@each $marketing, $font-size in $font-sizes-marketing {
.marketing-#{$marketing} {
@include rfs(map-get($font-size, "min"), map-get($font-size, "max"));

font-size: var(--fs-m#{$marketing});
font-weight: 500;
}
}
Expand Down
10 changes: 10 additions & 0 deletions scss/_vars.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
--titlebar-top-safe-space: env(titlebar-area-y, 0);
--titlebar-height: env(titlebar-area-height, 33px);
--titlebar-width: env(titlebar-area-width, 100%);

@each $heading, $font-size in $font-sizes-heading {
@include rfs(map-get($font-size, "min"), map-get($font-size, "max"), $heading);
}

@each $marketing, $font-size in $font-sizes-marketing {
@include rfs(map-get($font-size, "min"), map-get($font-size, "max"), "m#{$marketing}");
}

@include rfs(map-get($font-size-lead, "min"), map-get($font-size-lead, "max"), "lead");
}

// Dark mode
Expand Down

0 comments on commit aa274ac

Please sign in to comment.