forked from JosephusPaye/Keen-UI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add $base-font-size variable, and util for switching to rems
- Loading branch information
1 parent
62792a1
commit 88b4251
Showing
4 changed files
with
79 additions
and
6 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
@import 'variables'; | ||
@import 'mixins'; | ||
@import 'util'; |
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,65 @@ | ||
// Adapted from Foundation | ||
// (https://raw.githubusercontent.com/zurb/foundation-sites/develop/scss/util/_unit.scss) | ||
|
||
// Removes the unit (e.g. px, em, rem) from a value, returning the number only. | ||
@function strip-unit($num) { | ||
@return $num / ($num * 0 + 1); | ||
} | ||
|
||
// Converts one or more pixel values into matching rem values. | ||
@function rem-calc($values, $base: null) { | ||
$rem-values: (); | ||
$count: length($values); | ||
|
||
// If no base is defined, defer to the global font size | ||
@if $base == null { | ||
$base: $base-font-size; | ||
} | ||
|
||
// If the base font size is a %, then multiply it by 16px | ||
// This is because 100% font size = 16px in most all browsers | ||
@if unit($base) == '%' { | ||
$base: ($base / 100%) * 16px; | ||
} | ||
|
||
// Using rem as base allows correct scaling | ||
@if unit($base) == 'rem' { | ||
$base: strip-unit($base) * 16px; | ||
} | ||
|
||
@if $count == 1 { | ||
@return -zf-to-rem($values, $base); | ||
} | ||
|
||
@for $i from 1 through $count { | ||
$rem-values: append($rem-values, -zf-to-rem(nth($values, $i), $base)); | ||
} | ||
|
||
@return $rem-values; | ||
} | ||
|
||
// Converts a pixel value to matching rem value. *Any* value passed, regardless of unit, is assumed to be a pixel value. By default, the base pixel value used to calculate the rem value is taken from the `$base-font-size` variable. | ||
@function -zf-to-rem($value, $base: null) { | ||
// Check if the value is a number | ||
@if type-of($value) != 'number' { | ||
@warn inspect($value) + ' was passed to rem-calc(), which is not a number.'; | ||
@return $value; | ||
} | ||
|
||
// Transform em into rem if someone hands over 'em's | ||
@if unit($value) == 'em' { | ||
$value: strip-unit($value) * 1rem; | ||
} | ||
|
||
// Calculate rem if units for $value is not rem or em | ||
@if unit($value) != 'rem' { | ||
$value: strip-unit($value) / strip-unit($base) * 1rem; | ||
} | ||
|
||
// Turn 0rem into 0 | ||
@if $value == 0rem { | ||
$value: 0; | ||
} | ||
|
||
@return $value; | ||
} |
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