Last active
December 1, 2015 16:04
-
-
Save chrisburnell/890e30941098cd1b945f to your computer and use it in GitHub Desktop.
SCSS @mixin for choosing a `font-family` and optional `font-display`
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
/// @type List | |
$font-stack-primary: Georgia, serif !default; | |
/// @type List | |
$font-stack-secondary: Arial, sans-serif !default; | |
/// @type List | |
$font-stack-tertiary: Tahoma, sans-serif !default; | |
/// @type Map | |
/// @prop {String} key - Font Family name | |
/// @prop {Number} value - Font Family value | |
$font-families: ( | |
"primary": $font-stack-primary, | |
"secondary": $font-stack-secondary, | |
"tertiary": $font-stack-tertiary | |
} | |
/// | |
/// Specify font-family and associated font-display | |
/// | |
/// @param {String} $family - Font Family value | |
/// @param {String} $display - Font Display value | |
/// | |
/// @require {Variable} $font-families | |
/// | |
/// @example scss | |
/// @include font-family(primary); | |
/// // font-family: Georgia, serif; | |
/// | |
/// @example scss | |
/// @include font-family(secondary, swap); | |
/// // font-family: Arial, sans-serif; | |
/// // font-display: swap; | |
/// | |
/// @throw Error if no parameters are passed. | |
/// | |
@mixin font-family($family, $display) { | |
@if( length($family) == 0 ) { | |
@error "font-family() expects at least one parameter." | |
} | |
@if not map-has-key($font-families, $family) { | |
@error "There is no font-family named `#{$family}` in $font-families. Font Family should be one of #{map-keys($font-families)}."; | |
} | |
font-family: map-get($font-families, $family); | |
@if( length($display) != 0 ) { | |
font-display: $display; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment