Skip to content

Instantly share code, notes, and snippets.

@mjbondra
Last active December 30, 2015 01:49
Show Gist options
  • Save mjbondra/7759035 to your computer and use it in GitHub Desktop.
Save mjbondra/7759035 to your computer and use it in GitHub Desktop.
////////////
// MIXINS //
////////////
/*------------------------------------*\
FONTS
\*------------------------------------*/
/*--General--*/
/**
* @mixin font-details
*
* Font mixin designed for easily adding individual attributes,
* without including those that are unneccesary or unstated.
*
* Priority is given to size and color, though any attribute can
* be targeted through the use of the 'null' value.
*
* Example: font-weight: 300 and line-height: 1
* @include font-details(null, null, 300, 1);
*
* @param $size {value} - <absolute-size> | <relative-size> | <length> | <percentage> | inherit
* @param $color {value} - <color> | inherit
* @param $weight {value} - normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
* @param $height {value} - normal | <number> | <length> | <percentage>
* @param $style {value} - normal | italic | oblique
* @param $family {value} - [<family-name> | <generic-family>] | inherit
* @returns {declarations}
*/
@mixin font-details($size: null, $color: null, $weight: null, $height: null, $style: null, $family: null) {
@if $family != null {
@if $height != null {
@if $size != null {
font: $style $weight #{$size}/#{$height} $family; // this will work even if $weight or $style == null
} @else {
font-family: $family;
line-height: $height;
@if $weight != null {
font-weight: $weight;
}
@if $style != null {
font-style: $style;
}
}
} @else {
@if $size != null {
font: $style $weight $size $family; // this will work even if $weight or $style == null
} @else {
font-family: $family;
@if $weight != null {
font-weight: $weight;
}
@if $style != null {
font-style: $style;
}
}
}
} @else {
@if $size != null {
font-size: $size;
}
@if $weight != null {
font-weight: $weight;
}
@if $height != null {
line-height: $height;
}
@if $style != null {
font-style: $style;
}
}
@if $color != null {
color: $color;
}
}
/*--Specific--*/
/**
* The following mixins are subsets of the font-details mixin,
* differentiated by the fact that they are populated with
* specific font-families, and do not accept a $family parameter
*/
@mixin enzo($size: null, $color: null, $weight: null, $height: null, $style: null) {
$family: "ff-enzo-web", sans-serif;
@include font-details($size, $color, $weight, $height, $style, $family);
}
@mixin meta-serif($size: null, $color: null, $weight: null, $height: null, $style: null) {
$family: "ff-meta-serif-web-pro", serif;
@include font-details($size, $color, $weight, $height, $style, $family);
}
@mixin more-pro($size: null, $color: null, $weight: null, $height: null, $style: null) {
$family: "ff-more-web-pro", serif;
@include font-details($size, $color, $weight, $height, $style, $family);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment