Skip to content
This repository was archived by the owner on Dec 2, 2025. It is now read-only.

Commit 9612f34

Browse files
committed
Add in custom dialogs (WIP)
1 parent 6cdbcac commit 9612f34

File tree

4 files changed

+101
-21
lines changed

4 files changed

+101
-21
lines changed

src/Our.Umbraco.UiExamples.v14/src/manifest.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ export const manifests: Array<ManifestTypes> = [
6161
"match": "example.ui.section"
6262
}
6363
]
64+
},
65+
{
66+
"type": "modal",
67+
"alias": "My.Modal",
68+
"name": "My Modal",
69+
"element": () => import("./scripts/dialogs/custom-modal.ts"),
6470
}
6571
// ... insert as many manifests as you like
6672

src/Our.Umbraco.UiExamples.v14/src/scripts/dashboards/custom-dialogs-dashboard.ts

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { LitElement, css, html } from 'lit'
22
import { customElement, property } from 'lit/decorators.js'
3+
import { MY_MODAL_TOKEN } from '../dialogs/custom-modal.token';
4+
import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal';
5+
import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api';
36

47
/**
58
* An example element.
@@ -8,29 +11,48 @@ import { customElement, property } from 'lit/decorators.js'
811
* @csspart button - The button
912
*/
1013
@customElement('uie-custom-dialogs-dashboard')
11-
export default class UieCustomDialogsDashboard extends LitElement {
12-
/**
13-
* Copy for the read the docs hint.
14-
*/
15-
@property()
16-
docsHint = 'Click on the Vite and Lit logos to learn more'
14+
export default class UieCustomDialogsDashboard extends UmbElementMixin(LitElement) {
15+
#modalManagerContext?: typeof UMB_MODAL_MANAGER_CONTEXT.TYPE;
1716

17+
constructor() {
18+
super();
19+
this.consumeContext(UMB_MODAL_MANAGER_CONTEXT, (instance) => {
20+
this.#modalManagerContext = instance;
21+
// modalManagerContext is now ready to be used.
22+
});
23+
}
1824

19-
/**
20-
* The number of times the button has been clicked.
21-
*/
22-
@property({ type: Number })
23-
count = 0
25+
render() {
26+
return html`
27+
<uui-box>
28+
<div slot="header" class="header-bar">
29+
<div>
30+
<h5 class="title">Overlay Dialogs<br/><span class="sub-header">Overlays give you a 'modal' dialog across the whole screen</span></h5>
31+
</div>
32+
</div>
33+
<div slot="header-actions">
34+
<uui-button href="https://uui.umbraco.com/" target="_blank" look="primary" color="positive">
35+
<uui-badge slot="extra" label="A11Y label">!</uui-badge>
36+
<uui-icon name="info"></uui-icon>
37+
View the Storybook library</uui-button>
38+
</div>
39+
<slot>
40+
<p>The overlay service has a confirm option built, in with this you can quickly create a confirm dialog, to present your users with a simple option.</p>
41+
<uui-button-group>
42+
<uui-button look="primary" color="default" @click=${this._openModal}>Confirm</uui-button>
43+
<uui-button look="primary" color="positive">Confirm Remove</uui-button>
44+
<uui-button look="primary" color="danger">Confirm Delete</uui-button>
45+
</uui-button-group>
46+
</slot>
47+
</uui-box>`
48+
}
2449

25-
render() {
26-
return html`
27-
<uui-modal-container>
28-
<uui-modal-dialog>
29-
<h1>My Modal</h1>
30-
<p>My modal content</p>
31-
</uui-modal-dialog>
32-
</uui-modal-container>
33-
`
50+
private _openModal() {
51+
this.#modalManagerContext?.open(this, MY_MODAL_TOKEN, {
52+
data: {
53+
headline: "My modal headline",
54+
},
55+
});
3456
}
3557

3658
static styles = css`
@@ -85,6 +107,6 @@ export default class UieCustomDialogsDashboard extends LitElement {
85107

86108
declare global {
87109
interface HTMLElementTagNameMap {
88-
'uie-custom-dialogs-dashboard': UieCustomDialogsDashboard
110+
'uie-custom-dialogs-dashboard': UieCustomDialogsDashboard
89111
}
90112
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { UmbModalToken } from "@umbraco-cms/backoffice/modal";
2+
3+
export type MyModalData = {
4+
headline: string;
5+
}
6+
7+
export type MyModalValue = {
8+
myData: string;
9+
}
10+
11+
export const MY_MODAL_TOKEN = new UmbModalToken<MyModalData, MyModalValue>('My.Modal', {
12+
modal: {
13+
type: 'sidebar',
14+
size: 'small'
15+
}
16+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { html, LitElement, property, customElement } from "@umbraco-cms/backoffice/external/lit";
2+
import { UmbElementMixin } from "@umbraco-cms/backoffice/element-api";
3+
import type { UmbModalContext } from "@umbraco-cms/backoffice/modal";
4+
import type { MyModalData, MyModalValue } from "./custom-modal.token.ts";
5+
import { UmbModalExtensionElement } from "@umbraco-cms/backoffice/extension-registry";
6+
7+
@customElement('my-dialog')
8+
export default class MyDialogElement
9+
extends UmbElementMixin(LitElement)
10+
implements UmbModalExtensionElement<MyModalData, MyModalValue> {
11+
12+
@property({ attribute: false })
13+
modalContext?: UmbModalContext<MyModalData, MyModalValue>;
14+
15+
@property({ attribute: false })
16+
data?: MyModalData;
17+
18+
private _handleCancel() {
19+
this.modalContext?.submit();
20+
}
21+
22+
private _handleSubmit() {
23+
this.modalContext?.updateValue({ myData: "hello world" });
24+
this.modalContext?.submit();
25+
}
26+
27+
render() {
28+
return html`
29+
<div>
30+
<h1>${this.modalContext?.data.headline ?? "Default headline"}</h1>
31+
<button @click=${this._handleCancel}>Cancel</button>
32+
<button @click=${this._handleSubmit}>Submit</button>
33+
</div>
34+
`;
35+
}
36+
}

0 commit comments

Comments
 (0)