Skip to content

Commit 54c6158

Browse files
karahansl
authored andcommitted
chore(menu): change export to menu.ts (#895)
1 parent c68efbd commit 54c6158

File tree

6 files changed

+96
-92
lines changed

6 files changed

+96
-92
lines changed

src/components/menu/menu-directive.ts

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

src/components/menu/menu-trigger.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import {
99
AfterViewInit,
1010
OnDestroy
1111
} from '@angular/core';
12-
import {MdMenu} from './menu';
13-
import {MdMenuItem, MdMenuAnchor} from './menu-item';
12+
import {MdMenu} from './menu-directive';
1413
import {MdMenuMissingError} from './menu-errors';
1514
import {
1615
Overlay,
@@ -138,5 +137,3 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
138137
);
139138
}
140139
}
141-
142-
export const MD_MENU_DIRECTIVES = [MdMenu, MdMenuItem, MdMenuTrigger, MdMenuAnchor];

src/components/menu/menu.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {inject} from '@angular/core/testing';
22
import {TestComponentBuilder} from '@angular/compiler/testing';
33
import {Component} from '@angular/core';
44

5-
import {MD_MENU_DIRECTIVES} from './menu-trigger';
5+
import {MD_MENU_DIRECTIVES} from './menu';
66

77
describe('MdMenu', () => {
88
let builder: TestComponentBuilder;

src/components/menu/menu.ts

Lines changed: 7 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,9 @@
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';
44

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';
878

9+
export const MD_MENU_DIRECTIVES = [MdMenu, MdMenuItem, MdMenuTrigger, MdMenuAnchor];

src/demo-app/menu/menu-demo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {MD_MENU_DIRECTIVES} from '@angular2-material/menu/menu-trigger';
2+
import {MD_MENU_DIRECTIVES} from '@angular2-material/menu/menu';
33
import {MD_ICON_DIRECTIVES} from '@angular2-material/icon/icon';
44
import {MD_BUTTON_DIRECTIVES} from '@angular2-material/button/button';
55
import {MD_TOOLBAR_DIRECTIVES} from '@angular2-material/toolbar/toolbar';

src/e2e-app/menu/menu-e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {MD_MENU_DIRECTIVES} from '@angular2-material/menu/menu-trigger';
2+
import {MD_MENU_DIRECTIVES} from '@angular2-material/menu/menu';
33

44
@Component({
55
moduleId: module.id,

0 commit comments

Comments
 (0)