mixins converted to use maps for parameters - fixed variations param order.

This commit is contained in:
Kevin Ross 2015-11-04 10:57:10 -06:00
parent 9c7731cc3d
commit 057f55cbf7
3 changed files with 160 additions and 103 deletions

View File

@ -1,13 +1,18 @@
@import 'mixins-shared'; @import 'mixins-shared';
@mixin generic-variations-colors($mixin-name, $extra, $default, $contrast-factor, $material-param-1) { @mixin generic-variations-colors($args) {
$material-color-names: "red" "pink" "purple" "deep-purple" "indigo" "blue" "light-blue" "cyan" "teal" "green" "light-green" "lime" "yellow" "amber" "orange" "deep-orange" "brown" "grey" "blue-grey"; $material-color-names: "red" "pink" "purple" "deep-purple" "indigo" "blue" "light-blue" "cyan" "teal" "green" "light-green" "lime" "yellow" "amber" "orange" "deep-orange" "brown" "grey" "blue-grey";
@each $material-color-name in $material-color-names { @each $material-color-name in $material-color-names {
// given a color build multiples depths // given a color build multiples depths
$material-color-numbers: "" "-50" "-100" "-200" "-300" "-400" "-500" "-600" "-700" "-800" "-900" "-A100" "-A200" "-A400" "-A700"; $material-color-numbers: "" "-50" "-100" "-200" "-300" "-400" "-500" "-600" "-700" "-800" "-900" "-A100" "-A200" "-A400" "-A700";
@each $material-color-number in $material-color-numbers { @each $material-color-number in $material-color-numbers {
@include generic-variations-color($mixin-name, $extra, $default, $contrast-factor, $material-color-name, $material-color-number, $material-param-1)
$args: map-merge($args, (
material-color-number: $material-color-number
));
@include generic-variations-color($args)
} }
} }
} }

View File

