@progress/kendo-angular-layout
Version:
Kendo UI for Angular Layout Package - a collection of components to create professional application layoyts
183 lines (182 loc) • 8.03 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Component, ElementRef, HostBinding, Input, Renderer2, NgZone, Output, EventEmitter } from '@angular/core';
import { Subscription } from 'rxjs';
import { DIRECTION_CLASSES, HIDDEN_CLASS } from './constants';
import { isTablistHorizontal } from './util';
import { TabScrollEvent } from './events/tabscroll-event';
import { caretAltDownIcon, caretAltLeftIcon, caretAltRightIcon, caretAltUpIcon } from '@progress/kendo-svg-icons';
import { LocalizationService } from '@progress/kendo-angular-l10n';
import { IconWrapperComponent } from '@progress/kendo-angular-icons';
import * as i0 from "@angular/core";
import * as i1 from "@progress/kendo-angular-l10n";
/**
* @hidden
*/
export class TabStripScrollableButtonComponent {
host;
renderer;
ngZone;
localization;
get prevClass() {
return this.prev;
}
get nextClass() {
return !this.prev;
}
prev = false;
tabPosition;
scrollable;
tabScroll = new EventEmitter();
onClick = new EventEmitter();
get hostBoundingClientRect() {
return this.host.nativeElement.getBoundingClientRect();
}
get iconClass() {
return this.scrollButtonIconClass;
}
get customIconClass() {
return this.customScrollButtonIconClass;
}
get svgIcon() {
return this.scrollButtonSVGIcon;
}
caretAltLeftIcon = caretAltLeftIcon;
caretAltRightIcon = caretAltRightIcon;
caretAltUpIcon = caretAltUpIcon;
caretAltDownIcon = caretAltDownIcon;
subs = new Subscription();
constructor(host, renderer, ngZone, localization) {
this.host = host;
this.renderer = renderer;
this.ngZone = ngZone;
this.localization = localization;
}
ngAfterViewInit() {
this.ngZone.runOutsideAngular(() => {
this.subs.add(this.renderer.listen(this.host.nativeElement, 'click', this.clickHandler));
});
}
ngOnDestroy() {
this.subs.unsubscribe();
}
toggle(show) {
this.renderer[show ? 'removeClass' : 'addClass'](this.host.nativeElement, HIDDEN_CLASS);
}
clickHandler = (scrollEvent) => {
const tabStripScrollEvent = this.emitScrollEvent(scrollEvent);
const isTabStripScrollEventPrevented = tabStripScrollEvent.isDefaultPrevented();
if (isTabStripScrollEventPrevented) {
return;
}
const buttonType = this.prev ? 'prev' : 'next';
this.onClick.emit(buttonType);
};
get scrollButtonIconClass() {
const defaultPrevIcon = isTablistHorizontal(this.tabPosition) ?
!this.localization.rtl ?
DIRECTION_CLASSES.left :
DIRECTION_CLASSES.right :
DIRECTION_CLASSES.up;
const defaultNextIcon = isTablistHorizontal(this.tabPosition) ?
!this.localization.rtl ?
DIRECTION_CLASSES.right :
DIRECTION_CLASSES.left :
DIRECTION_CLASSES.down;
if (typeof this.scrollable === 'object') {
const prevIcon = typeof this.scrollable.prevButtonIcon === 'undefined' ? defaultPrevIcon : '';
const nextIcon = typeof this.scrollable.nextButtonIcon === 'undefined' ? defaultNextIcon : '';
if (prevIcon && this.prev) {
return prevIcon;
}
else if (nextIcon && !this.prev) {
return nextIcon;
}
}
}
get customScrollButtonIconClass() {
if (typeof this.scrollable === 'object') {
const prevIcon = this.scrollable.prevButtonIcon;
const nextIcon = this.scrollable.nextButtonIcon;
if (prevIcon && this.prev) {
return `k-icon ${prevIcon}`;
}
if (nextIcon && !this.prev) {
return `k-icon ${nextIcon}`;
}
}
}
get scrollButtonSVGIcon() {
const defaultPrevSVGIcon = isTablistHorizontal(this.tabPosition) ?
!this.localization.rtl ?
this.caretAltLeftIcon :
this.caretAltRightIcon :
this.caretAltUpIcon;
const defaultNextSVGIcon = isTablistHorizontal(this.tabPosition) ?
!this.localization.rtl ?
this.caretAltRightIcon :
this.caretAltLeftIcon :
this.caretAltDownIcon;
if (typeof this.scrollable === 'object') {
const prevIcon = this.scrollable.prevSVGButtonIcon !== undefined ? this.scrollable.prevSVGButtonIcon : defaultPrevSVGIcon;
const nextIcon = this.scrollable.nextSVGButtonIcon !== undefined ? this.scrollable.nextSVGButtonIcon : defaultNextSVGIcon;
if (prevIcon || nextIcon) {
return this.prev ? prevIcon : nextIcon;
}
}
}
emitScrollEvent(event) {
const scrollEvent = new TabScrollEvent({
originalEvent: event
});
this.tabScroll.emit(scrollEvent);
return scrollEvent;
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TabStripScrollableButtonComponent, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i0.NgZone }, { token: i1.LocalizationService }], target: i0.ɵɵFactoryTarget.Component });
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: TabStripScrollableButtonComponent, isStandalone: true, selector: "[kendoTabStripScrollableButton]", inputs: { prev: "prev", tabPosition: "tabPosition", scrollable: "scrollable" }, outputs: { tabScroll: "tabScroll", onClick: "onClick" }, host: { properties: { "class.k-tabstrip-prev": "this.prevClass", "class.k-tabstrip-next": "this.nextClass" } }, ngImport: i0, template: `
<kendo-icon-wrapper
[name]="iconClass"
[customFontClass]="customIconClass"
[svgIcon]="svgIcon"
innerCssClass="k-button-icon"
>
</kendo-icon-wrapper>
`, isInline: true, dependencies: [{ kind: "component", type: IconWrapperComponent, selector: "kendo-icon-wrapper", inputs: ["name", "svgIcon", "innerCssClass", "customFontClass", "size"], exportAs: ["kendoIconWrapper"] }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TabStripScrollableButtonComponent, decorators: [{
type: Component,
args: [{
template: `
<kendo-icon-wrapper
[name]="iconClass"
[customFontClass]="customIconClass"
[svgIcon]="svgIcon"
innerCssClass="k-button-icon"
>
</kendo-icon-wrapper>
`,
// eslint-disable-next-line @angular-eslint/component-selector
selector: '[kendoTabStripScrollableButton]',
standalone: true,
imports: [IconWrapperComponent]
}]
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i0.NgZone }, { type: i1.LocalizationService }]; }, propDecorators: { prevClass: [{
type: HostBinding,
args: ['class.k-tabstrip-prev']
}], nextClass: [{
type: HostBinding,
args: ['class.k-tabstrip-next']
}], prev: [{
type: Input
}], tabPosition: [{
type: Input
}], scrollable: [{
type: Input
}], tabScroll: [{
type: Output
}], onClick: [{
type: Output
}] } });