@angular-mdc/web
Version:
276 lines (272 loc) • 8.02 kB
JavaScript
/**
* @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 { Component, ViewEncapsulation, ChangeDetectionStrategy, ChangeDetectorRef, ElementRef, Input, NgModule } from '@angular/core';
import { Platform } from '@angular/cdk/platform';
import { coerceNumberProperty, coerceBooleanProperty } from '@angular/cdk/coercion';
import { MDCComponent } from '@angular-mdc/web/base';
import { MDCLinearProgressFoundation, strings } from '@material/linear-progress';
/**
* @fileoverview added by tsickle
* Generated from: linear-progress/linear-progress.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class MdcLinearProgress extends MDCComponent {
/**
* @param {?} _platform
* @param {?} _changeDetectorRef
* @param {?} elementRef
*/
constructor(_platform, _changeDetectorRef, elementRef) {
super(elementRef);
this._platform = _platform;
this._changeDetectorRef = _changeDetectorRef;
this.elementRef = elementRef;
this._initialized = false;
/* Label indicating how the progress bar should be announced to the user. */
this.label = undefined;
this._progress = 0;
this._determinate = false;
this._buffer = 0;
this._reversed = false;
this._root = this.elementRef.nativeElement;
}
/**
* @return {?}
*/
get progress() {
return this._progress;
}
/**
* @param {?} value
* @return {?}
*/
set progress(value) {
this._progress = coerceNumberProperty(value);
}
/**
* @return {?}
*/
get determinate() {
return this._determinate;
}
/**
* @param {?} value
* @return {?}
*/
set determinate(value) {
this._determinate = coerceBooleanProperty(value);
}
/**
* @return {?}
*/
get buffer() {
return this._buffer;
}
/**
* @param {?} value
* @return {?}
*/
set buffer(value) {
this._buffer = coerceNumberProperty(value);
}
/**
* @return {?}
*/
get reversed() {
return this._reversed;
}
/**
* @param {?} value
* @return {?}
*/
set reversed(value) {
this._reversed = coerceBooleanProperty(value);
this._syncReversedWithFoundation();
}
/**
* @return {?}
*/
getDefaultFoundation() {
/** @type {?} */
const adapter = {
addClass: (/**
* @param {?} className
* @return {?}
*/
(className) => this._root.classList.add(className)),
forceLayout: (/**
* @return {?}
*/
() => ((/** @type {?} */ (this._root))).offsetWidth),
getPrimaryBar: (/**
* @return {?}
*/
() => this._root.querySelector(strings.PRIMARY_BAR_SELECTOR)),
getBuffer: (/**
* @return {?}
*/
() => this._root.querySelector(strings.BUFFER_SELECTOR)),
hasClass: (/**
* @param {?} className
* @return {?}
*/
(className) => this._root.classList.contains(className)),
removeClass: (/**
* @param {?} className
* @return {?}
*/
(className) => this._root.classList.remove(className)),
setStyle: (/**
* @param {?} el
* @param {?} styleProperty
* @param {?} value
* @return {?}
*/
(el, styleProperty, value) => el.style.setProperty(styleProperty, value)),
removeAttribute: (/**
* @param {?} name
* @return {?}
*/
(name) => this._root.removeAttribute(name)),
setAttribute: (/**
* @param {?} name
* @param {?} value
* @return {?}
*/
(name, value) => this._root.setAttribute(name, value))
};
return new MDCLinearProgressFoundation(adapter);
}
/**
* @return {?}
*/
ngOnInit() {
if (this._platform.isBrowser) {
this._initialized = true;
this._foundation.init();
this._syncProgressWithFoundation();
this._syncBufferWithFoundation();
this._syncDeterminateWithFoundation();
this._syncReversedWithFoundation();
this._changeDetectorRef.markForCheck();
}
}
/**
* @param {?} changes
* @return {?}
*/
ngOnChanges(changes) {
if (!this._initialized) {
return;
}
if (changes['progress']) {
this._syncProgressWithFoundation();
}
if (changes['buffer']) {
this._syncBufferWithFoundation();
}
if (changes['determinate']) {
this._syncDeterminateWithFoundation();
}
if (changes['reversed']) {
this._syncReversedWithFoundation();
}
}
/**
* @return {?}
*/
open() {
this._foundation.open();
}
/**
* @return {?}
*/
close() {
this._foundation.close();
}
/**
* @private
* @return {?}
*/
_syncProgressWithFoundation() {
this._foundation.setProgress(this.progress);
}
/**
* @private
* @return {?}
*/
_syncBufferWithFoundation() {
this._foundation.setBuffer(this.buffer);
}
/**
* @private
* @return {?}
*/
_syncDeterminateWithFoundation() {
this._foundation.setDeterminate(this.determinate);
}
/**
* @private
* @return {?}
*/
_syncReversedWithFoundation() {
this._foundation.setReverse(this.reversed);
}
}
MdcLinearProgress.decorators = [
{ type: Component, args: [{selector: 'mdc-linear-progress',
exportAs: 'mdcLinearProgress',
host: {
'role': 'progressbar',
'class': 'mdc-linear-progress',
'[class.mdc-linear-progress--indeterminate]': '!determinate',
'[attr.aria-label]': 'label',
'aria-valuemin': '0',
'aria-valuemax': '100'
},
template: `
<div class="mdc-linear-progress__buffering-dots"></div>
<div class="mdc-linear-progress__buffer"></div>
<div class="mdc-linear-progress__bar mdc-linear-progress__primary-bar">
<span class="mdc-linear-progress__bar-inner"></span>
</div>
<div class="mdc-linear-progress__bar mdc-linear-progress__secondary-bar">
<span class="mdc-linear-progress__bar-inner"></span>
</div>`,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush
},] },
];
/** @nocollapse */
MdcLinearProgress.ctorParameters = () => [
{ type: Platform },
{ type: ChangeDetectorRef },
{ type: ElementRef }
];
MdcLinearProgress.propDecorators = {
label: [{ type: Input }],
progress: [{ type: Input }],
determinate: [{ type: Input }],
buffer: [{ type: Input }],
reversed: [{ type: Input }]
};
/**
* @fileoverview added by tsickle
* Generated from: linear-progress/module.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class MdcLinearProgressModule {
}
MdcLinearProgressModule.decorators = [
{ type: NgModule, args: [{
exports: [MdcLinearProgress],
declarations: [MdcLinearProgress]
},] },
];
export { MdcLinearProgress, MdcLinearProgressModule };
//# sourceMappingURL=linear-progress.js.map