Skip to content

Commit 56c095d

Browse files
committed
Bring in latest from RFS v8.x
1 parent 3e13bb8 commit 56c095d

File tree

1 file changed

+75
-93
lines changed

1 file changed

+75
-93
lines changed

scss/vendor/_rfs.scss

Lines changed: 75 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,29 @@
22

33
// SCSS RFS mixin
44
//
5-
// Automated font-resizing
5+
// Automated responsive font sizes
66
//
7-
// See https://github.com/twbs/rfs
7+
// Licensed under MIT (https://github.com/twbs/rfs/blob/v8.x/LICENSE)
88

99
// Configuration
1010

1111
// Base font size
1212
$rfs-base-font-size: 1.25rem !default;
1313
$rfs-font-size-unit: rem !default;
1414

15+
@if $rfs-font-size-unit != rem and $rfs-font-size-unit != px {
16+
@error "`#{$rfs-font-size-unit}` is not a valid unit for $rfs-font-size-unit. Use `px` or `rem`.";
17+
}
18+
1519
// Breakpoint at where font-size starts decreasing if screen width is smaller
1620
$rfs-breakpoint: 1200px !default;
1721
$rfs-breakpoint-unit: px !default;
1822

19-
// Resize font-size based on screen height and width
23+
@if $rfs-breakpoint-unit != px and $rfs-breakpoint-unit != em and $rfs-breakpoint-unit != rem {
24+
@error "`#{$rfs-breakpoint-unit}` is not a valid unit for $rfs-breakpoint-unit. Use `px`, `em` or `rem`.";
25+
}
26+
27+
// Resize font size based on screen height and width
2028
$rfs-two-dimensional: false !default;
2129

2230
// Factor of decrease
@@ -60,7 +68,49 @@ $rfs-breakpoint-unit-cache: unit($rfs-breakpoint);
6068
$rfs-breakpoint: $rfs-breakpoint / ($rfs-breakpoint * 0 + 1 / $rfs-rem-value);
6169
}
6270

