-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path_breakpoint.scss
90 lines (83 loc) · 2.54 KB
/
_breakpoint.scss
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
// Sass functions
@use 'sass:map';
@use 'sass:list';
@use 'sass:math';
@use 'sass:string';
@use '../functions' as fn;
// Breakpoint Vars
$xxs: fn.px-to-rem(375) !default; // Smartphone Portrait
$xs: fn.px-to-rem(568) !default; // Smartphone Landscape
$sm: fn.px-to-rem(768) !default; // Tablet Portrait
$md: fn.px-to-rem(1024) !default; // Tablet Landscape
$lg: fn.px-to-rem(1260) !default; // Kleinerer Desktop
$xlg: fn.px-to-rem(1440) !default; // Widescreen
$fhd: fn.px-to-rem(1920) !default; // Full HD
$uhd: fn.px-to-rem(2560) !default; // UHD
// Breakpoint Map
$breakpoints: (
'xxs': $xxs,
'xs': $xs,
'sm': $sm,
'md': $md,
'lg': $lg,
'xlg': $xlg,
'fhd': $fhd,
'uhd': $uhd,
) !default;
/// Breakpoint Mixin using breakpoint map
/// @param {String} $breakpoint Breakpoint key from the breakpoints map
/// @param {String} $direction ['min'] Breakpoint direction min or max
/// @param {Map} $breakpoint-map [$breakpoints] All breakpoint vars in one map
/// @param {Number} $max-overlap [null] How much should the max-width breakpoint overlap the min-width one?
/// @group @media
/// @author Felix Scholze
/// @since v1.1.0
///
/// @example
/// .my-selector {
/// @include breakpoint(lg) {...}
/// }
///
/// @example CSS - Output CSS
/// @media (min-width: 78.75rem) {
/// .my-selector {...}
/// }
///
@mixin breakpoint(
$breakpoint,
$direction: 'min',
$breakpoint-map: $breakpoints,
$max-overlap: null,
) {
/// Error handling
$valid-direction: ('min', 'max');
/// Search and return the key from the breakpoints map
$get-breakpoints: map.get($breakpoint-map, $breakpoint);
$unit: math.unit($get-breakpoints);
/// Give an error if the breakpoint direction is not correct
@if not list.index($valid-direction, $direction) {
@error '❌ ===> #{$direction} is not a valid option for direction. Please use: #{$valid-direction}';
}
/// Give an error if the breakpoint does not exist in the map
@if map.has-key($breakpoint-map, $breakpoint) != true {
@error '❌ ===> #{$breakpoint} is not valid breakpoint. Please use: #{map.keys($breakpoint-map)}';
}
/// If $max-overlap is not set, set it to 1px or 0.01rem
@if not $max-overlap {
@if fn.str-contains($unit, 'rem') or fn.str-contains($unit, 'em') {
$max-overlap: 0.01;
} @else {
$max-overlap: 1;
}
}
@if $direction == 'min' {
@media (width >= $get-breakpoints) {
@content;
}
}
@if $direction == 'max' {
@media (width <= $get-breakpoints - $max-overlap) {
@content;
}
}
}