Repository navigation
Expand file tree
/
Copy path_breakpoint.scss
More file actions
96 lines (94 loc) · 3.96 KB
/
Copy path_breakpoint.scss
File metadata and controls
96 lines (94 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
@charset "UTF-8";
@use "sass:list";
@use "sass:map";
@use "../maps/map-for-breakpoints" as *;
@use "../utilities/validate-breakpoint" as *;
@use "../internal/custom-property-in" as *;
@use "../internal/condition-width" as *;
// Every size goes through conditionWidth before a query is written, so a size no
// width condition can match raises instead of compiling into one. The queries
// themselves are written as they always were, and the checks in the branches
// below are called only for the error they raise, so a call that worked writes
// the same CSS.
@mixin breakpoint($params...) {
$custom-property: customPropertyIn($params);
@if $custom-property {
@error "`#{$custom-property}` cannot be used in a breakpoint: custom properties are not evaluated in a @media condition, so the rule would never apply. Pass a length or a key from $map-for-breakpoints.";
}
@if list.length($params) == 1 {
$value: list.nth($params, 1);
// Checked before the warning below, so a size that is wrong outright is
// refused rather than described as a single pixel.
$width: conditionWidth($value, "breakpoint");
// One argument matches a single pixel, which two agent trials took for
// "from this width up". Still emitted, and said out loud,
// but not refused: the CSS is valid and matches that one width.
@warn "`breakpoint(#{$value})` matches only a viewport exactly #{$width} wide, `(width: #{$width})`. Write `breakpoint(only, #{$value})` for that width, or `breakpoint(min, #{$value})` from it upwards.";
@if map.has-key($map-for-breakpoints, $value) {
@media (width: map.get($map-for-breakpoints, $value)) {
@content;
}
} @else {
@media (width: $value) {
@content;
}
}
} @else if list.length($params) == 2 {
@if not list.index("only" "min" "max" "between", list.nth($params, 1)) {
$start: list.nth($params, 1);
$end: list.nth($params, 2);
$checked: conditionWidth($start, "breakpoint") conditionWidth($end, "breakpoint");
@media (min-width: #{validateBreakpoint($start)}) and (max-width: #{if(map.has-key($map-for-breakpoints, $end), validateBreakpoint($end) - 1, $end)}) {
@content;
}
} @else {
$mode: list.nth($params, 1);
$value: list.nth($params, 2);
@if $mode != "between" {
$checked: conditionWidth($value, "breakpoint");
}
@if $mode == "only" {
@if map.has-key($map-for-breakpoints, $value) {
@media (width: map.get($map-for-breakpoints, $value)) {
@content;
}
} @else {
@media (width: $value) {
@content;
}
}
} @else if $mode == "min" {
@if map.has-key($map-for-breakpoints, $value) {
@media (min-width: map.get($map-for-breakpoints, $value)) {
@content;
}
} @else {
@media (min-width: $value) {
@content;
}
}
} @else if $mode == "max" {
@if map.has-key($map-for-breakpoints, $value) {
@media (max-width: map.get($map-for-breakpoints, $value)) {
@content;
}
} @else {
@media (max-width: $value) {
@content;
}
}
} @else if $mode == "between" {
$start: list.nth($value, 1);
$end: list.nth($value, 2);
$checked: conditionWidth($start, "breakpoint") conditionWidth($end, "breakpoint");
@media (min-width: #{validateBreakpoint($start)}) and (max-width: #{if(map.has-key($map-for-breakpoints, $end), validateBreakpoint($end) - 1, $end)}) {
@content;
}
}
}
} @else {
// Anything else used to match no branch and emit nothing, so a three
// argument range such as `between, medium, large` failed without a sound.
@error "`breakpoint` takes one or two arguments; you passed #{list.length($params)}. For a range, pass `between` with a space-separated pair, `between, medium large`, or two sizes, `medium, large`.";
}
}