Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/rfs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartijn Cuppens <martijn.cuppens@gmail.com>2019-03-04 23:57:16 +0300
committerGitHub <noreply@github.com>2019-03-04 23:57:16 +0300
commit4973057bb39bd33e4f4d903bc88f8d674a22dcc4 (patch)
tree9e7308acb25f837a8bb5b7870119e10157e0f36d
parent32cbc79faecf2d3c76061f2e90618b1b3abf53e4 (diff)
Scss rewrite (#105)
-rw-r--r--scss.scss168
1 files changed, 75 insertions, 93 deletions
diff --git a/scss.scss b/scss.scss
index 497e07e..43f19ca 100644
--- a/scss.scss
+++ b/scss.scss
@@ -2,9 +2,9 @@
// SCSS RFS mixin
//
-// Automated font-resizing
+// Automated responsive font sizes
//
-// See https://github.com/twbs/rfs
+// Licensed under MIT (https://github.com/twbs/rfs/blob/master/LICENSE)
// Configuration
@@ -12,11 +12,19 @@
$rfs-base-font-size: 1.25rem !default;
$rfs-font-size-unit: rem !default;
+@if $rfs-font-size-unit != rem and $rfs-font-size-unit != px {
+ @error "`#{$rfs-font-size-unit}` is not a valid unit for $rfs-font-size-unit. Use `px` or `rem`.";
+}
+
// Breakpoint at where font-size starts decreasing if screen width is smaller
$rfs-breakpoint: 1200px !default;
$rfs-breakpoint-unit: px !default;
-// Resize font-size based on screen height and width
+@if $rfs-breakpoint-unit != px and $rfs-breakpoint-unit != em and $rfs-breakpoint-unit != rem {
+ @error "`#{$rfs-breakpoint-unit}` is not a valid unit for $rfs-breakpoint-unit. Use `px`, `em` or `rem`.";
+}
+
+// Resize font size based on screen height and width
$rfs-two-dimensional: false !default;
// Factor of decrease
@@ -60,7 +68,49 @@ $rfs-breakpoint-unit-cache: unit($rfs-breakpoint);
$rfs-breakpoint: $rfs-breakpoint / ($rfs-breakpoint * 0 + 1 / $rfs-rem-value);
}
-// Responsive font-size mixin
+// Internal mixin that adds disable classes to the selector if needed.
+@mixin _rfs-disable-class {
+ @if $rfs-class == "disable" {
+ // Adding an extra class increases specificity, which prevents the media query to override the font size
+ &,
+ .disable-responsive-font-size &,
+ &.disable-responsive-font-size {
+ @content;
+ }
+ }
+ @else {
+ @content;
+ }
+}
+
+// Internal mixin that adds enable classes to the selector if needed.
+@mixin _rfs-enable-class {
+ @if $rfs-class == "enable" {
+ .enable-responsive-font-size &,
+ &.enable-responsive-font-size {
+ @content;
+ }
+ }
+ @else {
+ @content;
+ }
+}
+
+// Internal mixin used to determine which media query needs to be used
+@mixin _rfs-media-query($mq-value) {
+ @if $rfs-two-dimensional {
+ @media (max-width: #{$mq-value}), (max-height: #{$mq-value}) {
+ @content;
+ }
+ }
+ @else {
+ @media (max-width: #{$mq-value}) {
+ @content;
+ }
+ }
+}
+
+// Responsive font size mixin
@mixin rfs($fs, $important: false) {
// Cache $fs unit
$fs-unit: if(type-of($fs) == "number", unit($fs), false);
@@ -73,11 +123,7 @@ $rfs-breakpoint-unit-cache: unit($rfs-breakpoint);
font-size: #{$fs}#{$rfs-suffix};
}
@else {
- // Variables for storing static and fluid rescaling
- $rfs-static: null;
- $rfs-fluid: null;
-
- // Remove px-unit from $fs for calculations
+ // Remove unit from $fs for calculations
@if $fs-unit == "px" {
$fs: $fs / ($fs * 0 + 1);
}
@@ -85,116 +131,52 @@ $rfs-breakpoint-unit-cache: unit($rfs-breakpoint);
$fs: $fs / ($fs * 0 + 1 / $rfs-rem-value);
}
- // Set default font-size
- @if $rfs-font-size-unit == rem {
- $rfs-static: #{$fs / $rfs-rem-value}rem#{$rfs-suffix};
- }
- @else if $rfs-font-size-unit == px {
- $rfs-static: #{$fs}px#{$rfs-suffix};
+ // Set default font size
+ $rfs-static: if($rfs-font-size-unit == rem, #{$fs / $rfs-rem-value}rem, #{$fs}px);
+
+ // Only add the media query if the font size is bigger than the minimum font size
+ @if $fs <= $rfs-base-font-size or not $enable-responsive-font-sizes {
+ font-size: #{$rfs-static}#{$rfs-suffix};
}
@else {
- @error "`#{$rfs-font-size-unit}` is not a valid unit for $rfs-font-size-unit. Use `px` or `rem`.";
- }
-
- // Only add media query if font-size is bigger as the minimum font-size
- // If $rfs-factor == 1, no rescaling will take place
- @if $fs > $rfs-base-font-size and $enable-responsive-font-sizes {
- $min-width: null;
- $variable-unit: null;
-
- // Calculate minimum font-size for given font-size
+ // Calculate the minimum font size for $fs
$fs-min: $rfs-base-font-size + ($fs - $rfs-base-font-size) / $rfs-factor;
- // Calculate difference between given font-size and minimum font-size for given font-size
+ // Calculate difference between $fs and the minimum font size
$fs-diff: $fs - $fs-min;
// Base font-size formatting
- // No need to check if the unit is valid, because we did that before
$min-width: if($rfs-font-size-unit == rem, #{$fs-min / $rfs-rem-value}rem, #{$fs-min}px);
- // If two-dimensional, use smallest of screen width and height
+ // Use `vmin` if two-dimensional is enabled
$variable-unit: if($rfs-two-dimensional, vmin, vw);
// Calculate the variable width between 0 and $rfs-breakpoint
$variable-width: #{$fs-diff * 100 / $rfs-breakpoint}#{$variable-unit};
- // Set the calculated font-size.
+ // Set the calculated font-size
$rfs-fluid: calc(#{$min-width} + #{$variable-width}) #{$rfs-suffix};
- }
- // Rendering
- @if $rfs-fluid == null {
- // Only render static font-size if no fluid font-size is available
- font-size: $rfs-static;
- }
- @else {
- $mq-value: null;
+ // Breakpoint formatting
+ $mq-value: if($rfs-breakpoint-unit == px, #{$rfs-breakpoint}px, #{$rfs-breakpoint / $rfs-rem-value}#{$rfs-breakpoint-unit});
- // RFS breakpoint formatting
- @if $rfs-breakpoint-unit == em or $rfs-breakpoint-unit == rem {
- $mq-value: #{$rfs-breakpoint / $rfs-rem-value}#{$rfs-breakpoint-unit};
- }
- @else if $rfs-breakpoint-unit == px {
- $mq-value: #{$rfs-breakpoint}px;
- }
- @else {
- @error "`#{$rfs-breakpoint-unit}` is not a valid unit for $rfs-breakpoint-unit. Use `px`, `em` or `rem`.";
+ @include _rfs-disable-class {
+ font-size: #{$rfs-static}#{$rfs-suffix};
}
- @if $rfs-class == "disable" {
- // Adding an extra class increases specificity,
- // which prevents the media query to override the font size
- &,
- .disable-responsive-font-size &,
- &.disable-responsive-font-size {
- font-size: $rfs-static;
+ @include _rfs-media-query($mq-value) {
+ @include _rfs-enable-class {
+ font-size: $rfs-fluid;
}
- }
- @else {
- font-size: $rfs-static;
- }
- @if $rfs-two-dimensional {
- @media (max-width: #{$mq-value}), (max-height: #{$mq-value}) {
- @if $rfs-class == "enable" {
- .enable-responsive-font-size &,
- &.enable-responsive-font-size {
- font-size: $rfs-fluid;
- }
- }
- @else {
- font-size: $rfs-fluid;
- }
-
- @if $rfs-safari-iframe-resize-bug-fix {
- // stylelint-disable-next-line length-zero-no-unit
- min-width: 0vw;
- }
- }
- }
- @else {
- @media (max-width: #{$mq-value}) {
- @if $rfs-class == "enable" {
- .enable-responsive-font-size &,
- &.enable-responsive-font-size {
- font-size: $rfs-fluid;
- }
- }
- @else {
- font-size: $rfs-fluid;
- }
-
- @if $rfs-safari-iframe-resize-bug-fix {
- // stylelint-disable-next-line length-zero-no-unit
- min-width: 0vw;
- }
- }
+ // Include safari iframe resize fix if needed
+ min-width: if($rfs-safari-iframe-resize-bug-fix, (0 * 1vw), null);
}
}
}
}
-// The font-size & responsive-font-size mixin uses RFS to rescale font sizes
+// The font-size & responsive-font-size mixins use RFS to rescale the font size
@mixin font-size($fs, $important: false) {
@include rfs($fs, $important);
}