Skip to content

Commit

Permalink
Improved respond-to mixin to make it slightly more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
KittyGiraudel committed Apr 11, 2015
1 parent dbc68ea commit a27553e
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions en/_rwd.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ $breakpoints: ('seed': (min-width: 800px), 'sprout': (min-width: 1000px), 'plant
</div>
</div>

<div class="note">
<p>The previous examples uses nested maps to define breakpoints, however this really depends on what kind of breakpoint manager you use. You could opt for strings rather than inner maps for more flexibility (e.g. <code>'(min-width: 800px)'</code>).</p>
</div>




Expand All @@ -86,8 +90,12 @@ Once you have named your breakpoints the way you want, you need a way to use the
/// @param {String} $breakpoint - Breakpoint
/// @requires $breakpoints
@mixin respond-to($breakpoint) {
@if map-has-key($breakpoints, $breakpoint) {
@media #{inspect(map-get($breakpoints, $breakpoint))} {
$raw-query: map-get($breakpoints, $breakpoint);

@if $raw-query {
$query: if(type-of($raw-query) == 'string', unquote($raw-query), inspect($raw-query));

@media #{$query} {
@content;
}
} @else {
Expand All @@ -104,8 +112,12 @@ Once you have named your breakpoints the way you want, you need a way to use the
/// @param {String} $breakpoint - Breakpoint
/// @requires $breakpoints
=respond-to($breakpoint)
@if map-has-key($breakpoints, $breakpoint)
@media #{inspect(map-get($breakpoints, $breakpoint))}
$raw-query: map-get($breakpoints, $breakpoint)

@if $raw-query
$query: if(type-of($raw-query) == 'string', unquote($raw-query), inspect($raw-query))

@media #{$query}
@content

@else
Expand All @@ -116,8 +128,7 @@ Once you have named your breakpoints the way you want, you need a way to use the
</div>

<div class="note">
<p>Obviously, this is a fairly simplistic breakpoint manager that will not do the trick when dealing with custom and/or multiple-checks breakpoints.</p>
<p>If you need a slightly more permissive breakpoint manager, may I recommend you do not reinvent the wheel and use something that has been proven effective such as <a href="https://github.com/sass-mq/sass-mq">Sass-MQ</a>, <a href="http://breakpoint-sass.com/">Breakpoint</a> or <a href="https://github.com/eduardoboucas/include-media">include-media</a>.</p>
<p>Obviously, this is a fairly simplistic breakpoint manager. If you need a slightly more permissive one, may I recommend you do not reinvent the wheel and use something that has been proven effective such as <a href="https://github.com/sass-mq/sass-mq">Sass-MQ</a>, <a href="http://breakpoint-sass.com/">Breakpoint</a> or <a href="https://github.com/eduardoboucas/include-media">include-media</a>.</p>
</div>


Expand Down

2 comments on commit a27553e

@pierrechoffe
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 66, typo : should be either 'the previous examples use' or 'the previous example uses'

@KittyGiraudel
Copy link
Owner Author

@KittyGiraudel KittyGiraudel commented on a27553e Apr 12, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.