diff --git a/src/styles/_mixins.scss b/src/styles/_mixins.scss index a9579f7f..83f8b58e 100644 --- a/src/styles/_mixins.scss +++ b/src/styles/_mixins.scss @@ -2,6 +2,42 @@ /* GLOBAL MIXINS --------------------------------------------- */ +/* AUTO SCALING FOR TYPE WITH MIN/MAX SIZES + + @param {Number} $responsive - Viewport-based size + @param {Number} $min - Minimum font size (px) + @param {Number} $max - Maximum font size (px) (optional) + + @param {Number} $fallback - Fallback for viewport-based units (optional) + + @example SCSS - 5vw size, 35px min & 150px max size + 50px fallback: + + @include responsive-font(5vw, 35px, 150px, 50px); +*/ +@mixin responsive-font($responsive, $min, $max: false, $fallback: false) { + $responsive-unitless: $responsive / ($responsive - $responsive + 1); + $dimension: if(unit($responsive) == 'vh', 'height', 'width'); + $min-breakpoint: $min / $responsive-unitless * 100; + + @media (max-#{$dimension}: #{$min-breakpoint}) { + font-size: $min; + } + + @if $max { + $max-breakpoint: $max / $responsive-unitless * 100; + + @media (min-#{$dimension}: #{$max-breakpoint}) { + font-size: $max; + } + } + + @if $fallback { + font-size: $fallback; + } + + font-size: $responsive; +} + // Reset @mixin reset { box-sizing: border-box;