-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.directive.ts
126 lines (111 loc) · 2.81 KB
/
menu.directive.ts
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import {
AfterViewInit,
Directive,
ElementRef,
HostBinding,
HostListener,
Inject,
Input,
OnDestroy,
Self,
} from "@angular/core";
import { MenuCoordinator } from "./menu-coordinator.service";
import { MenuOverlayManager } from "./menu-overlay.service";
import {
MENU,
MENU_TRIGGER,
Menu,
MenuKind,
MenuTrigger,
} from "./menu.types";
@Directive({
selector: "[elxMenuTriggerFor]",
providers: [
{ provide: MENU_TRIGGER, useExisting: MenuTriggerDirective },
MenuOverlayManager,
],
exportAs: "menuTrigger",
})
export class MenuTriggerDirective implements MenuTrigger, OnDestroy {
@HostBinding("class")
readonly hostClass = "elx-menu-trigger";
@Input("elxMenuTriggerFor")
menu!: Menu;
@HostBinding("attr.aria-haspopup")
readonly ariaHasPopup = "menu";
@Input()
get orientation() { return this.overlay.orientation }
set orientation(value) { this.overlay.orientation = value }
constructor (
public elementRef: ElementRef<HTMLElement>,
@Self() public overlay: MenuOverlayManager,
private _coordinator: MenuCoordinator,
) {}
ngOnDestroy(): void {
this._coordinator.unregister(this);
}
@HostListener("mouseenter")
@HostListener("focus")
initialize(): void {
this._coordinator.register(MenuKind.Menu, this, this.overlay);
this.overlay.initialize({
origin: this.elementRef,
menuPanelClass: this.menu.panelClass,
encapsulationId: this.menu.encapsulationId,
});
}
}
@Directive({
selector: "[elxContextMenuTriggerFor]",
providers: [
{ provide: MENU_TRIGGER, useExisting: ContextMenuTriggerDirective },
MenuOverlayManager,
],
})
export class ContextMenuTriggerDirective implements MenuTrigger, AfterViewInit {
@Input("elxContextMenuTriggerFor")
menu!: Menu;
constructor (
public elementRef: ElementRef<HTMLElement>,
@Self() public overlay: MenuOverlayManager,
private _coordinator: MenuCoordinator,
) {}
ngAfterViewInit(): void {
this._coordinator.register(MenuKind.Context, this, this.overlay);
}
}
@Directive({
selector: "[elxSubmenuTriggerFor]",
providers: [
{ provide: MENU_TRIGGER, useExisting: SubmenuTriggerDirective },
MenuOverlayManager,
],
})
export class SubmenuTriggerDirective implements MenuTrigger {
@Input("elxSubmenuTriggerFor")
menu!: Menu;
@HostBinding("attr.aria-haspopup")
readonly ariaHasPopup = "menu";
constructor (
public elementRef: ElementRef<HTMLElement>,
@Self() public overlay: MenuOverlayManager,
private _coordinator: MenuCoordinator,
@Inject(MENU) private _parentMenu: Menu,
) {}
@HostListener("mouseenter")
@HostListener("focus")
initialize(): void {
this._coordinator.register(
MenuKind.Submenu,
this,
this.overlay,
this._parentMenu,
);
this.overlay.initialize({
origin: this.elementRef,
menuPanelClass: this.menu.panelClass,
encapsulationId: this.menu.encapsulationId,
orientation: "horizontal",
});
}
}