Skip to content

Commit 188b1d9

Browse files
committed
feat(material-experimental/mdc-slider): create MatSliderThumbDecorator
1 parent 25193ca commit 188b1d9

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-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: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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 {coerceBooleanProperty} from '@angular/cdk/coercion';
10+
import {
11+
ChangeDetectionStrategy,
12+
ChangeDetectorRef,
13+
Component,
14+
ElementRef,
15+
EventEmitter,
16+
Input,
17+
Output,
18+
ViewChild,
19+
ViewEncapsulation,
20+
} from '@angular/core';
21+
import {Thumb} from '@material/slider';
22+
23+
/**
24+
* Handles displaying the slider knobs and their value indicators.
25+
*/
26+
@Component({
27+
selector: 'mat-slider-start-thumb-decorator, mat-slider-end-thumb-decorator',
28+
templateUrl: 'slider-thumb-decorator.html',
29+
host: {
30+
'class': 'mdc-slider__thumb',
31+
'(mouseenter)': '_mouseenter.emit()',
32+
'(mouseleave)': '_mouseleave.emit()',
33+
},
34+
encapsulation: ViewEncapsulation.None,
35+
changeDetection: ChangeDetectionStrategy.OnPush,
36+
})
37+
export class MatSliderThumbDecorator {
38+
/** Whether the slider is discrete. */
39+
@Input()
40+
get isDiscrete(): boolean { return this._isDiscrete; }
41+
set isDiscrete(v) { this._isDiscrete = coerceBooleanProperty(v); }
42+
private _isDiscrete = false;
43+
44+
/** The text content of the value indicator for a discrete slider. */
45+
@Input()
46+
get valueIndicatorText(): string { return this._valueIndicatorText; }
47+
set valueIndicatorText(v: string) {
48+
this._valueIndicatorText = v;
49+
this._cdr.detectChanges();
50+
}
51+
private _valueIndicatorText: string;
52+
53+
/** Event emitted every time the cursor moves onto the MatSliderThumbDecorator. */
54+
@Output() mouseenter: EventEmitter<void> = new EventEmitter<void>();
55+
56+
/** Event emitted every time the cursor moves away from the MatSliderThumbDecorator. */
57+
@Output() mouseleave: EventEmitter<void> = new EventEmitter<void>();
58+
59+
/** The visible circle for the slider thumb. This reference is used by the SliderAdapter. */
60+
@ViewChild('knob') _knob: ElementRef<HTMLElement>;
61+
62+
constructor(
63+
private _cdr: ChangeDetectorRef,
64+
private _elementRef: ElementRef<HTMLElement>,
65+
) {}
66+
67+
/** Returns the thumb that this decorator corresponds to. */
68+
_getThumb(): Thumb {
69+
return this._getHostElement().tagName === 'MAT-SLIDER-END-THUMB-DECORATOR'
70+
? Thumb.END
71+
: Thumb.START;
72+
}
73+
74+
/** Returns the hosts native HTML element. */
75+
_getHostElement(): HTMLElement {
76+
return this._elementRef.nativeElement;
77+
}
78+
}

0 commit comments

Comments
 (0)