Skip to content

Commit d26ead4

Browse files
jelbournkara
authored andcommitted
feat(menu): add md-menu standalone component
1 parent 04d1c80 commit d26ead4

File tree

6 files changed

+82
-10
lines changed

6 files changed

+82
-10
lines changed

src/components/button/_button-base.scss

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
@import 'variables';
33
@import 'elevation';
4+
@import 'mixins';
45

56
// TODO(jelbourn): This goes away.
67
@import 'default-theme';
@@ -34,12 +35,7 @@ $md-mini-fab-padding: 8px !default;
3435
position: relative;
3536

3637
// Reset browser <button> styles.
37-
background: transparent;
38-
text-align: center;
39-
cursor: pointer;
40-
user-select: none;
41-
outline: none;
42-
border: none;
38+
@include md-button-reset();
4339

4440
// Make anchors render like buttons.
4541
display: inline-block;
@@ -52,6 +48,7 @@ $md-mini-fab-padding: 8px !default;
5248
font-family: $md-font-family;
5349
font-weight: 500;
5450
color: currentColor;
51+
text-align: center;
5552

5653
// Sizing.
5754
margin: $md-button-margin;

src/components/menu/menu.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div class="md-menu">
2+
<ng-content></ng-content>
3+
</div>
4+

src/components/menu/menu.scss

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// TODO(kara): update vars for desktop when MD team responds
2+
3+
@import 'variables';
4+
@import 'elevation';
5+
@import 'default-theme';
6+
@import 'mixins';
7+
8+
// menu width must be a multiple of 56px
9+
$md-menu-overlay-min-width: 112px !default; // 56 * 2
10+
$md-menu-overlay-max-width: 280px !default; // 56 * 5
11+
12+
$md-menu-overlay-max-height: calc(100vh + $md-menu-item-height) !default;
13+
$md-menu-item-height: 48px !default;
14+
$md-menu-font-size: 16px !default;
15+
$md-menu-side-padding: 16px !default;
16+
17+
.md-menu {
18+
@include md-elevation(2);
19+
min-width: $md-menu-overlay-min-width;
20+
max-width: $md-menu-overlay-max-width;
21+
max-height: $md-menu-overlay-max-height;
22+
23+
background: md-color($md-background, 'background');
24+
}
25+
26+
[md-menu-item] {
27+
@include md-button-reset();
28+
29+
display: block;
30+
width: 100%;
31+
height: $md-menu-item-height;
32+
padding: 0 $md-menu-side-padding;
33+
34+
font-size: $md-menu-font-size;
35+
font-family: $md-font-family;
36+
text-align: start;
37+
color: md-color($md-foreground, 'text');
38+
39+
&[disabled] {
40+
color: md-color($md-foreground, 'disabled');
41+
}
42+
43+
&:hover:not([disabled]) {
44+
background: md-color($md-background, 'hover');
45+
}
46+
}
47+

src/components/menu/menu.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
import {Component, ViewEncapsulation} from '@angular/core';
1+
import {Component, Directive, ViewEncapsulation} from '@angular/core';
22

33
@Component({
44
moduleId: module.id,
55
selector: 'md-menu',
6+
host: {'role': 'menu'},
67
templateUrl: 'menu.html',
78
styleUrls: ['menu.css'],
8-
encapsulation: ViewEncapsulation.None
9+
encapsulation: ViewEncapsulation.None,
10+
exportAs: 'mdMenu'
911
})
1012
export class MdMenu {}
1113

12-
export const MD_MENU_DIRECTIVES = [MdMenu];
14+
@Directive({
15+
selector: '[md-menu-item]',
16+
host: {'role': 'menuitem'}
17+
})
18+
export class MdMenuItem {}
19+
20+
export const MD_MENU_DIRECTIVES = [MdMenu, MdMenuItem];
1321

src/core/style/_mixins.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@
3838
}
3939
}
4040

41+
/**
42+
* This mixin overrides default button styles like the gray background,
43+
* the border, and the outline.
44+
*/
45+
@mixin md-button-reset {
46+
background: transparent;
47+
cursor: pointer;
48+
user-select: none;
49+
outline: none;
50+
border: none;
51+
}
52+
4153
/**
4254
* A mixin, which generates temporary ink ripple on a given component.
4355
* When $bindToParent is set to true, it will check for the focused class on the same selector as you included

src/demo-app/menu/menu-demo.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
menu
1+
<md-menu>
2+
<button md-menu-item>Refresh</button>
3+
<button md-menu-item>Settings</button>
4+
<button md-menu-item disabled>Help</button>
5+
</md-menu>

0 commit comments

Comments
 (0)