-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use shared sass fluid function for About page (#209)
* Use shared sass fluid function for About page * Remove usage of custom properties for fluid defaults
- Loading branch information
1 parent
c044980
commit 1c2db51
Showing
3 changed files
with
55 additions
and
8 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
source/wp-content/themes/wporg-main-2022/src/style/_fluid.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// See https://www.smashingmagazine.com/2022/10/fluid-typography-clamp-sass-functions/ | ||
|
||
@use "sass:math"; | ||
@import "utilities"; | ||
|
||
// Default breakpoints based on parent theme `layout` widths | ||
/* stylelint-disable-next-line max-line-length */ | ||
// https://github.com/WordPress/wporg-parent-2021/blob/trunk/source/wp-content/themes/wporg-parent-2021/theme.json#L364 | ||
$default-min-bp: 600px; | ||
$default-max-bp: 1320px; // wide size + edge space * 2 | ||
|
||
@function fluid( | ||
$min-size, | ||
$max-size, | ||
$min-breakpoint: $default-min-bp, | ||
$max-breakpoint: $default-max-bp, | ||
$unit: vw | ||
) { | ||
$slope: math.div($max-size - $min-size, $max-breakpoint - $min-breakpoint); | ||
$slope-to-unit: round_to_decimals($slope * 100, 2); | ||
$intercept-rem: round_to_decimals(px_to_rem($min-size - $slope * $min-breakpoint), 2); | ||
$min-size-rem: round_to_decimals(px_to_rem($min-size), 2); | ||
$max-size-rem: round_to_decimals(px_to_rem($max-size), 2); | ||
|
||
@return clamp(#{$min-size-rem}, #{$slope-to-unit}#{$unit} + #{$intercept-rem}, #{$max-size-rem}); | ||
} |
20 changes: 20 additions & 0 deletions
20
source/wp-content/themes/wporg-main-2022/src/style/_utilities.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
@use "sass:math"; | ||
|
||
@function round_to_decimals($number, $decimals: 0) { | ||
$n: 1; | ||
|
||
@if $decimals > 0 { | ||
|
||
@for $i from 1 through $decimals { | ||
$n: $n * 10; | ||
} | ||
} | ||
|
||
@return math.div(math.round($number * $n), $n); | ||
} | ||
|
||
@function px_to_rem($px) { | ||
$rems: math.div($px, 16px) * 1rem; | ||
|
||
@return $rems; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters