amélioration du mixant "respond-to()"

This commit is contained in:
Raphael Goetter 2017-04-21 22:40:35 +02:00
parent e29a67981e
commit faccfdb4bf
5 changed files with 33 additions and 42 deletions

View file

@ -1,6 +1,6 @@
{
"name": "KNACSS",
"version": "6.1.0",
"version": "6.1.1",
"homepage": "http://www.knacss.com/",
"authors": [
"Raphaël GOETTER, Alsacreations"

View file

@ -1,3 +1,6 @@
# changelog v6.1.1 (21 avril 2017)
- amélioration du mixin "respond-to()"
# changelog v6.1.0 (3 mars 2017)
- passage à [Normalize 5.0.0](https://github.com/necolas/normalize.css/blob/5.0.0/CHANGELOG.md)
- ajout de variables pour tailles de polices différentes sur petits et sur grands écrans (`$h1-size` et `$h1-size-l` par exemple). Par défaut, les tailles "mobile" sont appliquées, et les tailles "desktop" s'appliquent en min-width `$tiny +1`

View file

@ -1,6 +1,6 @@
{
"name": "knacss",
"version": "6.1.0",
"version": "6.1.1",
"homepage": "http://www.knacss.com/",
"bugs": "https://github.com/alsacreations/KNACSS/issues",
"author": [

View file

@ -1,44 +1,32 @@
// Additionnal "utility" breakpoints aliases
// ex. @include respond-to("medium-up") {...}
@function breakpoint($bp) {
@if $bp == 'tiny' {
@return '(max-width: #{$tiny})';
}
@else if $bp == 'small' {
@return '(max-width: #{$small})';
}
@else if $bp == 'medium' {
@return '(max-width: #{$medium})';
}
@else if $bp == 'large' {
@return '(max-width: #{$large})';
}
@else if $bp == 'extra-large' {
@return '(max-width: #{$extra-large})';
}
@else if $bp == 'tiny-up' {
@return '(min-width: #{$tiny + 1})';
}
@else if $bp == 'small-up' {
@return '(min-width: #{$small + 1})';
}
@else if $bp == 'medium-up' {
@return '(min-width: #{$medium + 1})';
}
@else if $bp == 'large-up' {
@return '(min-width: #{$large + 1})';
}
@else if $bp == 'extra-large-up' {
@return '(min-width: #{$extra-large + 1})';
}
@else if $bp == 'retina' {
@return '(-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi), (min-resolution: 2dppx)';
}
}
$bp-aliases: (
'tiny' : (max-width: #{$tiny}),
'small' : (max-width: #{$small}),
'medium' : (max-width: #{$medium}),
'large' : (max-width: #{$large}),
'extra-large' : (max-width: #{$extra-large}),
'tiny-up' : (min-width: #{$tiny + 1}),
'small-up' : (min-width: #{$small + 1}),
'medium-up' : (min-width: #{$medium + 1}),
'large-up' : (min-width: #{$large + 1}),
'extra-large-up' : (min-width: #{$extra-large + 1}),
'retina' : (min-resolution: 2dppx)
);
@mixin respond-to($value) {
$string: breakpoint($value);
@media screen and #{$string} {
@content;
// Source : https://www.sitepoint.com/managing-responsive-breakpoints-sass/
@mixin respond-to($name) {
// If the key exists in the map
@if map-has-key($bp-aliases, $name) {
// Prints a media query based on the value
@media #{inspect(map-get($bp-aliases, $name))} {
@content;
}
}
// If the key doesn't exist in the map
@else {
@warn "Unfortunately, no value could be retrieved from `#{$breakpoint}`. "
+ "Please make sure it is defined in `$breakpoints` map.";
}
}

View file

@ -1,5 +1,5 @@
/*!
* www.KNACSS.com V6.0.5 (1er décembre 2016) @author: Alsacreations, Raphael Goetter
* www.KNACSS.com v6.1.1 (21 avril 2017) @author: Alsacreations, Raphael Goetter
* Licence WTFPL http://www.wtfpl.net/
*/