Skip to content

Commit 8e072e4

Browse files
committed
docs(cdk-experimental/menu): add examples to menu documentation
1 parent 98d4799 commit 8e072e4

22 files changed

+527
-5
lines changed

src/cdk-experimental/menu/menu.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ menu directives to build your custom menu. A typical menu consists of the follow
2929
- `cdkMenu` - the actual menu you want to open
3030
- `cdkMenuItem` - added to each button
3131

32-
<!-- TODO basic standalone menu example (like mat-menu has) -->
32+
<!-- example({
33+
"example": "cdk-menu-standalone-menu",
34+
"file": "cdk-menu-standalone-menu-example.html"
35+
}) -->
3336

3437
Most menu interactions consist of two parts: a trigger and a menu panel.
3538

@@ -70,7 +73,10 @@ layed out horizontally or vertically (defaulting to horizontal). If the layout c
7073
the `orientation` attribute to match in order for the keyboard navigation to work properly and for
7174
menus to open up in the correct location.
7275

73-
<!-- TODO basic menubar example (google docs?) -->
76+
<!-- example({
77+
"example": "cdk-menu-menubar",
78+
"file": "cdk-menu-menubar-example.html"
79+
}) -->
7480

7581
### Context Menus
7682

@@ -79,7 +85,10 @@ container element with the `cdkContextMenuTriggerFor`, which behaves like `cdkMe
7985
that it responds to the browser's native `contextmenu` event. Custom context menus appear next to
8086
the cursor, similarly to native context menus.
8187

82-
<!-- TODO basic context menu example -->
88+
<!-- example({
89+
"example": "cdk-menu-context",
90+
"file": "cdk-menu-context-example.html"
91+
}) -->
8392

8493
You can nest context menu container elements. Upon right-click, the menu associated with the closest
8594
container element will open.
@@ -101,7 +110,10 @@ trigger. You can use an inline menu when you want a persistent menu interaction
101110
items within an inline menus are logically grouped together and you can navigate through them using
102111
your keyboard.
103112

104-
<!-- TODO inline menu example (gmail buttons?) -->
113+
<!-- example({
114+
"example": "cdk-menu-inline",
115+
"file": "cdk-menu-inline-example.html"
116+
}) -->
105117

106118
### Menu Items
107119

@@ -177,7 +189,10 @@ Note however that when the menu is closed and reopened any state is lost. You mu
177189
groups `change` output, or to `cdkMenuItemToggled` on each radio item and track changes your self.
178190
Finally, you can provide state for each item using the `checked` attribute.
179191

180-
<!-- TODO standalone menu example with checkboxes and grouped radios -->
192+
<!-- example({
193+
"example": "cdk-menu-standalone-stateful-menu",
194+
"file": "cdk-menu-standalone-stateful-menu-example.html"
195+
}) -->
181196

182197
### Smart Menu Aim
183198

src/components-examples/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ ALL_EXAMPLES = [
5959
"//src/components-examples/cdk/clipboard",
6060
"//src/components-examples/cdk/a11y",
6161
"//src/components-examples/cdk/overlay",
62+
"//src/components-examples/cdk-experimental/menu",
6263
"//src/components-examples/cdk-experimental/popover-edit",
6364
"//src/components-examples/cdk-experimental/selection",
6465
]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
load("//tools:defaults.bzl", "ng_module")
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
ng_module(
6+
name = "menu",
7+
srcs = glob(["**/*.ts"]),
8+
assets = glob([
9+
"**/*.html",
10+
"**/*.css",
11+
]),
12+
module_name = "@angular/components-examples/cdk-experimental/menu",
13+
deps = [
14+
"//src/cdk-experimental/menu",
15+
"@npm//@angular/forms",
16+
],
17+
)
18+
19+
filegroup(
20+
name = "source-files",
21+
srcs = glob([
22+
"**/*.html",
23+
"**/*.css",
24+
"**/*.ts",
25+
]),
26+
)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.cdk-menu {
2+
display: inline-flex;
3+
flex-direction: column;
4+
min-width: 180px;
5+
max-width: 280px;
6+
background-color: white;
7+
padding: 6px 0;
8+
}
9+
10+
.cdk-menu-item {
11+
background-color: transparent;
12+
cursor: pointer;
13+
outline: none;
14+
border: none;
15+
16+
user-select: none;
17+
min-width: 64px;
18+
line-height: 36px;
19+
padding: 0 16px;
20+
21+
display: flex;
22+
align-items: center;
23+
flex-direction: row;
24+
flex: 1;
25+
}
26+
27+
.cdk-menu-item:hover {
28+
background-color: #d0d0d0;
29+
}
30+
31+
.cdk-menu-item:active {
32+
background-color: #aaa;
33+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<div [cdkContextMenuTriggerFor]="context_menu">
2+
Did you ever hear the tragedy of Darth Plagueis The Wise? I thought not. It's not a story the Jedi
3+
would tell you. It's a Sith legend. Darth Plagueis was a Dark Lord of the Sith, so powerful and so
4+
wise he could use the Force to influence the midichlorians to create life… He had such a knowledge
5+
of the dark side that he could even keep the ones he cared about from dying. The dark side of the
6+
Force is a pathway to many abilities some consider to be unnatural. He became so powerful… the
7+
only thing he was afraid of was losing his power, which eventually, of course, he did.
8+
Unfortunately, he taught his apprentice everything he knew, then his apprentice killed him in his
9+
sleep. Ironic. He could save others from death, but not himself.
10+
</div>
11+
12+
<ng-template #context_menu="cdkMenuPanel" cdkMenuPanel>
13+
<div cdkMenu [cdkMenuPanel]="context_menu">
14+
<button cdkMenuItem>Cut</button>
15+
<button cdkMenuItem>Copy</button>
16+
<button cdkMenuItem>Link</button>
17+
</div>
18+
</ng-template>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {Component} from '@angular/core';
2+
3+
/** @title Context menu. */
4+
@Component({
5+
selector: 'cdk-menu-context-example',
6+
exportAs: 'cdkMenuContextExample',
7+
styleUrls: ['cdk-menu-context-example.css'],
8+
templateUrl: 'cdk-menu-context-example.html',
9+
})
10+
export class CdkMenuContextExample {}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.cdk-menu {
2+
display: inline-flex;
3+
flex-direction: column;
4+
min-width: 180px;
5+
max-width: 280px;
6+
background-color: white;
7+
padding: 6px 0;
8+
}
9+
10+
.cdk-menu-item {
11+
background-color: transparent;
12+
cursor: pointer;
13+
outline: none;
14+
border: none;
15+
16+
user-select: none;
17+
min-width: 64px;
18+
line-height: 36px;
19+
padding: 0 16px;
20+
21+
display: flex;
22+
align-items: center;
23+
flex-direction: row;
24+
flex: 1;
25+
}
26+
27+
.cdk-menu-item:hover {
28+
background-color: #d0d0d0;
29+
}
30+
31+
.cdk-menu-item:active {
32+
background-color: #aaa;
33+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div cdkMenu>
2+
<button cdkMenuItem>Inbox</button>
3+
<button cdkMenuItem>Snoozed</button>
4+
<button cdkMenuItem>Important</button>
5+
<button cdkMenuItem>Sent</button>
6+
<button cdkMenuItem>Drafts</button>
7+
<button cdkMenuItem>All Mail</button>
8+
</div>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {Component} from '@angular/core';
2+
3+
/** @title Gmail inline menu. */
4+
@Component({
5+
selector: 'cdk-menu-inline-example',
6+
exportAs: 'cdkMenuInlineExample',
7+
styleUrls: ['cdk-menu-inline-example.css'],
8+
templateUrl: 'cdk-menu-inline-example.html',
9+
})
10+
export class CdkMenuInlineExample {}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
.example-menu-bar-item {
2+
cursor: pointer;
3+
outline: none;
4+
border: none;
5+
6+
user-select: none;
7+
min-width: 34px;
8+
line-height: 26px;
9+
padding: 0 16px;
10+
}
11+
12+
.example-menu-bar-item:hover {
13+
background-color: #d0d0d0;
14+
}
15+
.example-menu-bar-item[aria-expanded='true'] {
16+
background-color: #d0d0d0;
17+
}
18+
19+
.cdk-menu {
20+
display: inline-flex;
21+
flex-direction: column;
22+
min-width: 180px;
23+
max-width: 280px;
24+
background-color: white;
25+
padding: 6px 0;
26+
}
27+
28+
.cdk-menu hr {
29+
width: 100%;
30+
color: #0000001f;
31+
}
32+
33+
.cdk-menu .cdk-menu-group {
34+
display: inline-flex;
35+
flex-direction: column;
36+
}
37+
38+
.cdk-menu .cdk-menu-item {
39+
background-color: transparent;
40+
cursor: pointer;
41+
outline: none;
42+
border: none;
43+
44+
user-select: none;
45+
min-width: 64px;
46+
line-height: 36px;
47+
padding: 0 16px;
48+
49+
display: flex;
50+
align-items: center;
51+
flex-direction: row;
52+
flex: 1;
53+
}
54+
55+
.cdk-menu-item > span {
56+
display: flex;
57+
flex-direction: row;
58+
flex: 1;
59+
justify-content: flex-end;
60+
}
61+
62+
.cdk-menu .cdk-menu-item:hover {
63+
background-color: #d0d0d0;
64+
}
65+
66+
.cdk-menu .cdk-menu-item[role='menuitemradio'][aria-checked='true'] {
67+
background-color: #e1e1e1;
68+
}
69+
.cdk-menu .cdk-menu-item[role='menuitemcheckbox'][aria-checked='true'] {
70+
background-color: #e1e1e1;
71+
}
72+
.cdk-menu .cdk-menu-item:active {
73+
background-color: #aaa;
74+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<div cdkMenuBar>
2+
<button class="example-menu-bar-item" cdkMenuItem [cdkMenuTriggerFor]="file">File</button>
3+
<button class="example-menu-bar-item" cdkMenuItem [cdkMenuTriggerFor]="edit">Edit</button>
4+
<button class="example-menu-bar-item" cdkMenuItem [cdkMenuTriggerFor]="format">Format</button>
5+
</div>
6+
7+
<ng-template cdkMenuPanel #file="cdkMenuPanel">
8+
<div cdkMenu [cdkMenuPanel]="file">
9+
<button cdkMenuItem>Share</button>
10+
<hr />
11+
<button cdkMenuItem [cdkMenuTriggerFor]="new">New <span>&#10148;</span></button>
12+
<button cdkMenuItem>Open</button>
13+
<button cdkMenuItem>Make a Copy</button>
14+
<hr />
15+
<button cdkMenuItem [cdkMenuTriggerFor]="download">Download <span>&#10148;</span></button>
16+
</div>
17+
</ng-template>
18+
19+
<ng-template #edit="cdkMenuPanel" cdkMenuPanel>
20+
<div cdkMenu [cdkMenuPanel]="edit">
21+
<button cdkMenuItem>Undo</button>
22+
<button cdkMenuItem>Redo</button>
23+
<hr />
24+
<button cdkMenuItem>Cut</button>
25+
<button cdkMenuItem>Copy</button>
26+
<button cdkMenuItem>Paste</button>
27+
</div>
28+
</ng-template>
29+
30+
<ng-template #format="cdkMenuPanel" cdkMenuPanel>
31+
<div cdkMenu [cdkMenuPanel]="format">
32+
<div cdkMenuGroup>
33+
<button checked id="bf" cdkMenuItemCheckbox>Bold</button>
34+
<button id="if" cdkMenuItemCheckbox>Italic</button>
35+
</div>
36+
<hr />
37+
<div cdkMenuGroup>
38+
<button id="small" cdkMenuItemRadio>Small</button>
39+
<button checked id="normal" cdkMenuItemRadio>Normal</button>
40+
<button id="large" cdkMenuItemRadio>Big</button>
41+
</div>
42+
</div>
43+
</ng-template>
44+
45+
<ng-template #new="cdkMenuPanel" cdkMenuPanel>
46+
<div cdkMenu [cdkMenuPanel]="new">
47+
<button cdkMenuItem>Document</button>
48+
<button cdkMenuItem>From template</button>
49+
<hr />
50+
<button cdkMenuItem>Spreadsheet</button>
51+
<button cdkMenuItem>Presentation</button>
52+
<button cdkMenuItem>Form</button>
53+
</div>
54+
</ng-template>
55+
56+
<ng-template #download="cdkMenuPanel" cdkMenuPanel>
57+
<div cdkMenu [cdkMenuPanel]="download">
58+
<button cdkMenuItem>Microsoft Word</button>
59+
<button cdkMenuItem>PDF</button>
60+
<button cdkMenuItem>Plain text</button>
61+
</div>
62+
</ng-template>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {Component} from '@angular/core';
2+
3+
/** @title Google Docs Menu Bar. */
4+
@Component({
5+
selector: 'cdk-menu-menubar-example',
6+
exportAs: 'cdkMenuMenubarExample',
7+
styleUrls: ['cdk-menu-menubar-example.css'],
8+
templateUrl: 'cdk-menu-menubar-example.html',
9+
})
10+
export class CdkMenuMenubarExample {}

0 commit comments

Comments
 (0)