63-
// Responsive font-size mixin
71+
// Internal mixin that adds disable classes to the selector if needed.
72+
@mixin _rfs-disable-class {
73+
@if $rfs-class == "disable" {
74+
// Adding an extra class increases specificity, which prevents the media query to override the font size
75+
&,
76+
.disable-responsive-font-size &,
77+
&.disable-responsive-font-size {
78+
@content;
79+
}
80+
}
81+
@else {
82+
@content;
83+
}
84+
}
85+
86+
// Internal mixin that adds enable classes to the selector if needed.
87+
@mixin _rfs-enable-class {
88+
@if $rfs-class == "enable" {
89+
.enable-responsive-font-size &,
90+
&.enable-responsive-font-size {
91+
@content;
92+
}
93+
}
94+
@else {
95+
@content;
96+
}
97+
}
98+
99+
// Internal mixin used to determine which media query needs to be used
100+
@mixin _rfs-media-query($mq-value) {
101+
@if $rfs-two-dimensional {
102+
@media (max-width: #{$mq-value}), (max-height: #{$mq-value}) {
103+
@content;
104+
}
105+
}
106+
@else {
107+
@media (max-width: #{$mq-value}) {
108+
@content;
109+
}
110+
}
111+
}
112+
113+
// Responsive font size mixin
64114
@mixin rfs($fs, $important: false) {
65115
// Cache $fs unit
66116
$fs-unit: if(type-of($fs) == "number", unit($fs), false);
@@ -73,128 +123,60 @@ $rfs-breakpoint-unit-cache: unit($rfs-breakpoint);
73123
font-size: #{$fs}#{$rfs-suffix};
74124
}
75125
@else {
76-
// Variables for storing static and fluid rescaling
77-
$rfs-static: null;
78-
$rfs-fluid: null;
79-
80-
// Remove px-unit from $fs for calculations
126+
// Remove unit from $fs for calculations
81127
@if $fs-unit == "px" {
82128
$fs: $fs / ($fs * 0 + 1);
83129
}
84130
@else if $fs-unit == "rem" {
85131
$fs: $fs / ($fs * 0 + 1 / $rfs-rem-value);
86132
}
87133

88-
// Set default font-size
89-
@if $rfs-font-size-unit == rem {
90-
$rfs-static: #{$fs / $rfs-rem-value}rem#{$rfs-suffix};
91-
}
92-
@else if $rfs-font-size-unit == px {
93-
$rfs-static: #{$fs}px#{$rfs-suffix};
134+
// Set default font size
135+
$rfs-static: if($rfs-font-size-unit == rem, #{$fs / $rfs-rem-value}rem, #{$fs}px);
136+
137+
// Only add the media query if the font size is bigger than the minimum font size
138+
@if $fs <= $rfs-base-font-size or not $enable-responsive-font-sizes {
139+
font-size: #{$rfs-static}#{$rfs-suffix};
94140
}
95141
@else {
96-
@error "`#{$rfs-font-size-unit}` is not a valid unit for $rfs-font-size-unit. Use `px` or `rem`.";
97-
}
98-
99-
// Only add media query if font-size is bigger as the minimum font-size
100-
// If $rfs-factor == 1, no rescaling will take place
101-
@if $fs > $rfs-base-font-size and $enable-responsive-font-sizes {
102-
$min-width: null;
103-
$variable-unit: null;
104-
105-
// Calculate minimum font-size for given font-size
142+
// Calculate the minimum font size for $fs
106143
$fs-min: $rfs-base-font-size + ($fs - $rfs-base-font-size) / $rfs-factor;
107144

108-
// Calculate difference between given font-size and minimum font-size for given font-size
145+
// Calculate difference between $fs and the minimum font size
109146
$fs-diff: $fs - $fs-min;
110147

111148
// Base font-size formatting
112-
// No need to check if the unit is valid, because we did that before
113149
$min-width: if($rfs-font-size-unit == rem, #{$fs-min / $rfs-rem-value}rem, #{$fs-min}px);
114150

115-
// If two-dimensional, use smallest of screen width and height
151+
// Use `vmin` if two-dimensional is enabled
116152
$variable-unit: if($rfs-two-dimensional, vmin, vw);
117153

118154
// Calculate the variable width between 0 and $rfs-breakpoint
119155
$variable-width: #{$fs-diff * 100 / $rfs-breakpoint}#{$variable-unit};
120156

121-
// Set the calculated font-size.
157+
// Set the calculated font-size
122158
$rfs-fluid: calc(#{$min-width} + #{$variable-width}) #{$rfs-suffix};
123-
}
124159

125-
// Rendering
126-
@if $rfs-fluid == null {
127-
// Only render static font-size if no fluid font-size is available
128-
font-size: $rfs-static;
129-
}
130-
@else {
131-
$mq-value: null;
160+
// Breakpoint formatting
161+
$mq-value: if($rfs-breakpoint-unit == px, #{$rfs-breakpoint}px, #{$rfs-breakpoint / $rfs-rem-value}#{$rfs-breakpoint-unit});
132162

133-
// RFS breakpoint formatting
134-
@if $rfs-breakpoint-unit == em or $rfs-breakpoint-unit == rem {
135-
$mq-value: #{$rfs-breakpoint / $rfs-rem-value}#{$rfs-breakpoint-unit};
136-
}
137-
@else if $rfs-breakpoint-unit == px {
138-
$mq-value: #{$rfs-breakpoint}px;
139-
}
140-
@else {
141-
@error "`#{$rfs-breakpoint-unit}` is not a valid unit for $rfs-breakpoint-unit. Use `px`, `em` or `rem`.";
163+
@include _rfs-disable-class {
164+
font-size: #{$rfs-static}#{$rfs-suffix};
142165
}
143166

144-
@if $rfs-class == "disable" {
145-
// Adding an extra class increases specificity,
146-
// which prevents the media query to override the font size
147-
&,
148-
.disable-responsive-font-size &,
149-
&.disable-responsive-font-size {
150-
font-size: $rfs-static;
167+
@include _rfs-media-query($mq-value) {
168+
@include _rfs-enable-class {
169+
font-size: $rfs-fluid;
151170
}
152-
}
153-
@else {
154-
font-size: $rfs-static;
155-
}
156171

157-
@if $rfs-two-dimensional {
158-
@media (max-width: #{$mq-value}), (max-height: #{$mq-value}) {
159-
@if $rfs-class == "enable" {
160-
.enable-responsive-font-size &,
161-
&.enable-responsive-font-size {
162-
font-size: $rfs-fluid;
163-
}
164-
}
165-
@else {
166-
font-size: $rfs-fluid;
167-
}
168-
169-
@if $rfs-safari-iframe-resize-bug-fix {
170-
// stylelint-disable-next-line length-zero-no-unit
171-
min-width: 0vw;
172-
}
173-
}
174-
}
175-
@else {
176-
@media (max-width: #{$mq-value}) {
177-
@if $rfs-class == "enable" {
178-
.enable-responsive-font-size &,
179-
&.enable-responsive-font-size {
180-
font-size: $rfs-fluid;
181-
}
182-
}
183-
@else {
184-
font-size: $rfs-fluid;
185-
}
186-
187-
@if $rfs-safari-iframe-resize-bug-fix {
188-
// stylelint-disable-next-line length-zero-no-unit
189-
min-width: 0vw;
190-
}
191-
}
172+
// Include safari iframe resize fix if needed
173+
min-width: if($rfs-safari-iframe-resize-bug-fix, (0 * 1vw), null);
192174
}
193175
}
194176
}
195177
}
196178

197-
// The font-size & responsive-font-size mixin uses RFS to rescale font sizes
179+
// The font-size & responsive-font-size mixins use RFS to rescale the font size
198180
@mixin font-size($fs, $important: false) {
199181
@include rfs($fs, $important);
200182
}

0 commit comments

Comments
 (0)