From 8541f8e351c1ae8b87a061236d0dbb8b23f1d728 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Fri, 17 Feb 2017 00:56:51 +0100 Subject: [PATCH] feat(slide-toggle): use ripple service (#3068) * Removes the temporary ripple mixin and uses the new ripple service. * Updates the ripple colors to match the specification images (no explicit opacity values are specified) * Triggers ripple on label mousedown (similar as in the Android Nougat implementation) Closes #2900. --- src/lib/slide-toggle/_slide-toggle-theme.scss | 37 +++++++++---------- src/lib/slide-toggle/slide-toggle.html | 9 ++++- src/lib/slide-toggle/slide-toggle.scss | 21 +++++++---- src/lib/slide-toggle/slide-toggle.ts | 3 +- 4 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/lib/slide-toggle/_slide-toggle-theme.scss b/src/lib/slide-toggle/_slide-toggle-theme.scss index d9ed0391a5ec..42b51177b6d5 100644 --- a/src/lib/slide-toggle/_slide-toggle-theme.scss +++ b/src/lib/slide-toggle/_slide-toggle-theme.scss @@ -1,7 +1,6 @@ @import '../core/theming/palette'; @import '../core/theming/theming'; - @mixin _mat-slide-toggle-checked($palette, $thumb-checked-hue) { // Do not apply the checked colors if the toggle is disabled, because the specificity would be to high for // the disabled styles. @@ -16,21 +15,14 @@ } } -// TODO(jelbourn): remove this when the real ripple has been applied to slide-toggle. -@mixin _mat-slide-toggle-ripple($palette, $foreground, $thumb-checked-hue) { - - &.mat-slide-toggle-focused { - &:not(.mat-checked) .mat-ink-ripple { - // When the slide-toggle is not checked and it shows its focus indicator, it should use a 12% opacity - // of black in light themes and 12% of white in dark themes. - background-color: mat-color($foreground, divider); - } - - .mat-ink-ripple { - background-color: mat-color($palette, $thumb-checked-hue, 0.26); - } +// Applies the specified colors to the slide-toggle ripple elements. +@mixin _mat-slide-toggle-ripple($palette, $ripple-unchecked-color, $ripple-checked-color) { + &:not(.mat-checked) .mat-ripple-element { + background-color: $ripple-unchecked-color; + } + .mat-ripple-element { + background-color: $ripple-checked-color; } - } @mixin mat-slide-toggle-theme($theme) { @@ -50,19 +42,26 @@ $bar-normal-color: mat-color($foreground, disabled); $bar-disabled-color: if($is-dark, rgba(white, 0.12), rgba(black, 0.1)); + // Ripple colors are based on the current palette and the state of the slide-toggle. + // See https://material.google.com/components/selection-controls.html#selection-controls-switch + $ripple-checked-opacity: 0.12; + $ripple-unchecked-color: mat-color($foreground, base, if($is-dark, 0.12, 0.06)); + $ripple-primary-color: mat-color($primary, $thumb-checked-hue, $ripple-checked-opacity); + $ripple-accent-color: mat-color($accent, $thumb-checked-hue, $ripple-checked-opacity); + $ripple-warn-color: mat-color($warn, $thumb-checked-hue, $ripple-checked-opacity); + .mat-slide-toggle { @include _mat-slide-toggle-checked($accent, $thumb-checked-hue); - @include _mat-slide-toggle-ripple($accent, $foreground, $thumb-checked-hue); - + @include _mat-slide-toggle-ripple($accent, $ripple-unchecked-color, $ripple-accent-color); &.mat-primary { @include _mat-slide-toggle-checked($primary, $thumb-checked-hue); - @include _mat-slide-toggle-ripple($primary, $foreground, $thumb-checked-hue); + @include _mat-slide-toggle-ripple($accent, $ripple-unchecked-color, $ripple-primary-color); } &.mat-warn { @include _mat-slide-toggle-checked($warn, $thumb-checked-hue); - @include _mat-slide-toggle-ripple($warn, $foreground, $thumb-checked-hue); + @include _mat-slide-toggle-ripple($accent, $ripple-unchecked-color, $ripple-warn-color); } } diff --git a/src/lib/slide-toggle/slide-toggle.html b/src/lib/slide-toggle/slide-toggle.html index 0cc40bbaba47..7b3ecf84efca 100644 --- a/src/lib/slide-toggle/slide-toggle.html +++ b/src/lib/slide-toggle/slide-toggle.html @@ -1,4 +1,4 @@ -