@progress/kendo-angular-treelist
Version:
Kendo UI TreeList for Angular - Display hierarchical data in an Angular tree grid view that supports sorting, filtering, paging, and much more.
250 lines (247 loc) • 10.6 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* 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 { NgIf, NgTemplateOutlet } from '@angular/common';
import { trigger, transition, style, animate, state } from '@angular/animations';
import { chevronDownIcon, chevronUpIcon } from '@progress/kendo-svg-icons';
import { IconWrapperComponent } from '@progress/kendo-angular-icons';
import { ColumnMenuItemContentTemplateDirective } from './column-menu-item-content-template.directive';
import { ColumnMenuService } from './column-menu.service';
import { guid } from '@progress/kendo-angular-common';
import * as i0 from "@angular/core";
/**
* Represents an item you can place inside a [`ColumnMenuTemplate`]({% slug api_treelist_columnmenutemplatedirective %}) directive.
*
* @example
* ```html
* <kendo-treelist ...>
* <ng-template kendoTreeListColumnMenuTemplate let-service="service" let-column="column">
* <kendo-treelist-columnmenu-item text="Fit column"></kendo-treelist-columnmenu-item>
* </ng-template>
* </kendo-treelist>
* ```
*/
export class ColumnMenuItemComponent {
/**
* Fires when the item is clicked.
*/
itemClick = new EventEmitter();
/**
* Fires when the content expands.
*/
expand = new EventEmitter();
/**
* Fires when the content collapses.
*/
collapse = new EventEmitter();
/**
* Sets the name of the [font icon](slug:icons#icons-list) rendered for the item.
*/
icon;
/**
* Sets the name of the [SVG icon]({% slug svgicon_list %}) rendered for the item.
*/
svgIcon;
/**
* Sets 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;
/**
* Provides the [ColumnMenuService]({% slug api_treelist_columnmenuservice %}) instance.
* 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-treelist-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
<div
class="k-columnmenu-item"
(click)="onClick($event)"
(keydown.enter)="onClick($event)"
[]="selected"
[]="disabled"
role="button"
[]="expanded"
[]="expanded ? contentId : undefined">
<kendo-icon-wrapper
[]="icon"
[]="svgIcon"></kendo-icon-wrapper>
{{ text }}
<span *ngIf="contentTemplate" class="k-spacer"></span>
<span *ngIf="contentTemplate" class="k-expander-indicator">
<kendo-icon-wrapper
[]="expandedIcon"
[]="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-treelist-columnmenu-item',
template: `
<div *ngIf="contentTemplate; else content" class="k-expander">
<ng-container [ngTemplateOutlet]="content"></ng-container>
</div>
<ng-template
<div
class="k-columnmenu-item"
(click)="onClick($event)"
(keydown.enter)="onClick($event)"
[]="selected"
[]="disabled"
role="button"
[]="expanded"
[]="expanded ? contentId : undefined">
<kendo-icon-wrapper
[]="icon"
[]="svgIcon"></kendo-icon-wrapper>
{{ text }}
<span *ngIf="contentTemplate" class="k-spacer"></span>
<span *ngIf="contentTemplate" class="k-expander-indicator">
<kendo-icon-wrapper
[]="expandedIcon"
[]="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]
}] } });