Skip to content

Commit da7edfa

Browse files
committed
(PDS-442) Add breakpoint tools to sass-variables
Adds variables and mixins to the `sass-variables` package to allow for configuring and responding to different breakpoints. There are three breakpoints: small, medium, and large: - Portrait-mode phones tend to be smaller than 'small' - Landscape-mode phones tend to be between 'small' and 'medium' - Tablets and small browser windows tend to be between 'medium' and 'large' - Browser windows and some landscape-mode tablets tend to be larger than 'large' Default breakpoints can be overridden by defining your own `@breakpoints` map in your stylesheets before importing `sass-variables`. Two mixins are included: - `respond-above` applies styles to widths greater than the given size - `respond-below` applies styles to widths below the given size
1 parent 7e071bf commit da7edfa

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

packages/sass-variables/_index.scss

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
@import './common';
33
@import './fonts';
44
@import './typography';
5+
@import './responsive';
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
$breakpoints: (
2+
// Portrait-mode phones are generally smaller than the 'small' breakpoint.
3+
'small': 576px,
4+
// Landscape-mode phones are between 'small' and 'medium'.
5+
'medium': 768px,
6+
// Tablets + smaller desktop browser windows are between 'medium' and 'large'.
7+
'large': 1180px,
8+
// Desktop browser windows + large landscape-mode tablets are larger than 'large'.
9+
) !default;
10+
11+
@mixin respond-above($breakpoint) {
12+
@if map-has-key($breakpoints, $breakpoint) {
13+
@media (min-width: map-get($breakpoints, $breakpoint)) {
14+
@content;
15+
}
16+
} @else {
17+
@warn "Unrecognized breakpoint '#{$breakpoint}'. Available breakpoints are: #{map-keys($breakpoints)}.";
18+
}
19+
}
20+
21+
@mixin respond-below($breakpoint) {
22+
@if map-has-key($breakpoints, $breakpoint) {
23+
@media (max-width: map-get($breakpoints, $breakpoint) - 1) {
24+
@content;
25+
}
26+
} @else {
27+
@warn "Unrecognized breakpoint '#{$breakpoint}'. Available breakpoints are: #{map-keys($breakpoints)}.";
28+
}
29+
}

0 commit comments

Comments
 (0)