Skip to content

Commit

Permalink
adds new mixin partial and includes updated strip-unit, em(), rem() a…
Browse files Browse the repository at this point in the history
…nd new line height mixins for use with Bourbon 5 (#254)
  • Loading branch information
jomurgel authored and gregrickaby committed Mar 28, 2017
1 parent 03f518f commit 8534ddb
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 3 deletions.
69 changes: 69 additions & 0 deletions assets/sass/utilities/mixins/_units-of-measure.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//--------------------------------------------------------------
// Size Conversion SCSS Mixins
//--------------------------------------------------------------

//-----------------------------------------
// Strip Units Forked from Bourbon 4 https://github.com/thoughtbot/bourbon/blob/v4-stable/app/assets/stylesheets/functions/_strip-units.scss
//-----------------------------------------
@function strip-unit($number) {
@if type-of($number) == "number" and not unitless($number) {
@return $number / ($number * 0 + 1);
}

@return $number;
}

//-----------------------------------------
// PX to EM Forked from Bourbon 4 https://github.com/thoughtbot/bourbon/blob/v4-stable/app/assets/stylesheets/functions/_px-to-em.scss
// Usage em(12) — defaults context to 16
// Usage em(12, 16) = same as above.
//-----------------------------------------
@function em($pixelvalue, $context: $base-context) {

@if not unitless($pixelvalue) {
$pixelvalue: strip-units($pixelvalue);
}

@if not unitless($context) {
$base: strip-units($context);
}

@return ($pixelvalue / $base-context) * 1em;
}


//-----------------------------------------
// PX to REM Forked from Bourbon 4 https://github.com/thoughtbot/bourbon/blob/v4-stable/app/assets/stylesheets/functions/_px-to-rem.scss
// Usage em(12) — defaults context to 16
// Usage em(12, 16) = same as above.
//-----------------------------------------
@function rem($pixelvalue, $context: $base-context) {

@if not unitless($pixelvalue) {
$pixelvalue: strip-units($pixelvalue);
}

@if not unitless($context) {
$base: strip-units($context);
}

@return ($pixelvalue / $base-context) * 1rem;
}

//-----------------------------------------
// Unitless Line Height
// Usage lh(12) = lh(12,12) = 1
// Usage lh(24, 12) = 2
//-----------------------------------------
@function lh($font-size, $line-height: $font-size) {

@if not unitless($font-size) {
$font-size: strip-units($font-size);
}

@if not unitless($line-height) {
$line-height: strip-units($line-height);
}

@return $font-size / $line-height;
}
7 changes: 4 additions & 3 deletions assets/sass/utilities/mixins/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
@import "margin-auto";
@import "margin-padding-reset";
@import "omega-reset";
@import "word-break";
@import "z-index";
@import "reverse-list";
@import "vertical-align";
@import "units-of-measure";
@import "vertical-align";
@import "word-break";
@import "z-index";

0 comments on commit 8534ddb

Please sign in to comment.