Debian Codegraph @

docs/src/scss/utilities/_break.scss

raw
1 ////
2 /// Copyright (c) 2016-2020 Martin Donath <[email protected]>
3 ///
4 /// Permission is hereby granted, free of charge, to any person obtaining a
5 /// copy of this software and associated documentation files (the "Software"),
6 /// to deal in the Software without restriction, including without limitation
7 /// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 /// and/or sell copies of the Software, and to permit persons to whom the
9 /// Software is furnished to do so, subject to the following conditions:
10 ///
11 /// The above copyright notice and this permission notice shall be included in
12 /// all copies or substantial portions of the Software.
13 ///
14 /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 /// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 /// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 /// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 /// DEALINGS
21 ////
22
23 // ----------------------------------------------------------------------------
24 // Variables
25 // ----------------------------------------------------------------------------
26
27 ///
28 /// Device-specific breakpoints
29 ///
30 /// @example
31 /// $break-devices: (
32 /// mobile: (
33 /// portrait: 220px 479px,
34 /// landscape: 480px 719px
35 /// ),
36 /// tablet: (
37 /// portrait: 720px 959px,
38 /// landscape: 960px 1219px
39 /// ),
40 /// screen: (
41 /// small: 1220px 1599px,
42 /// medium: 1600px 1999px,
43 /// large: 2000px
44 /// )
45 /// );
46 ///
47 @use "sass:map";
48 @use "sass:list";
49 @use "sass:meta";
50 @use "./convert";
51
52 $break-devices: (
53 mobile: (
54 portrait: convert.px2em(220px) convert.px2em(479px),
55 landscape: convert.px2em(480px) convert.px2em(719px)
56 ),
57 tablet: (
58 portrait: convert.px2em(720px) convert.px2em(959px),
59 landscape: convert.px2em(960px) convert.px2em(1219px)
60 ),
61 screen: (
62 small: convert.px2em(1220px) convert.px2em(1599px),
63 medium: convert.px2em(1600px) convert.px2em(1999px),
64 large: convert.px2em(2000px)
65 )
66 ) !default;
67
68 // ----------------------------------------------------------------------------
69 // Helpers
70 // ----------------------------------------------------------------------------
71
72 ///
73 /// Choose minimum and maximum device widths
74 ///
75 @function break-select-min-max($devices) {
76 $min: 1000000;
77 $max: 0;
78 @each $key, $value in $devices {
79 @while meta.type-of($value) == map {
80 $value: break-select-min-max($value);
81 }
82 @if meta.type-of($value) == list {
83 @each $number in $value {
84 @if meta.type-of($number) == number {
85 $min: min($number, $min);
86 @if $max != null {
87 $max: max($number, $max);
88 }
89 } @else {
90 @error "Invalid number: #{$number}";
91 }
92 }
93 } @else if meta.type-of($value) == number {
94 $min: min($value, $min);
95 $max: null;
96 } @else {
97 @error "Invalid value: #{$value}";
98 }
99 }
100 @return $min, $max;
101 }
102
103 ///
104 /// Select minimum and maximum widths for a device breakpoint
105 ///
106 @function break-select-device($device) {
107 $current: $break-devices;
108 @for $n from 1 through list.length($device) {
109 @if meta.type-of($current) == map {
110 $current: map.get($current, list.nth($device, $n));
111 } @else {
112 @error "Invalid device map: #{$devices}";
113 }
114 }
115 @if meta.type-of($current) == list or meta.type-of($current) == number {
116 $current: (default: $current);
117 }
118 @return break-select-min-max($current);
119 }
120
121 // ----------------------------------------------------------------------------
122 // Mixins
123 // ----------------------------------------------------------------------------
124
125 ///
126 /// A minimum-maximum media query breakpoint
127 ///
128 @mixin break-at($breakpoint) {
129 @if meta.type-of($breakpoint) == number {
130 @media screen and (min-width: $breakpoint) {
131 @content;
132 }
133 } @else if meta.type-of($breakpoint) == list {
134 $min: list.nth($breakpoint, 1);
135 $max: list.nth($breakpoint, 2);
136 @if meta.type-of($min) == number and meta.type-of($max) == number {
137 @media screen and (min-width: $min) and (max-width: $max) {
138 @content;
139 }
140 } @else {
141 @error "Invalid breakpoint: #{$breakpoint}";
142 }
143 } @else {
144 @error "Invalid breakpoint: #{$breakpoint}";
145 }
146 }
147
148 ///
149 /// An orientation media query breakpoint
150 ///
151 @mixin break-at-orientation($breakpoint) {
152 @if meta.type-of($breakpoint) == string {
153 @media screen and (orientation: $breakpoint) {
154 @content;
155 }
156 } @else {
157 @error "Invalid breakpoint: #{$breakpoint}";
158 }
159 }
160
161 ///
162 /// A maximum-aspect-ratio media query breakpoint
163 ///
164 @mixin break-at-ratio($breakpoint) {
165 @if meta.type-of($breakpoint) == number {
166 @media screen and (max-aspect-ratio: $breakpoint) {
167 @content;
168 }
169 } @else {
170 @error "Invalid breakpoint: #{$breakpoint}";
171 }
172 }
173
174 ///
175 /// A minimum-maximum media query device breakpoint
176 ///
177 @mixin break-at-device($device) {
178 @if meta.type-of($device) == string {
179 $device: $device,;
180 }
181 @if meta.type-of($device) == list {
182 $breakpoint: break-select-device($device);
183 @if list.nth($breakpoint, 2) != null {
184 $min: list.nth($breakpoint, 1);
185 $max: list.nth($breakpoint, 2);
186 @media screen and (min-width: $min) and (max-width: $max) {
187 @content;
188 }
189 } @else {
190 @error "Invalid device: #{$device}";
191 }
192 } @else {
193 @error "Invalid device: #{$device}";
194 }
195 }
196
197 ///
198 /// A minimum media query device breakpoint
199 ///
200 @mixin break-from-device($device) {
201 @if meta.type-of($device) == string {
202 $device: $device,;
203 }
204 @if meta.type-of($device) == list {
205 $breakpoint: break-select-device($device);
206 $min: list.nth($breakpoint, 1);
207 @media screen and (min-width: $min) {
208 @content;
209 }
210 } @else {
211 @error "Invalid device: #{$device}";
212 }
213 }
214
215 ///
216 /// A maximum media query device breakpoint
217 ///
218 @mixin break-to-device($device) {
219 @if meta.type-of($device) == string {
220 $device: $device,;
221 }
222 @if meta.type-of($device) == list {
223 $breakpoint: break-select-device($device);
224 $max: list.nth($breakpoint, 2);
225 @media screen and (max-width: $max) {
226 @content;
227 }
228 } @else {
229 @error "Invalid device: #{$device}";
230 }
231 }