UNPKG

@progress/kendo-angular-gantt

Version:
182 lines (181 loc) 8.46 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { ToolbarTemplateDirective } from './toolbar-template.directive'; import { Component, Input, HostBinding, Output, EventEmitter, HostListener, ElementRef } from '@angular/core'; import { ToolbarNavigationService } from './toolbar-navigation.service'; import { closest, focusableSelector, isDocumentAvailable, isFocusable, isVisible } from '@progress/kendo-angular-common'; import { ViewSelectorComponent } from './view-selector.component'; import { GanttAddTaskComponent } from '../editing/add-task.component'; import { NgTemplateOutlet } from '@angular/common'; import * as i0 from "@angular/core"; import * as i1 from "./toolbar-navigation.service"; /** * @hidden */ export class ToolbarComponent { hostEl; navigationService; context = {}; role = 'toolbar'; hostClasses = true; clickHandler(ev) { if (this.navigable) { const closestFocusable = closest(ev.target, isFocusable); const targetIndex = this.navigationService.focusableContent.indexOf(closestFocusable); if (targetIndex > -1) { this.navigationService.focusIndex = targetIndex; } this.navigationService.updateFocus(); } } arrowLeftListener() { if (this.navigable && isDocumentAvailable()) { this.navigationService.focusIndex--; if (this.navigationService.focusIndex < 0) { this.navigationService.focusIndex = this.navigationService.focusableContent.length - 1; } this.navigationService.updateFocus(); } } arrowRightListener() { if (this.navigable && isDocumentAvailable()) { this.navigationService.focusIndex++; if (this.navigationService.focusIndex >= this.navigationService.focusableContent.length) { this.navigationService.focusIndex = 0; } this.navigationService.updateFocus(); } } activeViewChange = new EventEmitter(); showAddTask; showViewSelector; views; activeView; toolbarTemplate; navigable; set position(value) { this.context.position = this._position = value; } get position() { return this._position; } get toolbarTemplateRef() { return this.toolbarTemplate ? this.toolbarTemplate.templateRef : undefined; } get renderTemplate() { const ganttToolbarTemplate = this.toolbarTemplate; const templatePosition = ganttToolbarTemplate ? ganttToolbarTemplate.position : null; return ganttToolbarTemplate && (templatePosition === 'both' || templatePosition === this.position); } _position; constructor(hostEl, navigationService) { this.hostEl = hostEl; this.navigationService = navigationService; } handleViewChange(view) { this.activeViewChange.emit(view); } ngAfterViewInit() { if (isDocumentAvailable()) { const focusableElements = Array.from(this.hostEl.nativeElement.querySelectorAll(focusableSelector) || []) .filter(el => isVisible(el)); if (focusableElements.length) { this.navigationService.focusableContent = focusableElements; } } } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: ToolbarComponent, deps: [{ token: i0.ElementRef }, { token: i1.ToolbarNavigationService }], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: ToolbarComponent, isStandalone: true, selector: "kendo-gantt-toolbar", inputs: { showAddTask: "showAddTask", showViewSelector: "showViewSelector", views: "views", activeView: "activeView", toolbarTemplate: "toolbarTemplate", navigable: "navigable", position: "position" }, outputs: { activeViewChange: "activeViewChange" }, host: { listeners: { "click": "clickHandler($event)", "keydown.arrowleft": "arrowLeftListener($event)", "keydown.arrowright": "arrowRightListener($event)" }, properties: { "attr.role": "this.role", "class.k-gantt-toolbar": "this.hostClasses", "class.k-toolbar": "this.hostClasses", "class.k-toolbar-md": "this.hostClasses", "class.k-toolbar-solid": "this.hostClasses" } }, providers: [ToolbarNavigationService], ngImport: i0, template: ` @if (!renderTemplate) { @if (showAddTask) { <kendo-gantt-add-task></kendo-gantt-add-task> } <span class="k-spacer k-toolbar-spacer"></span> @if (showViewSelector) { <kendo-gantt-view-selector [views]="views" [activeView]="activeView" (activeViewChange)="handleViewChange($event)"></kendo-gantt-view-selector> } } @if (renderTemplate) { <ng-template [ngTemplateOutlet]="toolbarTemplateRef" [ngTemplateOutletContext]="context" > </ng-template> } `, isInline: true, dependencies: [{ kind: "component", type: GanttAddTaskComponent, selector: "kendo-gantt-add-task", inputs: ["data", "icon", "svgIcon"] }, { kind: "component", type: ViewSelectorComponent, selector: "kendo-gantt-view-selector", inputs: ["views", "activeView"], outputs: ["activeViewChange"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: ToolbarComponent, decorators: [{ type: Component, args: [{ selector: 'kendo-gantt-toolbar', providers: [ToolbarNavigationService], template: ` @if (!renderTemplate) { @if (showAddTask) { <kendo-gantt-add-task></kendo-gantt-add-task> } <span class="k-spacer k-toolbar-spacer"></span> @if (showViewSelector) { <kendo-gantt-view-selector [views]="views" [activeView]="activeView" (activeViewChange)="handleViewChange($event)"></kendo-gantt-view-selector> } } @if (renderTemplate) { <ng-template [ngTemplateOutlet]="toolbarTemplateRef" [ngTemplateOutletContext]="context" > </ng-template> } `, standalone: true, imports: [GanttAddTaskComponent, ViewSelectorComponent, NgTemplateOutlet] }] }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i1.ToolbarNavigationService }], propDecorators: { role: [{ type: HostBinding, args: ['attr.role'] }], hostClasses: [{ type: HostBinding, args: ['class.k-gantt-toolbar'] }, { type: HostBinding, args: ['class.k-toolbar'] }, { type: HostBinding, args: ['class.k-toolbar-md'] }, { type: HostBinding, args: ['class.k-toolbar-solid'] }], clickHandler: [{ type: HostListener, args: ['click', ['$event']] }], arrowLeftListener: [{ type: HostListener, args: ['keydown.arrowleft', ['$event']] }], arrowRightListener: [{ type: HostListener, args: ['keydown.arrowright', ['$event']] }], activeViewChange: [{ type: Output }], showAddTask: [{ type: Input }], showViewSelector: [{ type: Input }], views: [{ type: Input }], activeView: [{ type: Input }], toolbarTemplate: [{ type: Input }], navigable: [{ type: Input }], position: [{ type: Input }] } });