@angular-mdc/web
Version:
386 lines (382 loc) • 12.5 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, ChangeDetectionStrategy, ViewEncapsulation, NgZone, ElementRef, Input, ViewChild, NgModule } from '@angular/core';
import { __extends } from 'tslib';
import { supportsPassiveEventListeners, Platform } from '@angular/cdk/platform';
import { Subject, merge, fromEvent } from 'rxjs';
import { takeUntil, filter } from 'rxjs/operators';
import { MDCComponent } from '@angular-mdc/web/base';
import { matches } from '@angular-mdc/web/dom';
import { MDCTabScrollerFoundation, util } from '@material/tab-scroller';
/**
* @fileoverview added by tsickle
* Generated from: tab-scroller/tab-scroller.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var SCROLLER_EVENTS = [
'keydown',
'mousedown',
'pointerdown',
'touchstart',
'wheel'
];
var MdcTabScroller = /** @class */ (function (_super) {
__extends(MdcTabScroller, _super);
function MdcTabScroller(_ngZone, _platform, elementRef) {
var _this = _super.call(this, elementRef) || this;
_this._ngZone = _ngZone;
_this._platform = _platform;
_this.elementRef = elementRef;
/**
* Emits whenever the component is destroyed.
*/
_this._destroy = new Subject();
_this._align = null;
_this._scrollAreaEventsSubscription = null;
return _this;
}
Object.defineProperty(MdcTabScroller.prototype, "align", {
get: /**
* @return {?}
*/
function () {
return this._align;
},
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
this.setAlign(value);
},
enumerable: true,
configurable: true
});
Object.defineProperty(MdcTabScroller.prototype, "scrollAreaEvents", {
/** Combined stream of all of the scroll area events. */
get: /**
* Combined stream of all of the scroll area events.
* @return {?}
*/
function () {
var _this = this;
return merge.apply(void 0, SCROLLER_EVENTS.map((/**
* @param {?} evt
* @return {?}
*/
function (evt) {
return fromEvent(_this._getScrollArea(), evt, { passive: supportsPassiveEventListeners() });
})));
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
MdcTabScroller.prototype.getDefaultFoundation = /**
* @return {?}
*/
function () {
var _this = this;
/** @type {?} */
var adapter = {
eventTargetMatchesSelector: (/**
* @param {?} evtTarget
* @param {?} selector
* @return {?}
*/
function (evtTarget, selector) { return matches(evtTarget, selector); }),
addClass: (/**
* @param {?} className
* @return {?}
*/
function (className) { return _this._getHostElement().classList.add(className); }),
removeClass: (/**
* @param {?} className
* @return {?}
*/
function (className) { return _this._getHostElement().classList.remove(className); }),
addScrollAreaClass: (/**
* @param {?} className
* @return {?}
*/
function (className) { return _this.area.nativeElement.classList.add(className); }),
setScrollAreaStyleProperty: (/**
* @param {?} propName
* @param {?} value
* @return {?}
*/
function (propName, value) {
return _this.area.nativeElement.style.setProperty(propName, value);
}),
setScrollContentStyleProperty: (/**
* @param {?} propName
* @param {?} value
* @return {?}
*/
function (propName, value) {
return _this.content.nativeElement.style.setProperty(propName, value);
}),
getScrollContentStyleValue: (/**
* @param {?} propName
* @return {?}
*/
function (propName) {
return _this._platform.isBrowser ? window.getComputedStyle(_this.content.nativeElement).getPropertyValue(propName) : '';
}),
setScrollAreaScrollLeft: (/**
* @param {?} scrollX
* @return {?}
*/
function (scrollX) { return _this.area.nativeElement.scrollLeft = scrollX; }),
getScrollAreaScrollLeft: (/**
* @return {?}
*/
function () { return _this.area.nativeElement.scrollLeft; }),
getScrollContentOffsetWidth: (/**
* @return {?}
*/
function () { return _this.content.nativeElement.offsetWidth; }),
getScrollAreaOffsetWidth: (/**
* @return {?}
*/
function () { return _this.area.nativeElement.offsetWidth; }),
computeScrollAreaClientRect: (/**
* @return {?}
*/
function () {
return _this._platform.isBrowser ? _this.area.nativeElement.getBoundingClientRect() : {};
}),
computeScrollContentClientRect: (/**
* @return {?}
*/
function () {
return _this._platform.isBrowser ? _this.content.nativeElement.getBoundingClientRect() : {};
}),
computeHorizontalScrollbarHeight: (/**
* @return {?}
*/
function () {
return _this._platform.isBrowser ? util.computeHorizontalScrollbarHeight(document) : 0;
})
};
return new MDCTabScrollerFoundation(adapter);
};
/**
* @return {?}
*/
MdcTabScroller.prototype.ngAfterViewInit = /**
* @return {?}
*/
function () {
this._foundation.init();
this._loadListeners();
};
/**
* @return {?}
*/
MdcTabScroller.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
this._destroy.next();
this._destroy.complete();
if (this._scrollAreaEventsSubscription) {
this._scrollAreaEventsSubscription.unsubscribe();
}
};
/**
* @param {?} align
* @return {?}
*/
MdcTabScroller.prototype.setAlign = /**
* @param {?} align
* @return {?}
*/
function (align) {
this._getHostElement().classList.remove("mdc-tab-scroller--align-" + this._align);
this._align = align;
if (align) {
this._getHostElement().classList.add("mdc-tab-scroller--align-" + align);
}
};
/** Returns the current visual scroll position */
/**
* Returns the current visual scroll position
* @return {?}
*/
MdcTabScroller.prototype.getScrollPosition = /**
* Returns the current visual scroll position
* @return {?}
*/
function () {
if (!this._platform.isBrowser) {
return -1;
}
return this._foundation.getScrollPosition();
};
/** Returns the width of the scroll content */
/**
* Returns the width of the scroll content
* @return {?}
*/
MdcTabScroller.prototype.getScrollContentWidth = /**
* Returns the width of the scroll content
* @return {?}
*/
function () {
return this.content.nativeElement.offsetWidth;
};
/** Increments the scroll value by the given amount */
/**
* Increments the scroll value by the given amount
* @param {?} scrollXIncrement
* @return {?}
*/
MdcTabScroller.prototype.incrementScroll = /**
* Increments the scroll value by the given amount
* @param {?} scrollXIncrement
* @return {?}
*/
function (scrollXIncrement) {
if (!this._platform.isBrowser) {
return -1;
}
this._foundation.incrementScroll(scrollXIncrement);
};
/** Scrolls to the given pixel position */
/**
* Scrolls to the given pixel position
* @param {?} scrollX
* @return {?}
*/
MdcTabScroller.prototype.scrollTo = /**
* Scrolls to the given pixel position
* @param {?} scrollX
* @return {?}
*/
function (scrollX) {
this._foundation.scrollTo(scrollX);
};
/**
* @private
* @return {?}
*/
MdcTabScroller.prototype._loadListeners = /**
* @private
* @return {?}
*/
function () {
var _this = this;
this._scrollAreaEventsSubscription = this.scrollAreaEvents.pipe()
.subscribe((/**
* @return {?}
*/
function () { return _this._foundation.handleInteraction(); }));
this._ngZone.runOutsideAngular((/**
* @return {?}
*/
function () {
return fromEvent(_this._getScrollContent(), 'transitionend')
.pipe(takeUntil(_this._destroy), filter((/**
* @param {?} e
* @return {?}
*/
function (e) {
return e.target === _this._getScrollContent();
})))
.subscribe((/**
* @param {?} evt
* @return {?}
*/
function (evt) { return _this._ngZone.run((/**
* @return {?}
*/
function () { return _this._foundation.handleTransitionEnd(evt); })); }));
}));
};
/**
* @private
* @return {?}
*/
MdcTabScroller.prototype._getScrollArea = /**
* @private
* @return {?}
*/
function () {
return this.area.nativeElement;
};
/**
* @private
* @return {?}
*/
MdcTabScroller.prototype._getScrollContent = /**
* @private
* @return {?}
*/
function () {
return this.content.nativeElement;
};
/** Retrieves the DOM element of the component host. */
/**
* Retrieves the DOM element of the component host.
* @private
* @return {?}
*/
MdcTabScroller.prototype._getHostElement = /**
* Retrieves the DOM element of the component host.
* @private
* @return {?}
*/
function () {
return this.elementRef.nativeElement;
};
MdcTabScroller.decorators = [
{ type: Component, args: [{selector: '[mdcTabScroller], mdc-tab-scroller',
exportAs: 'mdcTabScroller',
host: {
'class': 'mdc-tab-scroller'
},
template: "\n <div #area class=\"mdc-tab-scroller__scroll-area\">\n <div #content class=\"mdc-tab-scroller__scroll-content\">\n <ng-content></ng-content>\n </div>\n </div>\n ",
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None
},] },
];
/** @nocollapse */
MdcTabScroller.ctorParameters = function () { return [
{ type: NgZone },
{ type: Platform },
{ type: ElementRef }
]; };
MdcTabScroller.propDecorators = {
align: [{ type: Input }],
area: [{ type: ViewChild, args: ['area', { static: true },] }],
content: [{ type: ViewChild, args: ['content', { static: true },] }]
};
return MdcTabScroller;
}(MDCComponent));
/**
* @fileoverview added by tsickle
* Generated from: tab-scroller/module.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var MdcTabScrollerModule = /** @class */ (function () {
function MdcTabScrollerModule() {
}
MdcTabScrollerModule.decorators = [
{ type: NgModule, args: [{
exports: [MdcTabScroller],
declarations: [MdcTabScroller]
},] },
];
return MdcTabScrollerModule;
}());
export { MdcTabScroller, MdcTabScrollerModule };
//# sourceMappingURL=tab-scroller.es5.js.map