|
1 | 1 | --- |
2 | 2 | description: >- |
3 | | - Create menus that appear throughout the backoffice, in sidebars, button flyouts, and more. |
| 3 | + Create menus that appear throughout the backoffice, including sidebars and button flyouts. |
4 | 4 | --- |
5 | 5 |
|
6 | 6 | # Menus |
7 | 7 |
|
8 | | -Menu extensions contain one or more menu item extensions and can be placed throughout the backoffice - in sidebars, flyouts, and more. This article will cover how to create a menu with custom menu items. |
| 8 | +Menu extensions contain one or more [menu item extensions](menu-item.md) and can appear throughout the backoffice—such as in sidebars and flyouts. |
9 | 9 |
|
10 | 10 | <figure><img src="../../../.gitbook/assets/menu.png" alt="" width="250"><figcaption><p>Menu</p></figcaption></figure> |
11 | 11 |
|
@@ -65,136 +65,6 @@ export const onInit: UmbEntryPointOnInit = (_host, _extensionRegistry) => { |
65 | 65 | {% endtab %} |
66 | 66 | {% endtabs %} |
67 | 67 |
|
68 | | -# Menu Items |
69 | | - |
70 | | -Each menu consists of one or more menu item extensions. Extension authors can create customized menu items. |
71 | | - |
72 | | -<figure><img src="../../../.gitbook/assets/menu-item.png" alt="" width="250"><figcaption><p>Menu Item</p></figcaption></figure> |
73 | | - |
74 | | -## Creating menu items |
75 | | - |
76 | | -Menu Item extensions can be created using either JSON or TypeScript. Both approaches are shown below. |
77 | | - |
78 | | -### Manifest |
79 | | - |
80 | | -To add custom menu items, you can define a single MenuItem manifest and link an element to it. In this element, you can fetch the data and render as many menu items as you want based on that data. |
81 | | - |
82 | | -{% tabs %} |
83 | | -{% tab title="JSON" %} |
84 | | -{% code title="umbraco-package.json" %} |
85 | | -```json |
86 | | -{ |
87 | | - "$schema": "../../umbraco-package-schema.json", |
88 | | - "name": "My Package", |
89 | | - "version": "0.1.0", |
90 | | - "extensions": [ |
91 | | - { |
92 | | - "type": "menuItem", |
93 | | - "alias": "My.MenuItem", |
94 | | - "name": "My Menu Item", |
95 | | - "element": "./menu-items.ts", |
96 | | - "meta": { |
97 | | - "label": "My Menu Item", |
98 | | - "menus": ["My.Menu"] |
99 | | - } |
100 | | - } |
101 | | - ] |
102 | | -} |
103 | | -``` |
104 | | -{% hint style="info" %} |
105 | | -The `element` parameter is optional. Omitting it will render a menu item styled using Umbraco defaults. |
106 | | -{% endhint %} |
107 | | -{% endcode %} |
108 | | -{% endtab %} |
109 | | -{% tab title="TypeScript" %} |
110 | | - |
111 | | -Extension authors define the menu manifest, then register it dynamically/during runtime using a [Backoffice Entry Point](../../extending-overview/extension-types/backoffice-entry-point.md) extension. |
112 | | - |
113 | | -The `element` attribute will point toward a custom Lit component, an example of which will be in the next section of this article. |
114 | | - |
115 | | -{% code title="my-menu/manifests.ts" %} |
116 | | -```typescript |
117 | | -import type { ManifestMenuItem } from '@umbraco-cms/backoffice/menu'; |
118 | | - |
119 | | -export const menuItemManifest: ManifestMenuItem = { |
120 | | - type: 'menuItem', |
121 | | - alias: 'My.MenuItem', |
122 | | - name: 'My Menu Item', |
123 | | - meta: { |
124 | | - label: 'My Menu Item', |
125 | | - menus: ["My.Menu"] |
126 | | - }, |
127 | | -}; |
128 | | -``` |
129 | | -{% endcode %} |
130 | | - |
131 | | -{% code title="entrypoints/entrypoints.ts" %} |
132 | | -```typescript |
133 | | -import type { |
134 | | - UmbEntryPointOnInit, |
135 | | -} from "@umbraco-cms/backoffice/extension-api"; |
136 | | -import { umbExtensionsRegistry } from "@umbraco-cms/backoffice/extension-registry"; |
137 | | -import { menuItemManifest } from "./../my-menu/manifests.ts"; |
138 | | - |
139 | | -export const onInit: UmbEntryPointOnInit = (_host, _extensionRegistry) => { |
140 | | - console.log("Hello from my extension 🎉"); |
141 | | - |
142 | | - umbExtensionsRegistry.register(menuItemManifest); |
143 | | -}; |
144 | | -``` |
145 | | -{% endcode %} |
146 | | -{% endtab %} |
147 | | -{% endtabs %} |
148 | | - |
149 | | -#### Default Element |
150 | | - |
151 | | -The default element supports rendering a subtree of menu items. |
152 | | - |
153 | | -```typescript |
154 | | -class UmbMenuItemTreeDefaultElement {} |
155 | | -``` |
156 | | - |
157 | | -## Adding menu items to an existing menu |
158 | | - |
159 | | -Extension authors are able to add their own additional menu items to the menus that ship with Umbraco. |
160 | | - |
161 | | -Some examples of these built-in menus include: |
162 | | - |
163 | | -* Content - `Umb.Menu.Content` |
164 | | -* Media - `Umb.Menu.Media` |
165 | | -* Settings - `Umb.Menu.StructureSettings` |
166 | | -* Templating - `Umb.Menu.Templating` |
167 | | -* ... |
168 | | - |
169 | | -Additional Umbraco menus (nine, total) can be found using the Extension Insights browser and selecting **Menu** from the dropdown. |
170 | | - |
171 | | -<figure><img src="../../../.gitbook/assets/extension-types-backoffice-browser.png" alt=""><figcaption><p>Backoffice extension browser</p></figcaption></figure> |
172 | | - |
173 | | -### Extending Menus |
174 | | - |
175 | | -To add a menu item to an existing menu, use the `meta.menus` property. |
176 | | - |
177 | | -{% code title="umbraco-package.json" %} |
178 | | -```json |
179 | | -{ |
180 | | - "$schema": "../../umbraco-package-schema.json", |
181 | | - "name": "My Package", |
182 | | - "version": "0.1.0", |
183 | | - "extensions": [ |
184 | | - { |
185 | | - "type": "menuItem", |
186 | | - "alias": "My.MenuItem", |
187 | | - "name": "My Menu Item", |
188 | | - "meta": { |
189 | | - "label": "My Menu Item", |
190 | | - "menus": ["Umb.Menu.Content"] |
191 | | - }, |
192 | | - "element": "menu-items.js" |
193 | | - } |
194 | | - ] |
195 | | -} |
196 | | -``` |
197 | | -{% endcode %} |
198 | | - |
199 | 68 | ## See Also |
200 | 69 | * [Section Sidebar](sections/section-sidebar.md) for information on creating menus for navigation within section extensions. |
| 70 | +* [Menu Item](menu-item.md) for information on creating menu items. |
0 commit comments