Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new em() and rem() mixins along with lh() (unitless line height) #254

Merged
merged 2 commits into from
Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";