UNPKG

3.79 kBMarkdownView Raw
1# td-dynamic-menu
2
3`td-dynamic-menu` element supports the creation of n-level deep cascading menus with
4group labels and URL/action links and actions using a JSON object.
5
6## API Summary
7
8#### Model
9
10```typescript
11// Trigger button launches top level menu. Must specify text and/or icon.
12export interface IMenuTrigger {
13 id?: string; // Optional identifier
14 text?: string; // Text to display on button
15 icon?: string; // Optional icon
16 svgIcon?: string; // Optional svgIcon
17 iconClasses?: string[]; // Optional styling classes
18}
19
20// Menu items can serve one of four roles:
21// - Submenu trigger (has children property)
22// - URL link (has link property)
23// - Action link (has action property)
24// - Grouping label (has neither children, link or action properties)
25export interface IMenuItem {
26 id?: string; // Optional identifier
27 text: string; // Display text
28 icon?: string; // Optional icon
29 svgIcon?: string; // Optional svgIcon
30 iconClasses?: string[]; // Optional styling classes
31 // If children provided, item is a submenu trigger
32 // Represents the contents of the submenu
33 children?: IMenuItem[];
34 // If link provided, item is a URL link
35 link?: string; // href (relative or fully qualified).
36 newTab?: boolean; // Indicates where URL should be displayed, current or new browser tab
37 // If action provided, item is an action link
38 // A click on this item will emit itemClicked event
39 action?: string;
40}
41
42// Click action event payload derived from IMenuItem
43export interface ITdDynamicMenuLinkClickEvent {
44 text: string;
45 action: string;
46}
47```
48
49#### Inputs
50
51- trigger: IMenuTrigger
52 - Definition for trigger button.
53- items: IMenuItem[]
54 - One or more items to be displayed in menu.
55
56#### Output
57
58- itemClicked: ITdDynamicMenuLinkClickEvent
59 - Emitted when an action link is pressed.
60
61## Setup
62
63Import the **[CovalentDynamicMenuModule]** in your NgModule:
64
65```typescript
66import { CovalentDynamicMenuModule } from '@covalent/core/dynamic-menu';
67@NgModule({
68 imports: [
69 CovalentDynamicMenuModule,
70 ...
71 ],
72 ...
73})
74export class MyModule {}
75```
76
77## Usage
78
79Basic Example:
80
81```typescript
82trigger: IMenuTrigger = {
83 id: 'triggerbutton',
84 icon: 'list',
85 text: 'Trigger With Text And Icon',
86};
87
88items: IMenuItem[] = [
89 { // Grouping label
90 id: 'platform',
91 text: 'Platform',
92 },
93 { // Submenu trigger
94 id: 'covalentlinkstrigger',
95 text: 'Covalent Links',
96 svgIcon: 'assets:covalent',
97 children: [
98 { // URL link
99 id: 'quickstartlink',
100 text: 'Quickstart',
101 icon: 'flash_on',
102 link: 'https://github.com/Teradata/covalent-quickstart',
103 newTab: true,
104 },
105 { // URL link
106 id: 'electronlink',
107 text: 'Electron App',
108 icon: 'laptop_mac',
109 link: 'https://github.com/Teradata/covalent-electron',
110 newTab: true,
111 },
112 { // URL link
113 id: 'datalink',
114 text: 'Covalent Data',
115 icon: 'aspect_ratio',
116 link: 'https://github.com/Teradata/covalent-data',
117 newTab: true,
118 },
119 ],
120 },
121 { // Grouping label
122 id: 'framework',
123 text: 'Framework',
124 },
125 { // Submenu trigger
126 id: 'angularlink',
127 text: 'Angular Link',
128 svgIcon: 'assets:angular',
129 children: [
130 { // URL link
131 text: 'Angular Homepage',
132 link: 'https://angular.io/',
133 newTab: true,
134 },
135 ],
136 },
137 { // Grouping label
138 id: 'actions',
139 text: 'Actions',
140 },
141 { // Action link
142 id: 'actionlink',
143 text: 'Do Action',
144 icon: 'directions_run',
145 action: 'Go Run',
146 },
147 ];
148```
149
150```html
151<td-dynamic-menu [trigger]="trigger" [items]="items"></td-dynamic-menu>
152```