Created
September 9, 2014 18:46
-
-
Save rydurham/9dde974dea12b355525a to your computer and use it in GitHub Desktop.
Sass Media Queries mixin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$breakpoints: ( | |
'small' ( '( max-width: 616px )'), | |
'medium' ( '( min-width: 617px ) and (max-width: 1066px)'), | |
'large' ( '( min-width: 1067px )') | |
); | |
@mixin respond-to($name, $push: false) { | |
// If the key exists in the map | |
@if map-has-key($breakpoints, $name) { | |
// Prints a media query based on the value | |
@media #{map-get($breakpoints, $name)} { | |
@content; | |
} | |
} | |
// If the key doesn't exist in the map | |
// But $push is defined | |
// @else if $push != false { | |
// // Add the new breakpoint to the map | |
// $breakpoints: map-merge($breakpoints, ($name $push)) !global; | |
// // And re-call the mixin normally | |
// @include respond-to($name) { | |
// @content; | |
// } | |
// } | |
// If the key doesn't exist in the map | |
// And there is no push | |
@else { | |
// Just warn the user | |
@warn "Unfortunately, no value could be retrieved from `#{$name}`. " | |
+ "Please make sure it is defined in `$breakpoints` map. " | |
+ "Or pass the media query as a second parameter to add it to the map."; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment