Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(slide-toggle): respect primary palette of theme #12698

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 22 additions & 25 deletions src/lib/slide-toggle/_slide-toggle-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@
}

.mat-slide-toggle-bar {
background-color: mat-color($palette, $thumb-checked-hue, 0.5);
// Opacity is determined from the specs for the selection controls.
// See: https://material.io/design/components/selection-controls.html#specs
background-color: mat-color($palette, $thumb-checked-hue, 0.54);
}
}
}

// 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;
.mat-ripple-element {
// Set no opacity for the ripples because the ripple opacity will be adjusted dynamically
// based on the type of interaction with the slide-toggle (e.g. for hover, focus)
background-color: mat-color($palette, $thumb-checked-hue);
}
}
}

Expand All @@ -34,36 +32,35 @@
$background: map-get($theme, background);
$foreground: map-get($theme, foreground);

// Color hues based on the specs, which prescribe different hues for dark and light themes
// https://material.google.com/components/selection-controls.html#selection-controls-switch
$thumb-normal-hue: if($is-dark, 400, 50);
$thumb-checked-hue: if($is-dark, 200, 500);
// Color hues are based on the specs which briefly show the hues that are applied to a switch.
// The 2018 specs no longer describe how dark switches should look like. Due to the lack of
// information for dark themed switches, we keep the old behavior that is based on the previous
// specifications. See: https://material.io/design/components/selection-controls.html#specs
$thumb-unchecked-hue: if($is-dark, 400, 50);
$thumb-checked-hue: if($is-dark, 200, default);
$thumb-disabled-hue: if($is-dark, 800, 400);

$bar-normal-color: mat-color($foreground, disabled);
$bar-unchecked-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-unchecked-color: mat-color($foreground, base);
$ripple-primary-color: mat-color($primary, $thumb-checked-hue);
$ripple-accent-color: mat-color($accent, $thumb-checked-hue);
$ripple-warn-color: mat-color($warn, $thumb-checked-hue);

.mat-slide-toggle {
@include _mat-slide-toggle-checked($accent, $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($accent, $ripple-unchecked-color, $ripple-primary-color);
}

&.mat-warn {
@include _mat-slide-toggle-checked($warn, $thumb-checked-hue);
@include _mat-slide-toggle-ripple($accent, $ripple-unchecked-color, $ripple-warn-color);
}

&:not(.mat-checked) .mat-ripple-element {
// Set no opacity for the ripples because the ripple opacity will be adjusted dynamically
// based on the type of interaction with the slide-toggle (e.g. for hover, focus)
background-color: $ripple-unchecked-color;
}
}

.mat-disabled {
Expand All @@ -79,11 +76,11 @@
}

.mat-slide-toggle-thumb {
background-color: mat-color($mat-grey, $thumb-normal-hue);
background-color: mat-color($mat-grey, $thumb-unchecked-hue);
}

.mat-slide-toggle-bar {
background-color: $bar-normal-color;
background-color: $bar-unchecked-color;
}
}

Expand Down