|
1 | | -// TODO(kara): keyboard events for menu navigation |
2 | | -// TODO(kara): prevent-close functionality |
3 | | -// TODO(kara): set position of menu |
| 1 | +import { MdMenu } from './menu-directive'; |
| 2 | +import { MdMenuItem, MdMenuAnchor } from './menu-item'; |
| 3 | +import { MdMenuTrigger } from './menu-trigger'; |
4 | 4 |
|
5 | | -import { |
6 | | - Attribute, |
7 | | - Component, |
8 | | - EventEmitter, |
9 | | - Input, |
10 | | - Output, |
11 | | - TemplateRef, |
12 | | - ViewChild, |
13 | | - ViewEncapsulation |
14 | | -} from '@angular/core'; |
15 | | -import {MenuPositionX, MenuPositionY} from './menu-positions'; |
16 | | -import {MdMenuInvalidPositionX, MdMenuInvalidPositionY} from './menu-errors'; |
17 | | - |
18 | | -@Component({ |
19 | | - moduleId: module.id, |
20 | | - selector: 'md-menu', |
21 | | - host: {'role': 'menu'}, |
22 | | - templateUrl: 'menu.html', |
23 | | - styleUrls: ['menu.css'], |
24 | | - encapsulation: ViewEncapsulation.None, |
25 | | - exportAs: 'mdMenu' |
26 | | -}) |
27 | | -export class MdMenu { |
28 | | - private _showClickCatcher: boolean = false; |
29 | | - |
30 | | - // config object to be passed into the menu's ngClass |
31 | | - private _classList: Object; |
32 | | - |
33 | | - positionX: MenuPositionX = 'after'; |
34 | | - positionY: MenuPositionY = 'below'; |
35 | | - |
36 | | - @ViewChild(TemplateRef) templateRef: TemplateRef<any>; |
37 | | - |
38 | | - constructor(@Attribute('x-position') posX: MenuPositionX, |
39 | | - @Attribute('y-position') posY: MenuPositionY) { |
40 | | - if (posX) { this._setPositionX(posX); } |
41 | | - if (posY) { this._setPositionY(posY); } |
42 | | - } |
43 | | - |
44 | | - /** |
45 | | - * This method takes classes set on the host md-menu element and applies them on the |
46 | | - * menu template that displays in the overlay container. Otherwise, it's difficult |
47 | | - * to style the containing menu from outside the component. |
48 | | - * @param classes list of class names |
49 | | - */ |
50 | | - @Input('class') |
51 | | - set classList(classes: string) { |
52 | | - this._classList = classes.split(' ').reduce((obj: any, className: string) => { |
53 | | - obj[className] = true; |
54 | | - return obj; |
55 | | - }, {}); |
56 | | - } |
57 | | - |
58 | | - @Output() close = new EventEmitter; |
59 | | - |
60 | | - /** |
61 | | - * This function toggles the display of the menu's click catcher element. |
62 | | - * This element covers the viewport when the menu is open to detect clicks outside the menu. |
63 | | - * TODO: internal |
64 | | - */ |
65 | | - _setClickCatcher(bool: boolean): void { |
66 | | - this._showClickCatcher = bool; |
67 | | - } |
68 | | - |
69 | | - private _setPositionX(pos: MenuPositionX): void { |
70 | | - if ( pos !== 'before' && pos !== 'after') { |
71 | | - throw new MdMenuInvalidPositionX(); |
72 | | - } |
73 | | - this.positionX = pos; |
74 | | - } |
75 | | - |
76 | | - private _setPositionY(pos: MenuPositionY): void { |
77 | | - if ( pos !== 'above' && pos !== 'below') { |
78 | | - throw new MdMenuInvalidPositionY(); |
79 | | - } |
80 | | - this.positionY = pos; |
81 | | - } |
82 | | - |
83 | | - private _emitCloseEvent(): void { |
84 | | - this.close.emit(null); |
85 | | - } |
86 | | -} |
| 5 | +export { MdMenu } from './menu-directive'; |
| 6 | +export { MdMenuItem, MdMenuAnchor } from './menu-item'; |
| 7 | +export { MdMenuTrigger } from './menu-trigger'; |
87 | 8 |
|
| 9 | +export const MD_MENU_DIRECTIVES = [MdMenu, MdMenuItem, MdMenuTrigger, MdMenuAnchor]; |
0 commit comments