UNPKG

@angular-mdc/web

Version:
166 lines (162 loc) 4.66 kB
/** * @license * Copyright (c) Dominic Carretto * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/trimox/angular-mdc-web/blob/master/LICENSE */ import { Directive, NgZone, ElementRef, Input, NgModule } from '@angular/core'; import { Subject, fromEvent } from 'rxjs'; import { takeUntil, filter } from 'rxjs/operators'; import { MDCComponent } from '@angular-mdc/web/base'; import { MDCFloatingLabelFoundation, cssClasses } from '@material/floating-label'; /** * @fileoverview added by tsickle * Generated from: floating-label/floating-label.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class MdcFloatingLabel extends MDCComponent { /** * @param {?} _ngZone * @param {?} elementRef */ constructor(_ngZone, elementRef) { super(elementRef); this._ngZone = _ngZone; this.elementRef = elementRef; /** * Emits whenever the component is destroyed. */ this._destroy = new Subject(); } /** * @return {?} */ getDefaultFoundation() { /** @type {?} */ const adapter = { addClass: (/** * @param {?} className * @return {?} */ (className) => this._getHostElement().classList.add(className)), removeClass: (/** * @param {?} className * @return {?} */ (className) => this._getHostElement().classList.remove(className)), getWidth: (/** * @return {?} */ () => this._getHostElement().scrollWidth), registerInteractionHandler: (/** * @return {?} */ () => { }), deregisterInteractionHandler: (/** * @return {?} */ () => { }) }; return new MDCFloatingLabelFoundation(adapter); } /** * @return {?} */ ngAfterContentInit() { this._loadListeners(); } /** * @return {?} */ ngOnDestroy() { this._destroy.next(); this._destroy.complete(); } /** * Returns the width of the label element. * @return {?} */ getWidth() { return this._foundation.getWidth(); } /** * Styles the label to produce the label shake for errors. * @param {?} shouldShake * @return {?} */ shake(shouldShake) { this._foundation.shake(shouldShake); } /** * Styles the label to float or dock. * @param {?} shouldFloat * @return {?} */ float(shouldFloat) { this._foundation.float(shouldFloat); } /** * @private * @return {?} */ _loadListeners() { this._ngZone.runOutsideAngular((/** * @return {?} */ () => fromEvent(this._getHostElement(), 'animationend') .pipe(takeUntil(this._destroy), filter((/** * @param {?} e * @return {?} */ (e) => e.target === this._getHostElement()))) .subscribe((/** * @return {?} */ () => this._ngZone.run((/** * @return {?} */ () => this._getHostElement().classList.remove(cssClasses.LABEL_SHAKE))))))); } /** * Retrieves the DOM element of the component host. * @private * @return {?} */ _getHostElement() { return this.elementRef.nativeElement; } } MdcFloatingLabel.decorators = [ { type: Directive, args: [{ selector: 'label[mdcFloatingLabel], mdc-floating-label', exportAs: 'mdcFloatingLabel', host: { 'class': 'mdc-floating-label', '[for]': 'for' } },] }, ]; /** @nocollapse */ MdcFloatingLabel.ctorParameters = () => [ { type: NgZone }, { type: ElementRef } ]; MdcFloatingLabel.propDecorators = { for: [{ type: Input }] }; /** * @fileoverview added by tsickle * Generated from: floating-label/module.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class MdcFloatingLabelModule { } MdcFloatingLabelModule.decorators = [ { type: NgModule, args: [{ exports: [MdcFloatingLabel], declarations: [MdcFloatingLabel] },] }, ]; export { MdcFloatingLabel, MdcFloatingLabelModule }; //# sourceMappingURL=floating-label.js.map