Skip to content

Commit 28f1ec3

Browse files
mmalerbatinayuangao
authored andcommitted
feat(slider): add theme color support (#3766)
1 parent ccdd0f2 commit 28f1ec3

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

src/demo-app/slider/slider-demo.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ <h1>Default Slider</h1>
22
Label <md-slider #slidey></md-slider>
33
{{slidey.value}}
44

5+
<h1>Colors</h1>
6+
<md-slider color="primary" value="50" thumbLabel></md-slider>
7+
<md-slider color="accent" value="50" thumbLabel></md-slider>
8+
<md-slider color="warn" value="50" thumbLabel></md-slider>
9+
510
<h1>Slider with Min and Max</h1>
611
<input [(ngModel)]="min">
712
<md-slider [min]="min" [max]="max" tickInterval="5" #slider2></md-slider>

src/lib/slider/_slider-theme.scss

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44

55
@mixin mat-slider-theme($theme) {
6+
$primary: map-get($theme, primary);
67
$accent: map-get($theme, accent);
8+
$warn: map-get($theme, warn);
79

810
$mat-slider-off-color: rgba(black, 0.26);
911
$mat-slider-off-focused-color: rgba(black, 0.38);
@@ -17,24 +19,38 @@
1719
background-color: $mat-slider-off-color;
1820
}
1921

20-
.mat-slider-track-fill {
21-
background-color: mat-color($accent);
22+
.mat-slider-track-fill,
23+
.mat-slider-thumb,
24+
.mat-slider-thumb-label {
25+
.mat-primary & {
26+
background-color: mat-color($primary);
27+
}
28+
29+
.mat-accent & {
30+
background-color: mat-color($accent);
31+
}
32+
33+
.mat-warn & {
34+
background-color: mat-color($warn);
35+
}
2236
}
2337

2438
.mat-slider-focus-ring {
2539
background-color: $mat-slider-focus-ring-color;
2640
}
2741

28-
.mat-slider-thumb {
29-
background-color: mat-color($accent);
30-
}
42+
.mat-slider-thumb-label-text {
43+
.mat-primary & {
44+
color: mat-color($primary, default-contrast);
45+
}
3146

32-
.mat-slider-thumb-label {
33-
background-color: mat-color($accent);
34-
}
47+
.mat-accent & {
48+
color: mat-color($accent, default-contrast);
49+
}
3550

36-
.mat-slider-thumb-label-text {
37-
color: mat-color($accent, default-contrast);
51+
.mat-warn & {
52+
color: mat-color($warn, default-contrast);
53+
}
3854
}
3955

4056
.mat-slider:hover,

src/lib/slider/slider.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ export class MdSliderChange {
8484
'[attr.aria-valuemax]': 'max',
8585
'[attr.aria-valuemin]': 'min',
8686
'[attr.aria-valuenow]': 'value',
87+
'[class.mat-primary]': 'color == "primary"',
88+
'[class.mat-accent]': 'color != "primary" && color != "warn"',
89+
'[class.mat-warn]': 'color == "warn"',
8790
'[class.mat-slider-disabled]': 'disabled',
8891
'[class.mat-slider-has-ticks]': 'tickInterval',
8992
'[class.mat-slider-horizontal]': '!vertical',
@@ -204,6 +207,8 @@ export class MdSlider implements ControlValueAccessor, OnDestroy {
204207
set vertical(value: any) { this._vertical = coerceBooleanProperty(value); }
205208
private _vertical = false;
206209

210+
@Input() color: 'primary' | 'accent' | 'warn' = 'accent';
211+
207212
/** Event emitted when the slider value has changed. */
208213
@Output() change = new EventEmitter<MdSliderChange>();
209214

0 commit comments

Comments
 (0)