forked from vmware-archive/clarity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dropdown-menu.ts
89 lines (87 loc) · 2.71 KB
/
dropdown-menu.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
/*
* Copyright (c) 2016-2018 VMware, Inc. All Rights Reserved.
* This software is released under MIT license.
* The full license information can be found in LICENSE in the root directory of this project.
*/
import { Component, ElementRef, Inject, Injector, Input, Optional, SkipSelf } from '@angular/core';
import { AbstractPopover } from '../common/abstract-popover';
import { Point } from '../common/popover';
import { POPOVER_HOST_ANCHOR } from '../common/popover-host-anchor.token';
@Component({
selector: 'clr-dropdown-menu',
template: `
<ng-content></ng-content>
`,
host: {
'[class.dropdown-menu]': 'true',
},
})
export class ClrDropdownMenu extends AbstractPopover {
constructor(
injector: Injector,
@Optional()
@Inject(POPOVER_HOST_ANCHOR)
parentHost: ElementRef,
@Optional()
@SkipSelf()
nested: ClrDropdownMenu
) {
if (!parentHost) {
throw new Error('clr-dropdown-menu should only be used inside of a clr-dropdown');
}
super(injector, parentHost);
if (!nested) {
// Default positioning for normal dropdown is bottom-left
this.anchorPoint = Point.BOTTOM_LEFT;
this.popoverPoint = Point.LEFT_TOP;
} else {
// Default positioning for nested dropdown is right-top
this.anchorPoint = Point.RIGHT_TOP;
this.popoverPoint = Point.LEFT_TOP;
}
this.popoverOptions.allowMultipleOpen = true;
this.closeOnOutsideClick = true;
}
@Input('clrPosition')
set position(position: string) {
// set the popover values based on menu position
switch (position) {
case 'top-right':
this.anchorPoint = Point.TOP_RIGHT;
this.popoverPoint = Point.RIGHT_BOTTOM;
break;
case 'top-left':
this.anchorPoint = Point.TOP_LEFT;
this.popoverPoint = Point.LEFT_BOTTOM;
break;
case 'bottom-right':
this.anchorPoint = Point.BOTTOM_RIGHT;
this.popoverPoint = Point.RIGHT_TOP;
break;
case 'bottom-left':
this.anchorPoint = Point.BOTTOM_LEFT;
this.popoverPoint = Point.LEFT_TOP;
break;
case 'right-top':
this.anchorPoint = Point.RIGHT_TOP;
this.popoverPoint = Point.LEFT_TOP;
break;
case 'right-bottom':
this.anchorPoint = Point.RIGHT_BOTTOM;
this.popoverPoint = Point.LEFT_BOTTOM;
break;
case 'left-top':
this.anchorPoint = Point.LEFT_TOP;
this.popoverPoint = Point.RIGHT_TOP;
break;
case 'left-bottom':
this.anchorPoint = Point.LEFT_BOTTOM;
this.popoverPoint = Point.RIGHT_BOTTOM;
break;
default:
this.anchorPoint = Point.BOTTOM_LEFT;
this.popoverPoint = Point.LEFT_TOP;
break;
}
}
}