Skip to content

Commit 6b3230c

Browse files
committed
feat(material-experimental/mdc-slider): create MatSliderThumbDecorator
* mouseenter and mouseleave events are needed for displaying ripples * _knob and _getHostElement() will be needed for the SliderAdapter implementation * _getThumb() will be needed to implement the ripples
1 parent 25193ca commit 6b3230c

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<ng-container *ngIf="isDiscrete">
2+
<div class="mdc-slider__value-indicator-container">
3+
<div class="mdc-slider__value-indicator">
4+
<span class="mdc-slider__value-indicator-text">
5+
{{ valueIndicatorText }}
6+
</span>
7+
</div>
8+
</div>
9+
</ng-container>
10+
<div class="mdc-slider__thumb-knob" #knob></div>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {
10+
ChangeDetectionStrategy,
11+
ChangeDetectorRef,
12+
Component,
13+
ElementRef,
14+
EventEmitter,
15+
Input,
16+
Output,
17+
ViewChild,
18+
ViewEncapsulation,
19+
} from '@angular/core';
20+
import {Thumb} from '@material/slider';
21+
22+
/**
23+
* Handles displaying the slider knobs and their value indicators.
24+
*/
25+
@Component({
26+
selector: 'mat-slider-start-thumb-decorator, mat-slider-end-thumb-decorator',
27+
templateUrl: 'slider-thumb-decorator.html',
28+
host: {
29+
'class': 'mdc-slider__thumb',
30+
'(mouseenter)': '_mouseenter.emit()',
31+
'(mouseleave)': '_mouseleave.emit()',
32+
},
33+
encapsulation: ViewEncapsulation.None,
34+
changeDetection: ChangeDetectionStrategy.OnPush,
35+
})
36+
export class MatSliderThumbDecorator {
37+
/** Whether the slider is discrete. */
38+
@Input() isDiscrete: boolean;
39+
40+
/** The text content of the value indicator for a discrete slider. */
41+
@Input()
42+
get valueIndicatorText(): string { return this._valueIndicatorText; }
43+
set valueIndicatorText(v: string) {
44+
this._valueIndicatorText = v;
45+
this._cdr.detectChanges();
46+
}
47+
private _valueIndicatorText: string;
48+
49+
/** Event emitted every time the cursor moves onto the MatSliderThumbDecorator. */
50+
@Output() mouseenter: EventEmitter<void> = new EventEmitter<void>();
51+
52+
/** Event emitted every time the cursor moves away from the MatSliderThumbDecorator. */
53+
@Output() mouseleave: EventEmitter<void> = new EventEmitter<void>();
54+
55+
/** The visible circle for the slider thumb. This reference is used by the SliderAdapter. */
56+
@ViewChild('knob') _knob: ElementRef<HTMLElement>;
57+
58+
constructor(
59+
private _cdr: ChangeDetectorRef,
60+
private _elementRef: ElementRef<HTMLElement>,
61+
) {}
62+
63+
/** Returns the thumb that this decorator corresponds to. */
64+
_getThumb(): Thumb {
65+
return this._getHostElement().tagName === 'MAT-SLIDER-END-THUMB-DECORATOR'
66+
? Thumb.END
67+
: Thumb.START;
68+
}
69+
70+
/** Returns the hosts native HTML element. */
71+
_getHostElement(): HTMLElement {
72+
return this._elementRef.nativeElement;
73+
}
74+
}

0 commit comments

Comments
 (0)