@ -1,66 +1,80 @@
@mixin variations-content($material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1) { // variations(unquote(""), background-color, #FFF);
#{$material-param-1}: unquote($material-color); @mixin variations($extra, $material-param-1, $default) {
}
@mixin background-variations-content($material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1) {
background-color: $material-color;
@if ($material-color == $btn-default) {
color: $lightbg-text;
} @else {
color: $material-text-color;
}
}
@mixin text-variations-content($material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1) {
color: $material-color;
}
@mixin button-variations-content($material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1) {
background-color: contrast($material-color, darken($material-color, $material-param-1), lighten($material-color, $material-param-1), $contrast-factor);
}
@mixin bg-color-variations-content($material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1) {
background-color: rgba($material-color, $material-param-1);
}
// interpolation of mixin-name is not allowed evidently, so we statically include based on the mixin-name given
@mixin call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1) {
@if $mixin-name == variations-content {
@include variations-content($material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1);
} @else if $mixin-name == background-variations-content {
@include background-variations-content($material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1);
} @else if $mixin-name == text-variations-content {
@include text-variations-content($material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1);
} @else if $mixin-name == button-variations-content {
@include button-variations-content($material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1);
} @else if $mixin-name == bg-color-variations-content {
@include bg-color-variations-content($material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1);
} @else {
@error "Unknown mixin: #{$mixin-name}"
}
}
// @include button-variations(unquote(":not(.btn-link):not(.btn-flat)"), $btn-default, 4%);
@mixin variations($extra, $default, $material-param-1) {
@include generic-variations($extra, $default, "variations-content", $material-param-1); @include generic-variations($extra, $default, "variations-content", $material-param-1);
} }
@mixin variations-content($args) {
//@debug "#{map-get($args, mixin-name)}{ #{map-get($args, material-param-1)}: #{map-get($args, material-color)}; }";
//@debug "#{inspect($args)}";
//@error "break here";
#{map-get($args, material-param-1)}: map-get($args, material-color);
}
@mixin background-variations($extra, $default) { @mixin background-variations($extra, $default) {
@include generic-variations($extra, $default, "background-variations-content", null); @include generic-variations($extra, $default, "background-variations-content", null);
} }
@mixin background-variations-content($args) {
background-color: map-get($args, material-color);
@if (map-get($args, material-color) == $btn-default) {
color: $lightbg-text;
} @else {
color: map-get($args, material-text-color);
}
}
@mixin text-variations($extra, $default) { @mixin text-variations($extra, $default) {
@include generic-variations($extra, $default, "text-variations-content", null); @include generic-variations($extra, $default, "text-variations-content", null);
} }
@mixin text-variations-content($args) {
color: map-get($args, material-color);
}
@mixin button-variations($extra, $default, $material-param-1) { @mixin button-variations($extra, $default, $material-param-1) {
@include generic-variations($extra, $default, "button-variations-content", $material-param-1); @include generic-variations($extra, $default, "button-variations-content", $material-param-1);
} }
@mixin button-variations-content($args) {
@debug "#{inspect($args)}";
$material-color: map-get($args, material-color);
$material-param-1: map-get($args, material-param-1);
$contrast-factor: map-get($args, contrast-factor);
background-color: contrast($material-color, darken($material-color, $material-param-1), lighten($material-color, $material-param-1), $contrast-factor);
//@error "break here";
}
@mixin bg-color-variations($extra, $default, $material-param-1) { @mixin bg-color-variations($extra, $default, $material-param-1) {
@include generic-variations($extra, $default, "bg-color-variations-content", $material-param-1); @include generic-variations($extra, $default, "bg-color-variations-content", $material-param-1);
} }
@mixin bg-color-variations-content($args) {
background-color: rgba(map-get($args, material-color), map-get($args, material-param-1));
}
// interpolation of mixin-name is not allowed evidently, so we statically include based on the mixin-name given
@mixin call-variations-content-mixin($args) {
$mixin-name: map-get($args, mixin-name);
@if $mixin-name == variations-content {
@include variations-content($args);
} @else if $mixin-name == background-variations-content {
@include background-variations-content($args);
} @else if $mixin-name == text-variations-content {
@include text-variations-content($args);
} @else if $mixin-name == button-variations-content {
@include button-variations-content($args);
} @else if $mixin-name == bg-color-variations-content {
@include bg-color-variations-content($args);
} @else {
@error "Unknown mixin: #{$mixin-name}"
}
}
// //
// To use this mixin you should pass a function as final parameter to define // To use this mixin you should pass a function as final parameter to define
// the style. In that definition you can use the following variables to define it. // the style. In that definition you can use the following variables to define it.
@ -73,83 +87,118 @@
@mixin generic-variations($extra, $default, $mixin-name, $material-param-1) { @mixin generic-variations($extra, $default, $mixin-name, $material-param-1) {
$contrast-factor: 40% !default; $contrast-factor: 40%;
//setup map to pass parameters (instead of the incredibly long-error-prone list for each and every @include)
$args: (
extra: $extra,
default: $default,
mixin-name: $mixin-name,
material-param-1: $material-param-1,
contrast-factor: $contrast-factor,
);
// bootstrap styles // bootstrap styles
&#{$extra}, &-default#{$extra} { &#{$extra}, &-default#{$extra} {
$material-color-name: "default" !default;
$material-color-full-name: $material-color-name !default; $args-extra: map-merge($args, (
$material-color: $default !default; material-color-name: "default",
$material-text-color: $darkbg-text !default; material-color-full-name: "default",
@include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1); material-color: $default,
material-text-color: $darkbg-text
));
@include call-variations-content-mixin($args-extra);
} }
&-black#{$extra} { &-black#{$extra} {
$material-color-name: "black" !default; $args-black: map-merge($args, (
$material-color-full-name: $material-color-name !default; material-color-name: "black",
$material-color: $black !default; material-color-full-name: "black",
$material-text-color: $darkbg-text !default; material-color: $black,
@include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1); material-text-color: $darkbg-text
));
@include call-variations-content-mixin($args-black);
} }
&-white#{$extra} { &-white#{$extra} {
$material-color-name: "white" !default; $args-white: map-merge($args, (
$material-color-full-name: $material-color-name !default; material-color-name: "white",
$material-color: $white !default; material-color-full-name: "white",
$material-text-color: $lightbg-text !default; material-color: $white,
@include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1); material-text-color: $lightbg-text
));
@include call-variations-content-mixin($args-white);
} }
&-inverse#{$extra} { &-inverse#{$extra} {
$material-color-name: "inverse" !default; $args-inverse: map-merge($args, (
$material-color-full-name: $material-color-name !default; material-color-name: "inverse",
$material-color: $inverse !default; material-color-full-name: "inverse",
$material-text-color: contrast($inverse, $lightbg-text, $darkbg-text, $contrast-factor) !default; material-color: $inverse,
@include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1); material-text-color: contrast($inverse, $lightbg-text, $darkbg-text, $contrast-factor)
));
@include call-variations-content-mixin($args-inverse);
} }
&-primary#{$extra} { &-primary#{$extra} {
$material-color-name: "primary" !default; $args-primary: map-merge($args, (
$material-color-full-name: $material-color-name !default; material-color-name: "primary",
$material-color: $primary !default; material-color-full-name: "primary",
$material-text-color: $darkbg-text !default; material-color: $primary,
@include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1); material-text-color: $darkbg-text
));
@include call-variations-content-mixin($args-primary);
} }
&-success#{$extra} { &-success#{$extra} {
$material-color-name: "success" !default; $args-success: map-merge($args, (
$material-color-full-name: $material-color-name !default; material-color-name: "success",
$material-color: $success !default; material-color-full-name: "success",
$material-text-color: $darkbg-text !default; material-color: $success,
@include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1); material-text-color: $darkbg-text
));
@include call-variations-content-mixin($args-success);
} }
&-info#{$extra} { &-info#{$extra} {
$material-color-name: "info" !default; $args-info: map-merge($args, (
$material-color-full-name: $material-color-name !default; material-color-name: "info",
$material-color: $info !default; material-color-full-name: "info",
$material-text-color: $darkbg-text !default; material-color: $info,
@include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1); material-text-color: $darkbg-text
));
@include call-variations-content-mixin($args-info);
} }
&-warning#{$extra} { &-warning#{$extra} {
$material-color-name: "warning" !default; $args-warning: map-merge($args, (
$material-color-full-name: $material-color-name !default; material-color-name: "warning",
$material-color: $warning !default; material-color-full-name: "warning",
$material-text-color: $darkbg-text !default; material-color: $warning,
@include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1); material-text-color: $darkbg-text
));
@include call-variations-content-mixin($args-warning);
} }
&-danger#{$extra} { &-danger#{$extra} {
$material-color-name: "danger" !default; $args-danger: map-merge($args, (
$material-color-full-name: $material-color-name !default; material-color-name: "danger",
$material-color: $danger !default; material-color-full-name: "danger",
$material-text-color: $darkbg-text !default; material-color: $danger,
@include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1); material-text-color: $darkbg-text
));
@include call-variations-content-mixin($args-danger);
} }
@include generic-variations-colors($mixin-name, $extra, $default, $contrast-factor, $material-param-1) @include generic-variations-colors($args)
} }
@mixin generic-variations-color($mixin-name, $extra, $default, $contrast-factor, $material-color-name, $material-color-number, $material-param-1) { @mixin generic-variations-color($args) {
& -material-#{$material-color-name}#{unquote($material-color-number)}#{$extra} { $material-color-name: map-get($args, material-color-name);
$material-color-full-name: "#{$material-color-name}#{$material-color-number}" !default; $material-color-number: map-get($args, material-color-number);
$material-color: $material-color-full-name !default; $material-color-full-name: "#{$material-color-name}#{$material-color-number}";
$material-text-color: contrast($material-color, $lightbg-text, $darkbg-text, $contrast-factor) !default; $material-color: $material-color-full-name;
@include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1);
& -material-#{$material-color-name}#{unquote($material-color-number)}#{map-get($args, extra)} {
$args-color: map-merge($args, (
material-color-full-name: $material-color-full-name,
material-color: $material-color,
material-text-color: contrast($material-color, $lightbg-text, $darkbg-text, map-get($args, contrast-factor)),
));
@include call-variations-content-mixin($args-color);
} }
} }
$all-variations: unquote("-default, -primary, -info, -success, -warning, -danger") !default; $all-variations: unquote("-default, -primary, -info, -success, -warning, -danger");

View File

@ -1,6 +1,6 @@
@import 'mixins-shared'; @import 'mixins-shared';
@mixin generic-variations-colors($mixin-name, $extra, $default, $contrast-factor, $material-param-1) { @mixin generic-variations-colors($args) {
$material-color-names: "red" "pink" "purple" "deep-purple" "indigo" "blue" "light-blue" "cyan" "teal" "green" "light-green" "lime" "yellow" "amber" "orange" "deep-orange" "brown" "grey" "blue-grey"; $material-color-names: "red" "pink" "purple" "deep-purple" "indigo" "blue" "light-blue" "cyan" "teal" "green" "light-green" "lime" "yellow" "amber" "orange" "deep-orange" "brown" "grey" "blue-grey";
@each $material-color-name in $material-color-names { @each $material-color-name in $material-color-names {
@ -11,7 +11,10 @@
//} //}
// build a single depth color palette // build a single depth color palette
$material-color-number: ""; $args: map-merge($args, (
@include generic-variations-color($mixin-name, $extra, $default, $contrast-factor, $material-color-name, $material-color-number, $material-param-1) material-color-number: ""
));
@include generic-variations-color($args)
} }
} }