Skip to content

Commit 749bc0d

Browse files
committed
feat(material-experimental/mdc-slider): add slider styles
* implement _MatSliderMixinBase * add color input to MatSlider * extend _MatSliderMixinBase from MatSlider * use without-ripple mixin for slider.scss * @include all other mdc-slider mixins except thumb-ripple-color in _slider-theme.scss * implement primary, accent, and warn colors in _slider-theme.scss
1 parent 705dd97 commit 749bc0d

File tree

3 files changed

+82
-12
lines changed

3 files changed

+82
-12
lines changed

src/material-experimental/mdc-slider/_slider-theme.scss

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,43 @@
1-
// TODO: disabled until we implement the new MDC slider.
2-
// @import '@material/slider/mixins.import';
1+
@import '@material/slider/slider';
2+
@import '@material/slider/slider-theme';
33
@import '../mdc-helpers/mdc-helpers';
4+
@import '../../material/core/ripple/ripple';
45

56
@mixin mat-mdc-slider-color($config-or-theme) {
67
$config: mat-get-color-config($config-or-theme);
78
@include mat-using-mdc-theme($config) {
8-
// TODO: disabled until we implement the new MDC slider.
9-
// @include mdc-slider-core-styles($query: $mat-theme-styles-query);
9+
@include without-ripple($query: $mat-theme-styles-query);
1010

1111
.mat-mdc-slider {
12+
&.mat-primary, &.mat-accent, &.mat-warn {
13+
@include value-indicator-color(
14+
$color: #000,
15+
$opacity: 0.6,
16+
$query: $mat-theme-styles-query
17+
);
18+
@include value-indicator-text-color(
19+
$color: on-primary,
20+
$query: $mat-theme-styles-query
21+
);
22+
@include tick-mark-active-color(
23+
$color-or-map: (
24+
default: on-primary,
25+
disabled: on-primary,
26+
),
27+
$query: $mat-theme-styles-query
28+
);
29+
}
30+
1231
&.mat-primary {
13-
// TODO: disabled until we implement the new MDC slider.
14-
// @include mdc-slider-color-accessible(primary, $mat-theme-styles-query);
32+
@include custom-slider-color(primary);
33+
}
34+
35+
&.mat-accent {
36+
@include custom-slider-color(secondary);
1537
}
1638

1739
&.mat-warn {
18-
// TODO: disabled until we implement the new MDC slider.
19-
// @include mdc-slider-color-accessible(error, $mat-theme-styles-query);
40+
@include custom-slider-color(error);
2041
}
2142
}
2243
}
@@ -25,8 +46,7 @@
2546
@mixin mat-mdc-slider-typography($config-or-theme) {
2647
$config: mat-get-typography-config($config-or-theme);
2748
@include mat-using-mdc-typography($config) {
28-
// TODO: disabled until we implement the new MDC slider.
29-
// @include mdc-slider-core-styles($query: $mat-typography-styles-query);
49+
@include without-ripple($query: $mat-typography-styles-query);
3050
}
3151
}
3252

@@ -51,3 +71,38 @@
5171
}
5272
}
5373

74+
@mixin custom-slider-color($color) {
75+
@include thumb-color(
76+
$color-or-map: (
77+
default: $color,
78+
disabled: on-surface,
79+
),
80+
$query: $mat-theme-styles-query
81+
);
82+
@include track-active-color(
83+
$color-or-map: (
84+
default: $color,
85+
disabled: on-surface,
86+
),
87+
$query: $mat-theme-styles-query
88+
);
89+
@include track-inactive-color(
90+
$color-or-map: (
91+
default: $color,
92+
disabled: on-surface,
93+
),
94+
$query: $mat-theme-styles-query
95+
);
96+
@include tick-mark-inactive-color(
97+
$color-or-map: (
98+
default: $color,
99+
disabled: on-primary,
100+
),
101+
$query: $mat-theme-styles-query
102+
);
103+
@include mat-ripple-color((
104+
foreground: (
105+
base: mdc-theme-prop-value($color)
106+
),
107+
));
108+
}

src/material-experimental/mdc-slider/slider.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
@import '@material/slider/slider';
2-
@include core-styles;
2+
@import '../mdc-helpers/mdc-helpers';
3+
4+
@include without-ripple($query: $mat-base-styles-query);
35

46
.mdc-slider {
57
display: block;

src/material-experimental/mdc-slider/slider.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
ViewChildren,
3333
ViewEncapsulation,
3434
} from '@angular/core';
35+
import {CanColorCtor, mixinColor} from '@angular/material/core';
3536
import {SpecificEventListener, EventType} from '@material/base';
3637
import {MDCSliderAdapter, MDCSliderFoundation, Thumb, TickMark} from '@material/slider';
3738

@@ -196,6 +197,16 @@ export class MatSliderThumb implements AfterViewInit {
196197
static ngAcceptInputType_value: NumberInput;
197198
}
198199

200+
// Boilerplate for applying mixins to MatSlider.
201+
/** @docs-private */
202+
class MatSliderBase {
203+
constructor(public _elementRef: ElementRef<HTMLElement>) {}
204+
}
205+
const _MatSliderMixinBase:
206+
CanColorCtor &
207+
typeof MatSliderBase =
208+
mixinColor(MatSliderBase, 'primary');
209+
199210
/**
200211
* Allows users to select from a range of values by moving the slider thumb. It is similar in
201212
* behavior to the native `<input type="range">` element.
@@ -214,8 +225,9 @@ export class MatSliderThumb implements AfterViewInit {
214225
exportAs: 'matSlider',
215226
changeDetection: ChangeDetectionStrategy.OnPush,
216227
encapsulation: ViewEncapsulation.None,
228+
inputs: ['color'],
217229
})
218-
export class MatSlider implements AfterViewInit, OnDestroy {
230+
export class MatSlider extends _MatSliderMixinBase implements AfterViewInit, OnDestroy {
219231
/** The slider thumb(s). */
220232
@ViewChildren('thumb') _thumbs: QueryList<ElementRef<HTMLElement>>;
221233

@@ -314,6 +326,7 @@ export class MatSlider implements AfterViewInit, OnDestroy {
314326
readonly _elementRef: ElementRef<HTMLElement>,
315327
private readonly _platform: Platform,
316328
@Inject(DOCUMENT) document: any) {
329+
super(_elementRef);
317330
this._document = document;
318331
this._window = this._document.defaultView || window;
319332
}

0 commit comments

Comments
 (0)