Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit a0930d0

Browse files
Handle breakpoints additionally
1 parent 40e90e6 commit a0930d0

File tree

3 files changed

+72
-24
lines changed

3 files changed

+72
-24
lines changed

scss/utils/_config.scss

+9
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,12 @@ $spacing: (
55
"xs": 8px,
66
"none": 0px
77
);
8+
9+
$breakpoints: (
10+
"xs": 375px,
11+
"sm": 480px,
12+
"md": 768px,
13+
"lg": 1080px,
14+
"xl": 1440px,
15+
"xxl": 1920px
16+
);

scss/utils/_mixins.scss

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@mixin validate-unit($value, $value-type, $units...) {
2+
@if type-of($value) != $value-type or index($units, unit($value)) == null {
3+
@error "Invalid unit #{unit($value)} for value #{$value}.";
4+
}
5+
}

scss/utils/_spacing.scss

+58-24
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,71 @@
1+
@use "sass:map";
2+
@use "sass:math";
13
@use "config" as *;
4+
@use "mixins" as *;
25

36
$selectors: ("m": margin, "p": padding);
47
$directions: ("t": top, "b": bottom, "l": left, "r": right);
58
$axes: "y", "x";
69

7-
@each $prefix, $selector in $selectors {
8-
@each $suffix, $space in $spacing {
9-
.#{$prefix}-#{$suffix} {
10-
#{$selector}: #{$space} !important;
11-
}
12-
}
13-
}
10+
$breakpoint-values: map.values($breakpoints);
11+
$min-breakpoint: math.min($breakpoint-values...);
12+
13+
@each $breakpoint, $breakpoint-value in $breakpoints {
14+
@if $breakpoint-value == $min-breakpoint {
15+
@each $prefix, $selector in $selectors {
16+
@each $suffix, $space in $spacing {
17+
@include validate-unit($space, number, px, em, rem);
1418

15-
@each $prefix, $selector in $selectors {
16-
@each $abbr-dir, $direction in $directions {
17-
@each $suffix, $space in $spacing {
18-
.#{$prefix}#{$abbr-dir}-#{$suffix} {
19-
#{$selector}-#{$direction}: #{$space} !important;
19+
@each $abbr-dir, $direction in $directions {
20+
.#{$prefix}#{$abbr-dir}-#{$suffix} {
21+
#{$selector}-#{$direction}: #{$space} !important;
22+
}
23+
}
24+
25+
@each $axis in $axes {
26+
.#{$prefix}#{$axis}-#{$suffix} {
27+
@if $axis == "y" {
28+
#{$selector}-top: #{$space} !important;
29+
#{$selector}-bottom: #{$space} !important;
30+
} @else if $axis == "x" {
31+
#{$selector}-left: #{$space} !important;
32+
#{$selector}-right: #{$space} !important;
33+
}
34+
}
35+
}
36+
37+
.#{$prefix}-#{$suffix} {
38+
#{$selector}: #{$space} !important;
39+
}
2040
}
2141
}
22-
}
23-
}
42+
} @else {
43+
@media (min-width: $breakpoint-value) {
44+
@each $prefix, $selector in $selectors {
45+
@each $suffix, $space in $spacing {
46+
@include validate-unit($space, number, px, em, rem);
47+
48+
@each $abbr-dir, $direction in $directions {
49+
.#{$prefix}#{$abbr-dir}-#{$breakpoint}-#{$suffix} {
50+
#{$selector}-#{$direction}: #{$space} !important;
51+
}
52+
}
53+
54+
@each $axis in $axes {
55+
.#{$prefix}#{$axis}-#{$breakpoint}-#{$suffix} {
56+
@if $axis == "y" {
57+
#{$selector}-top: #{$space} !important;
58+
#{$selector}-bottom: #{$space} !important;
59+
} @else if $axis == "x" {
60+
#{$selector}-left: #{$space} !important;
61+
#{$selector}-right: #{$space} !important;
62+
}
63+
}
64+
}
2465

25-
@each $prefix, $selector in $selectors {
26-
@each $axis in $axes {
27-
@each $suffix, $space in $spacing {
28-
.#{$prefix}#{$axis}-#{$suffix} {
29-
@if $axis == "y" {
30-
#{$selector}-top: #{$space} !important;
31-
#{$selector}-bottom: #{$space} !important;
32-
} @else if $axis == "x" {
33-
#{$selector}-left: #{$space} !important;
34-
#{$selector}-right: #{$space} !important;
66+
.#{$prefix}-#{$breakpoint}-#{$suffix} {
67+
#{$selector}: #{$space} !important;
68+
}
3569
}
3670
}
3771
}

0 commit comments

Comments
 (0)