Skip to content

feat(material-experimental/mdc-slider): implement MatSlider #21680

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

Merged
10 changes: 10 additions & 0 deletions src/material-experimental/mdc-slider/slider-thumb-decorator.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<ng-container *ngIf="isDiscrete">
<div class="mdc-slider__value-indicator-container">
<div class="mdc-slider__value-indicator">
<span class="mdc-slider__value-indicator-text">
{{ valueIndicatorText }}
</span>
</div>
</div>
</ng-container>
<div class="mdc-slider__thumb-knob" #knob></div>
74 changes: 74 additions & 0 deletions src/material-experimental/mdc-slider/slider-thumb-decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef,
EventEmitter,
Input,
Output,
ViewChild,
ViewEncapsulation,
} from '@angular/core';
import {Thumb} from '@material/slider';

/**
* Handles displaying the slider knobs and their value indicators.
*/
@Component({
selector: 'mat-slider-start-thumb-decorator, mat-slider-end-thumb-decorator',
templateUrl: 'slider-thumb-decorator.html',
host: {
'class': 'mdc-slider__thumb',
'(mouseenter)': '_mouseenter.emit()',
'(mouseleave)': '_mouseleave.emit()',
Copy link
Member

Choose a reason for hiding this comment

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

Would these need to account for touch devices?

Copy link
Contributor Author

@wagnermaciel wagnermaciel Jan 25, 2021

Choose a reason for hiding this comment

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

Yes. Would it be acceptable for me to add a TODO here and implement the support for this in a later PR?

},
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MatSliderThumbDecorator {
/** Whether the slider is discrete. */
@Input() isDiscrete: boolean;

/** The text content of the value indicator for a discrete slider. */
@Input()
get valueIndicatorText(): string { return this._valueIndicatorText; }
set valueIndicatorText(v: string) {
this._valueIndicatorText = v;
this._cdr.detectChanges();
}
private _valueIndicatorText: string;

/** Event emitted every time the cursor moves onto the MatSliderThumbDecorator. */
@Output() mouseenter: EventEmitter<void> = new EventEmitter<void>();

/** Event emitted every time the cursor moves away from the MatSliderThumbDecorator. */
@Output() mouseleave: EventEmitter<void> = new EventEmitter<void>();

/** The visible circle for the slider thumb. This reference is used by the SliderAdapter. */
@ViewChild('knob') _knob: ElementRef<HTMLElement>;

constructor(
private _cdr: ChangeDetectorRef,
private _elementRef: ElementRef<HTMLElement>,
) {}

/** Returns the thumb that this decorator corresponds to. */
_getThumb(): Thumb {
return this._getHostElement().tagName === 'MAT-SLIDER-END-THUMB-DECORATOR'
? Thumb.END
: Thumb.START;
}

/** Returns the hosts native HTML element. */
_getHostElement(): HTMLElement {
return this._elementRef.nativeElement;
}
}