diff --git a/Gruntfile.js b/Gruntfile.js index 567aaa79..cb08b6bf 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -26,6 +26,19 @@ module.exports = function(grunt) { pattern: /@include (foo1|foo2)\(\);/gi, replacement: '@extend .$1;', order: 2 + }, + + // button variations mixin replacement(s) + //{ // http://rubular.com/r/r198CndVsf + // pattern: /.generic-variations\(unquote\((.*)\).*\).*(\d+).*}\);/m, + // replacement: '@include button-variations(unquote($1), $btn-default, $2%);', + // order: 200 + //} + // attempting multi-line replacement - https://github.com/duvillierA/grunt-less-to-sass/issues/6 + { // http://rubular.com/r/oL4O1x6Wda + pattern: /.generic-variations\(unquote\(("[^"]+")\), (\$.+?(?!\r|\n)), {$\n.+?(?!\r|\n)(\d+).+?(?!\r|\n)}\);$\n/m, + replacement: '@include button-variations(unquote($1), $2, $3%);', + order: 2 } ] diff --git a/sass/_buttons.scss b/sass/_buttons.scss index 4093dc0b..cd1ac012 100644 --- a/sass/_buttons.scss +++ b/sass/_buttons.scss @@ -36,7 +36,7 @@ background-color: contrast($material-color, darken($material-color, 6%), lighten($material-color, 6%), $contrast-factor); }); // BTN flat hover effect - .generic-variations(unquote(".btn-flat:hover:not(.btn-ink)"), $btn-default, { + .generic-variations(unquote(".btn-flat:hover:not(.btn-link)"), $btn-default, { background-color: rgba($material-color, (20/100)); }); diff --git a/sass/_mixins-fullpalette.scss b/sass/_mixins-fullpalette.scss index 59394d52..51ba2ca7 100644 --- a/sass/_mixins-fullpalette.scss +++ b/sass/_mixins-fullpalette.scss @@ -1,13 +1,13 @@ @import 'mixins-shared'; -@mixin generic-variations-colors($mixin-name, $extra, $default, $contrast-factor, $property) { +@mixin generic-variations-colors($mixin-name, $extra, $default, $contrast-factor, $material-param-1) { $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 { // given a color build multiples depths $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 { - @include generic-variations-color($mixin-name, $extra, $default, $contrast-factor, $material-color-name, $material-color-number, $property) + @include generic-variations-color($mixin-name, $extra, $default, $contrast-factor, $material-color-name, $material-color-number, $material-param-1) } } } diff --git a/sass/_mixins-shared.scss b/sass/_mixins-shared.scss index b1771ad5..b919fd02 100644 --- a/sass/_mixins-shared.scss +++ b/sass/_mixins-shared.scss @@ -1,8 +1,8 @@ -@mixin variations-content($material-color-name, $material-color-full-name, $material-color, $material-text-color, $property) { - #{$property}: $material-color; +@mixin variations-content($material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1) { + #{$material-param-1}: unquote($material-color); } -@mixin background-variations-content($material-color-name, $material-color-full-name, $material-color, $material-text-color, $property) { +@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; @@ -11,26 +11,32 @@ } } -@mixin text-variations-content($material-color-name, $material-color-full-name, $material-color, $material-text-color, $property) { +@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); +} + // 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, $property) { +@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, $property); + @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, $property); + @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, $property); + @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 { @error "Unknown mixin: #{$mixin-name}" } } -// usage: @include variations(unquote(" .check"), color, transparent); -@mixin variations($extra, $property, $default) { - @include generic-variations($extra, $default, "variations-content", $property); +// @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); } @mixin background-variations($extra, $default) { @@ -41,6 +47,10 @@ @include generic-variations($extra, $default, "text-variations-content", null); } +@mixin button-variations($extra, $default, $material-param-1) { + @include generic-variations($extra, $default, "variations-content", $material-param-1); +} + // // 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. @@ -51,7 +61,7 @@ // $material-text-color ---> rgba(255,255,255,0.84), rgba(0,0,0,0.84), rgba(255,255,255,0.84) ... // -@mixin generic-variations($extra, $default, $mixin-name, $property) { +@mixin generic-variations($extra, $default, $mixin-name, $material-param-1) { $contrast-factor: 40% !default; @@ -61,75 +71,75 @@ $material-color-full-name: $material-color-name !default; $material-color: $default !default; $material-text-color: $darkbg-text !default; - @include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $property); + @include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1); } &-black#{$extra} { $material-color-name: "black" !default; $material-color-full-name: $material-color-name !default; $material-color: $black !default; $material-text-color: $darkbg-text !default; - @include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $property); + @include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1); } &-white#{$extra} { $material-color-name: "white" !default; $material-color-full-name: $material-color-name !default; $material-color: $white !default; $material-text-color: $lightbg-text !default; - @include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $property); + @include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1); } &-inverse#{$extra} { $material-color-name: "inverse" !default; $material-color-full-name: $material-color-name !default; $material-color: $inverse !default; $material-text-color: contrast($inverse, $lightbg-text, $darkbg-text, $contrast-factor) !default; - @include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $property); + @include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1); } &-primary#{$extra} { $material-color-name: "primary" !default; $material-color-full-name: $material-color-name !default; $material-color: $primary !default; $material-text-color: $darkbg-text !default; - @include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $property); + @include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1); } &-success#{$extra} { $material-color-name: "success" !default; $material-color-full-name: $material-color-name !default; $material-color: $success !default; $material-text-color: $darkbg-text !default; - @include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $property); + @include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1); } &-info#{$extra} { $material-color-name: "info" !default; $material-color-full-name: $material-color-name !default; $material-color: $info !default; $material-text-color: $darkbg-text !default; - @include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $property); + @include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1); } &-warning#{$extra} { $material-color-name: "warning" !default; $material-color-full-name: $material-color-name !default; $material-color: $warning !default; $material-text-color: $darkbg-text !default; - @include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $property); + @include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1); } &-danger#{$extra} { $material-color-name: "danger" !default; $material-color-full-name: $material-color-name !default; $material-color: $danger !default; $material-text-color: $darkbg-text !default; - @include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $property); + @include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1); } - @include generic-variations-colors($mixin-name, $extra, $default, $contrast-factor, $property) + @include generic-variations-colors($mixin-name, $extra, $default, $contrast-factor, $material-param-1) } -@mixin generic-variations-color($mixin-name, $extra, $default, $contrast-factor, $material-color-name, $material-color-number, $property) { +@mixin generic-variations-color($mixin-name, $extra, $default, $contrast-factor, $material-color-name, $material-color-number, $material-param-1) { & -material-#{$material-color-name}#{unquote($material-color-number)}#{$extra} { $material-color-full-name: "#{$material-color-name}#{$material-color-number}" !default; $material-color: $material-color-full-name !default; $material-text-color: contrast($material-color, $lightbg-text, $darkbg-text, $contrast-factor) !default; - @include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $property); + @include call-variations-content-mixin($mixin-name, $material-color-name, $material-color-full-name, $material-color, $material-text-color, $material-param-1); } } diff --git a/sass/_mixins.scss b/sass/_mixins.scss index 5d96f2fa..09fa3921 100644 --- a/sass/_mixins.scss +++ b/sass/_mixins.scss @@ -1,6 +1,6 @@ @import 'mixins-shared'; -@mixin generic-variations-colors($mixin-name, $extra, $default, $contrast-factor, $property) { +@mixin generic-variations-colors($mixin-name, $extra, $default, $contrast-factor, $material-param-1) { $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 { @@ -12,6 +12,6 @@ // build a single depth color palette $material-color-number: ""; - @include generic-variations-color($mixin-name, $extra, $default, $contrast-factor, $material-color-name, $material-color-number, $property) + @include generic-variations-color($mixin-name, $extra, $default, $contrast-factor, $material-color-name, $material-color-number, $material-param-1) } }