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

feat(slide-toggle): use ripple service #3068

Merged
merged 1 commit into from
Feb 16, 2017
Merged
Show file tree
Hide file tree
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
37 changes: 18 additions & 19 deletions src/lib/slide-toggle/_slide-toggle-theme.scss
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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) {
Expand All @@ -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);
}

}
Expand Down
9 changes: 7 additions & 2 deletions src/lib/slide-toggle/slide-toggle.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<label class="mat-slide-toggle-label">
<label class="mat-slide-toggle-label" #label>

<div class="mat-slide-toggle-container">
<div class="mat-slide-toggle-bar"></div>
Expand All @@ -9,7 +9,12 @@
(slideend)="_onDragEnd()">

<div class="mat-slide-toggle-thumb">
<div class="mat-ink-ripple"></div>
<div class="mat-slide-toggle-ripple" md-ripple
[mdRippleTrigger]="label"
[mdRippleCentered]="true"
[mdRippleDisabled]="disabled"
[mdRippleSpeedFactor]="0.3">
</div>
</div>
</div>

Expand Down
21 changes: 13 additions & 8 deletions src/lib/slide-toggle/slide-toggle.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ $mat-slide-toggle-bar-height: 14px !default;
$mat-slide-toggle-thumb-size: 20px !default;
$mat-slide-toggle-margin: 16px !default;
$mat-slide-toggle-spacing: 8px !default;
$mat-slide-toggle-ripple-radius: 23px !default;


@mixin mat-switch-ripple() {
// Temporary ripple effect for the thumb of the slide-toggle.
// Bind to the parent selector and specify the current palette.
@include mat-temporary-ink-ripple(slide-toggle, true);
}

.mat-slide-toggle {
display: flex;
height: $mat-slide-toggle-height;
Expand All @@ -39,8 +34,6 @@ $mat-slide-toggle-spacing: 8px !default;
}
}

@include mat-switch-ripple();

&.mat-disabled {

.mat-slide-toggle-label, .mat-slide-toggle-container {
Expand Down Expand Up @@ -169,3 +162,15 @@ $mat-slide-toggle-spacing: 8px !default;
transition-property: background-color;
transition-delay: 50ms;
}

// Ripple positioning for the slide-toggle. Moves the ripple container into the center of the thumb.
.mat-slide-toggle-ripple {
position: absolute;
top: $mat-slide-toggle-thumb-size / 2 - $mat-slide-toggle-ripple-radius;
left: $mat-slide-toggle-thumb-size / 2 - $mat-slide-toggle-ripple-radius;
height: $mat-slide-toggle-ripple-radius * 2;
width: $mat-slide-toggle-ripple-radius * 2;
border-radius: 50%;
z-index: 1;
pointer-events: none;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should check if your editor has an option to add \n on save :p I think most editors have some type of option for this.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmalerba Why is it useful to have a newline at the end of each file? Or is this just convention? Always wondered about that 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha. That's a good idea. I've had so many lint issues with that - Thanks! 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dahaupt good question, I never thought about why that's the convention we use, but apparently that's just how lines are defined: http://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline

3 changes: 2 additions & 1 deletion src/lib/slide-toggle/slide-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
CompatibilityModule,
} from '../core';
import {Observable} from 'rxjs/Observable';
import {MdRippleModule} from '../core/ripple/ripple';


export const MD_SLIDE_TOGGLE_VALUE_ACCESSOR: any = {
Expand Down Expand Up @@ -339,7 +340,7 @@ class SlideToggleRenderer {


@NgModule({
imports: [FormsModule, CompatibilityModule],
imports: [FormsModule, MdRippleModule, CompatibilityModule],
exports: [MdSlideToggle, CompatibilityModule],
declarations: [MdSlideToggle],
providers: [{provide: HAMMER_GESTURE_CONFIG, useClass: GestureConfig}],
Expand Down