Skip to content

Commit 0e5a7f6

Browse files
Merge pull request #7393 from bszyman/header-apps
Header Apps
2 parents 55303c5 + 62c35c7 commit 0e5a7f6

File tree

2 files changed

+93
-60
lines changed

2 files changed

+93
-60
lines changed
90.1 KB
Loading
Lines changed: 93 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,36 @@
11
---
2-
description: Example how to work with extension registry
2+
description: Place single-purpose extensions in the top-level navigation bar, next to the user profile avatar.
33
---
44

55
# Header Apps
66

7-
{% hint style="warning" %}
8-
This page is a work in progress and may undergo further revisions, updates, or amendments. The information contained herein is subject to change without notice.
9-
{% endhint %}
10-
11-
A header app appears next to the user profile and global search icon on the top-right corner of Umbraco's backoffice.
12-
13-
In this article, you can find an example of an extension registry. This example details the creation of a Header App in two ways, similar to how the extension registry can be created:
14-
15-
1. [Using a manifest file](header-apps.md#button-header-app-with-manifest).
16-
2. [Using the JavaScript/TypeScript file](header-apps.md#button-header-app-with-js-ts).
7+
Header App extensions appear next to the user profile and the global search icon in the top right of Umbraco’s Backoffice. Extension authors can create custom header apps to add globally accessible functionality to the Backoffice.
178

189
<figure><img src="../../../.gitbook/assets/header-apps.svg" alt=""><figcaption><p>Header Apps</p></figcaption></figure>
1910

20-
## **Button Header App with Manifest**
11+
## Button Header Apps as a link
12+
Extension authors can create header apps that link to resource both inside and outside the backoffice. Header apps can be created using a manifest or using TypeScript.
2113

22-
Below you can find an example of how to setup a Header App using the manifest file.
14+
To create a link-style header app, define a `headerApp` extension in the `umbraco-package.json` file. Be sure to include `meta.label` and `meta.icon` so that your header app appears when you reload the backoffice.
2315

24-
1. Follow the [Vite Package Setup](../../development-flow/vite-package-setup.md) to create a header app and name it "`header-app`" when using the guide.
25-
2. Create a manifest file named `umbraco-package.json` at the root of the `header-app` folder. Here we define and configure our dashboard.
26-
3. Add the following code to `umbraco-package.json`:
16+
If `meta.href` is defined, the header app will function as a link. Links will open in the same tab.
2717

28-
{% code title="umbraco-package.json" lineNumbers="true" %}
29-
```typescript
18+
Header Apps can also be created using TypeScript. Examples of both approaches are shown below.
19+
20+
{% tabs %}
21+
{% tab title="Using the Package Manifest" %}
22+
{% code title="umbraco-package.json" %}
23+
```json
3024
{
3125
"$schema": "../../umbraco-package-schema.json",
32-
"name": "My Header App",
26+
"name": "My Package",
3327
"version": "0.1.0",
3428
"extensions": [
3529
{
3630
"type": "headerApp",
3731
"alias": "My.HeaderApp",
3832
"name": "My Header App",
3933
"kind": "button",
40-
4134
"meta": {
4235
"label": "Hello Umbraco",
4336
"icon": "icon-hearts",
@@ -48,69 +41,109 @@ Below you can find an example of how to setup a Header App using the manifest fi
4841
}
4942
```
5043
{% endcode %}
44+
{% endtab %}
45+
{% tab title="Using TypeScript" %}
46+
{% code title="my-element.ts" %}
47+
Create an object that implements the `UmbExtensionManifest` interface, then register the extension with the `umbExtensionsRegistry` service.
48+
49+
```typescript
50+
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry';
51+
52+
const manifest: UmbExtensionManifest = {
53+
type: "headerApp",
54+
alias: "My.HeaderApp.Documentation",
55+
name: "My Documentation Header App",
56+
kind: "button",
57+
meta: {
58+
label: "Hello Documentation",
59+
icon: "icon-addressbook",
60+
href: "https://docs.umbraco.com/"
61+
}
62+
};
5163

52-
* First we define the type which is a `headerApp`. Then we add a unique alias and a name to define the extension UI.
53-
* Then we can define what kind of extension it is, where in this case we can use a pre-defined element called button.
54-
* The button requires some metadata: an icon, label of the button (name of the button) and a link which opens once clicked.
64+
umbExtensionsRegistry.register(manifest);
65+
```
66+
{% endcode %}
67+
{% endtab %}
68+
{% endtabs %}
5569

56-
4. In the `header-app` folder run `npm run build` and then run the project. Then in the backoffice you will see our new Header App extension with **heart icon**:
70+
## Button Header Apps with deeper interactivity
5771

58-
<figure><img src="../../../.gitbook/assets/header-app-example.png" alt=""><figcaption><p>Header App in the Backoffice registered via Manifest File</p></figcaption></figure>
72+
Extension authors can also create header apps that have more interactivity than a link.
5973

60-
## **Button Header App with JS/TS**
74+
By creating a custom component, extension authors can control how the button renders itself and how it behaves when clicked. This allows header apps to control navigation, open modals, or perform other actions.
6175

62-
Below you can find an example of how to setup a Header App using the TypeScript file.
76+
For example, this is how the current user header app is able to present a modal when clicked.
6377

64-
This is a continuation of the above steps from the **Button Header App with Manifest** example. We will register a new Header App directly from the .ts file.
78+
<figure><img src="../../../.gitbook/assets/header-apps-custom.png" alt=""><figcaption><p>The current user modal is presented from a header app</p></figcaption></figure>
6579

66-
1. Add a reference to the .js file. Update the `umbraco-package.json` with the following:
80+
In order for a header app to have some functionality, extension authors will need to define behavior by creating a JavaScript or TypeScript component. Once the component has been created, it will need to be registered in the header app's `element` property.
6781

68-
{% code title="umbraco-package.json" lineNumbers="true" %}
69-
```typescript
82+
{% tabs %}
83+
{% tab title="Package Manifest" %}
84+
{% code title="umbraco-package.json" %}
85+
```json
7086
{
7187
"$schema": "../../umbraco-package-schema.json",
72-
"name": "My Header App",
88+
"name": "My Package",
7389
"version": "0.1.0",
7490
"extensions": [
7591
{
7692
"type": "headerApp",
77-
"alias": "My.HeaderApp",
78-
"name": "My Header App",
93+
"alias": "My.HeaderApp.ServerServices",
94+
"name": "My Server Services Header App",
7995
"kind": "button",
80-
"element": "/App_Plugins/header-app/dist/header-app.js",
81-
"meta": {
82-
"label": "Hello Umbraco",
83-
"icon": "icon-hearts",
84-
"href": "https://umbraco.com/"
85-
}
96+
"element": "/App_Plugins/MyPackage/server-services-header-app.js"
8697
}
8798
]
8899
}
89100
```
90101
{% endcode %}
91-
92-
2. Replace the content of the `src/my-element.ts file` with the following:
93-
94-
{% code title="my-element.ts" lineNumbers="true" %}
102+
{% endtab %}
103+
{% tab title="TypeScript" %}
104+
This example assumes that the extension author has transpiled the above TypeScript code into a JavaScript file. The name and location of the transpiled file should match the `element` property in the package manifest.
105+
{% code title="src/server-services-header.ts" lineNumbers="true" %}
95106
```typescript
96-
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry';
107+
import { html, customElement } from "@umbraco-cms/backoffice/external/lit";
108+
import { UmbHeaderAppButtonElement } from "@umbraco-cms/backoffice/components";
109+
import { umbOpenModal, UMB_CONFIRM_MODAL } from "@umbraco-cms/backoffice/modal";
110+
111+
@customElement("my-server-services-header-app")
112+
export class MyServerServicesHeaderAppElement extends UmbHeaderAppButtonElement {
113+
async #handleUserClick() {
114+
umbOpenModal(this, UMB_CONFIRM_MODAL, {
115+
data: {
116+
headline: "Would you like to disable all Server Services?",
117+
content:
118+
"This action can be undone, but only after all services have stopped.",
119+
color: "danger",
120+
confirmLabel: "Disable all services",
121+
},
122+
})
123+
.then(() => {
124+
console.log("User has approved");
125+
})
126+
.catch(() => {
127+
console.log("User has rejected");
128+
});
129+
}
97130

98-
const manifest: UmbExtensionManifest = {
99-
type: "headerApp",
100-
alias: "My.HeaderApp.Documentation",
101-
name: "My Header App Documentation",
102-
kind: "button",
103-
meta: {
104-
label: "Hello Documentation",
105-
icon: "icon-addressbook",
106-
href: "https://docs.umbraco.com/"
131+
override render() {
132+
return html`
133+
<uui-button
134+
@click=${this.#handleUserClick}
135+
look="primary"
136+
label="Server Services"
137+
compact
138+
>
139+
<uui-icon name="icon-server"></uui-icon>
140+
</uui-button>
141+
`;
107142
}
108-
};
143+
}
109144

110-
umbExtensionsRegistry.register(manifest);
145+
{ MyServerServicesHeaderAppElement as element };
111146
```
112147
{% endcode %}
113-
114-
3. In the `header-app` folder run `npm run build` and then run the project. Then in the backoffice you will see our new Header App extension with **address book** **icon**:
115-
116-
<figure><img src="../../../.gitbook/assets/header-app-example-ts.png" alt=""><figcaption><p>Header App in Backoffice registered via ts File</p></figcaption></figure>
148+
{% endtab %}
149+
{% endtabs %}

0 commit comments

Comments
 (0)