UNPKG

@progress/kendo-angular-grid

Version:

Kendo UI Grid for Angular - high performance data grid with paging, filtering, virtualization, CRUD, and more.

252 lines (249 loc) 10.6 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { Component, Input, Output, EventEmitter, ContentChild } from '@angular/core'; import { trigger, transition, style, animate, state } from '@angular/animations'; import { ColumnMenuItemContentTemplateDirective } from './column-menu-item-content-template.directive'; import { chevronDownIcon, chevronUpIcon } from '@progress/kendo-svg-icons'; import { guid } from '@progress/kendo-angular-common'; import { ColumnMenuService } from './column-menu.service'; import { NgIf, NgTemplateOutlet } from '@angular/common'; import { IconWrapperComponent } from '@progress/kendo-angular-icons'; import * as i0 from "@angular/core"; /** * Represents an item that can be placed inside a * [ColumnMenuTemplate]({% slug api_grid_columnmenutemplatedirective %}) directive. * * @example * ```html * <kendo-grid [columnMenu]="true" ...> * <ng-template kendoGridColumnMenuTemplate let-service="service" let-column="column"> * <kendo-grid-columnmenu-item text="Fit column"></kendo-grid-columnmenu-item> * </ng-template> * </kendo-grid> * ``` */ export class ColumnMenuItemComponent { /** * Fires when the item is clicked. */ itemClick = new EventEmitter(); /** * Fires when the content is expanded. */ expand = new EventEmitter(); /** * Fires when the content is collapsed. */ collapse = new EventEmitter(); /** * Specifies the name of the [font icon](slug:icon_list) * that will be rendered within the item. */ icon; /** * Defines the [SVG icon](slug:svgicon_list) to be rendered within the item. */ svgIcon; /** * Specifies the item text. */ text; /** * Specifies if the item is selected. */ selected; /** * Specifies if the item is disabled. */ disabled; /** * Specifies if the item is expanded. */ expanded; /** * Represents the [ColumnMenuService]({% slug api_grid_columnmenuservice %}) class. * Required to include the item in the column menu keyboard navigation sequence. */ service; contentTemplate; contentState = 'collapsed'; contentId; chevronUpIcon = chevronUpIcon; chevronDownIcon = chevronDownIcon; get expandedIcon() { return this.expanded ? 'arrow-chevron-up' : 'arrow-chevron-down'; } get expandedSvgIcon() { return this.expanded ? this.chevronUpIcon : this.chevronDownIcon; } ngAfterViewInit() { this.contentTemplate && (this.contentId = `k-${guid()}`); } ngOnChanges(changes) { if (changes.expanded) { this.updateContentState(); } } /** * @hidden */ onClick(e) { this.itemClick.emit(e); if (this.contentTemplate) { this.expanded = !this.expanded; this.updateContentState(); if (this.expanded) { this.expand.emit(); } else { this.collapse.emit(); } } } updateContentState() { this.contentState = this.expanded ? 'expanded' : 'collapsed'; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ColumnMenuItemComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: ColumnMenuItemComponent, isStandalone: true, selector: "kendo-grid-columnmenu-item", inputs: { icon: "icon", svgIcon: "svgIcon", text: "text", selected: "selected", disabled: "disabled", expanded: "expanded", service: "service" }, outputs: { itemClick: "itemClick", expand: "expand", collapse: "collapse" }, queries: [{ propertyName: "contentTemplate", first: true, predicate: ColumnMenuItemContentTemplateDirective, descendants: true }], usesOnChanges: true, ngImport: i0, template: ` <div *ngIf="contentTemplate; else content" class="k-expander"> <ng-container [ngTemplateOutlet]="content"></ng-container> </div> <ng-template #content> <div class="k-columnmenu-item" (click)="onClick($event)" (keydown.enter)="onClick($event)" [class.k-selected]="selected" [class.k-disabled]="disabled" role="button" [attr.aria-expanded]="expanded" [attr.aria-controls]="expanded ? contentId : undefined"> <kendo-icon-wrapper [name]="icon" [svgIcon]="svgIcon"></kendo-icon-wrapper> {{ text }} <span *ngIf="contentTemplate" class="k-spacer"></span> <span *ngIf="contentTemplate" class="k-expander-indicator"> <kendo-icon-wrapper [name]="expandedIcon" [svgIcon]="expandedSvgIcon"> </kendo-icon-wrapper> </span> </div> <div *ngIf="contentTemplate" [attr.id]="contentId" [@state]="contentState" [style.overflow]="'hidden'" class="k-columnmenu-item-content"> <ng-container [ngTemplateOutlet]="contentTemplate.templateRef"> </ng-container> </div> </ng-template> `, isInline: true, dependencies: [{ kind: "component", type: IconWrapperComponent, selector: "kendo-icon-wrapper", inputs: ["name", "svgIcon", "innerCssClass", "customFontClass", "size"], exportAs: ["kendoIconWrapper"] }, { kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }], animations: [ trigger('state', [ state('collapsed', style({ display: 'none' })), state('expanded', style({ display: 'block' })), transition('collapsed => expanded', [ style({ height: '0px', display: 'block' }), animate('100ms ease-in', style({ height: '*' })) ]), transition('expanded => collapsed', [ style({ height: '*' }), animate('100ms ease-in', style({ height: '0px' })) ]) ]) ] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ColumnMenuItemComponent, decorators: [{ type: Component, args: [{ animations: [ trigger('state', [ state('collapsed', style({ display: 'none' })), state('expanded', style({ display: 'block' })), transition('collapsed => expanded', [ style({ height: '0px', display: 'block' }), animate('100ms ease-in', style({ height: '*' })) ]), transition('expanded => collapsed', [ style({ height: '*' }), animate('100ms ease-in', style({ height: '0px' })) ]) ]) ], selector: 'kendo-grid-columnmenu-item', template: ` <div *ngIf="contentTemplate; else content" class="k-expander"> <ng-container [ngTemplateOutlet]="content"></ng-container> </div> <ng-template #content> <div class="k-columnmenu-item" (click)="onClick($event)" (keydown.enter)="onClick($event)" [class.k-selected]="selected" [class.k-disabled]="disabled" role="button" [attr.aria-expanded]="expanded" [attr.aria-controls]="expanded ? contentId : undefined"> <kendo-icon-wrapper [name]="icon" [svgIcon]="svgIcon"></kendo-icon-wrapper> {{ text }} <span *ngIf="contentTemplate" class="k-spacer"></span> <span *ngIf="contentTemplate" class="k-expander-indicator"> <kendo-icon-wrapper [name]="expandedIcon" [svgIcon]="expandedSvgIcon"> </kendo-icon-wrapper> </span> </div> <div *ngIf="contentTemplate" [attr.id]="contentId" [@state]="contentState" [style.overflow]="'hidden'" class="k-columnmenu-item-content"> <ng-container [ngTemplateOutlet]="contentTemplate.templateRef"> </ng-container> </div> </ng-template> `, standalone: true, imports: [IconWrapperComponent, NgIf, NgTemplateOutlet] }] }], propDecorators: { itemClick: [{ type: Output }], expand: [{ type: Output }], collapse: [{ type: Output }], icon: [{ type: Input }], svgIcon: [{ type: Input }], text: [{ type: Input }], selected: [{ type: Input }], disabled: [{ type: Input }], expanded: [{ type: Input }], service: [{ type: Input }], contentTemplate: [{ type: ContentChild, args: [ColumnMenuItemContentTemplateDirective] }] } });