-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmegamenu.component.ts
More file actions
77 lines (74 loc) · 2.62 KB
/
megamenu.component.ts
File metadata and controls
77 lines (74 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { Component, Input, TemplateRef } from '@angular/core';
import { NgTemplateOutlet } from '@angular/common';
import { MegaMenu } from 'primeng/megamenu';
import { MegaMenuItem, PrimeTemplate } from 'primeng/api';
import { Badge } from 'primeng/badge';
export type MegaMenuOrientation = 'horizontal' | 'vertical';
export interface MegaMenuModel extends MegaMenuItem {
description?: string;
badge?: string;
}
@Component({
selector: 'megamenu',
host: { style: 'display: contents' },
standalone: true,
imports: [MegaMenu, PrimeTemplate, NgTemplateOutlet, Badge],
template: `
<p-megamenu
[model]="model"
[orientation]="orientation"
[breakpoint]="breakpoint"
[scrollHeight]="scrollHeight"
[disabled]="disabled"
[ariaLabel]="ariaLabel"
[ariaLabelledBy]="ariaLabelledBy"
[tabindex]="tabindex"
>
<ng-template pTemplate="item" let-item let-hasSubmenu="hasSubmenu">
@if (itemTemplate) {
<ng-container [ngTemplateOutlet]="itemTemplate"
[ngTemplateOutletContext]="{ $implicit: item, hasSubmenu: hasSubmenu }">
</ng-container>
} @else {
<a
class="p-megamenu-item-link"
role="menuitem"
tabindex="0"
[class.p-disabled]="item.disabled"
[attr.href]="item.url || null"
[attr.target]="item.target || null"
>
@if (item.icon) {
<span [class]="item.icon + ' p-megamenu-item-icon'"></span>
}
@if ($any(item).description) {
<div class="megamenu-item-label">
<span class="p-megamenu-item-label">{{ item.label }}</span>
<small class="megamenu-item-caption">{{ $any(item).description }}</small>
</div>
} @else {
<span class="p-megamenu-item-label">{{ item.label }}</span>
}
@if ($any(item).badge) {
<p-badge [value]="$any(item).badge"></p-badge>
}
@if (hasSubmenu) {
<span class="p-megamenu-submenu-icon ti ti-chevron-down"></span>
}
</a>
}
</ng-template>
</p-megamenu>
`,
})
export class MegaMenuComponent {
@Input() model: MegaMenuModel[] = [];
@Input() orientation: MegaMenuOrientation = 'horizontal';
@Input() breakpoint: string = '960px';
@Input() scrollHeight: string = '';
@Input() disabled: boolean = false;
@Input() ariaLabel: string | undefined = undefined;
@Input() ariaLabelledBy: string | undefined = undefined;
@Input() tabindex: number = 0;
@Input() itemTemplate: TemplateRef<any> | null = null;
}