-
Notifications
You must be signed in to change notification settings - Fork 0
/
_mixins.scss
46 lines (41 loc) · 1.26 KB
/
_mixins.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
/**
* Sass mixins
* @see https://sass-lang.com/documentation/at-rules/mixin
*/
/// Replace `$search` with `$replace` in `$string`
/// @author Kitty Giraudel
/// @param {String} $string - Initial string
/// @param {String} $search - Substring to replace
/// @param {String} $replace ('') - New value
/// @return {String} - Updated string
@function str-replace($string, $search, $replace: '') {
$index: str-index($string, $search);
@if $index {
@return str-slice($string, 1, $index - 1) + $replace +
str-replace(
str-slice($string, $index + str-length($search)),
$search,
$replace
);
}
@return $string;
}
/// Mixin to manage responsive breakpoints
///
/// @author Kitty Giraudel
/// @param {String} $breakpoint - Breakpoint name
/// @require $breakpoints
@mixin breakpoint($breakpoint) {
// If the key exists in the map
@if map-has-key($breakpoints, $breakpoint) {
// Prints a media query based on the value
@media #{str-replace(inspect(map-get($breakpoints, $breakpoint)), ',', ') and (')} {
@content;
}
}
// If the key doesn't exist in the map
@else {
@warn 'Unfortunately, no value could be retrieved from `#{$breakpoint}`. '
+ 'Available breakpoints are: #{map-keys($breakpoints)}.';
}
}