Skip to content

Commit 55303c5

Browse files
authored
Merge pull request #7327 from bszyman/confirm-dialog
Confirm Dialog Updates
2 parents cb4d782 + e8fd5aa commit 55303c5

File tree

3 files changed

+97
-32
lines changed

3 files changed

+97
-32
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
description: Ask the user for confirmation
3+
---
4+
5+
# Confirm Dialog
6+
7+
This example shows how to open a confirm dialog. The `UMB_CONFIRM_MODAL` is a token that represents the confirm dialog. The `open` method takes the token and an object with the data for the confirm dialog. The `onSubmit` method returns a promise that resolves when the user confirms the dialog and rejects when the user cancels the dialog.
8+
9+
The confirm modal itself is built-in and does not need to be registered in the extension registry.
10+
11+
The modal token describes the options that you can pass to the modal. The confirm modal token has the following properties:
12+
13+
* `headline` - The headline of the modal.
14+
* `content` - The content of the modal, which can be a TemplateResult or a string.
15+
* `color` - (Optional) The color of the modal. This can be `positive` or `danger`.
16+
* `confirmLabel` - (Optional) The label of the confirm button.
17+
18+
## Basic Usage
19+
20+
{% code title="my-element.ts" %}
21+
```typescript
22+
import { html, LitElement, customElement } from "@umbraco-cms/backoffice/external/lit";
23+
import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api';
24+
import { UMB_MODAL_MANAGER_CONTEXT, UMB_CONFIRM_MODAL } from '@umbraco-cms/backoffice/modal';
25+
26+
@customElement('my-element')
27+
export class MyElement extends UmbElementMixin(LitElement) {
28+
29+
30+
async #onRequestDisable() {
31+
const context = await this.getContext(UMB_MODAL_MANAGER_CONTEXT)
32+
33+
const modal = context?.open(
34+
this, UMB_CONFIRM_MODAL,
35+
{
36+
data: {
37+
headline: `#actions_disable`,
38+
content: `#defaultdialogs_confirmdisable`,
39+
color: "danger",
40+
confirmLabel: "Disable",
41+
}
42+
}
43+
);
44+
45+
modal?.onSubmit()
46+
.then(() => {
47+
console.log("User has approved");
48+
})
49+
.catch(() => {
50+
console.log("User has rejected");
51+
});
52+
}
53+
54+
render() {
55+
return html`<uui-button
56+
look="primary"
57+
color="danger"
58+
@click=${this.#onRequestDisable}
59+
label=${this.localize.term("actions_disable")}></uui-button>`;
60+
}
61+
}
62+
```
63+
{% endcode %}

16/umbraco-cms/customizing/extending-overview/extension-types/modals/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description: >-
88

99
## **Modal Types**
1010

11-
The Dialog modal appears in the middle of the screen and the Sidebar Modal slides in from the right.
11+
The Dialog modal appears in the middle of the screen, and the Sidebar Modal slides in from the right.
1212

1313
## Open a Modal
1414

16/umbraco-cms/customizing/extending-overview/extension-types/modals/confirm-dialog.md

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,48 @@
11
---
2-
description: Ask the user for confirmation
2+
description: Present a dialog to ask the user for confirmation.
33
---
44

55
# Confirm Dialog
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 %}
7+
Confirmation dialogs are used to ask the user for confirmation to complete some action and are presented as a center-aligned modal in the backoffice.
108

11-
This example shows how to open a confirm dialog. The `UMB_CONFIRM_MODAL` is a token that represents the confirm dialog. The `open` method takes the token and an object with the data for the confirm dialog. The `onSubmit` method returns a promise that resolves when the user confirms the dialog and rejects when the user cancels the dialog.
9+
Extension authors do not need to register the dialog in their extension's manifest, instead these dialogs are opened by importing and calling the `umbOpenModal` function.
1210

13-
The confirm modal itself is built-in and does not need to be registered in the extension registry.
14-
15-
The modal token describes the options that you can pass to the modal. The confirm modal token has the following properties:
11+
Extension authors can customize the dialog with configuration options such as headline, body content, colors, and button labels.
1612

1713
* `headline` - The headline of the modal.
1814
* `content` - The content of the modal, which can be a TemplateResult or a string.
19-
* `color` - (Optional) The color of the modal. This can be `positive` or `danger`.
20-
* `confirmLabel` - (Optional) The label of the confirm button.
15+
* `color` - (Optional) The color of the modal, can be `positive` or `danger`. Defaults to `positive`.
16+
* `confirmLabel` - (Optional) The label of the confirmation button.
17+
* `cancelLabel` - (Optional) The label of the cancel button.
18+
19+
To see all properties of the `UMB_CONFIRM_MODAL` token, see the [API reference](https://apidocs.umbraco.com/v16/ui-api/interfaces/packages_core_modal.UmbConfirmModalData.html).
20+
21+
The `onSubmit` method returns a promise that resolves when the user confirms the dialog, and rejects when the user cancels the dialog.
2122

2223
## Basic Usage
2324

2425
{% code title="my-element.ts" %}
2526
```typescript
26-
import { html, LitElement, customElement } from "@umbraco-cms/backoffice/external/lit";
27-
import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api';
28-
import { umbOpenModal, UMB_CONFIRM_MODAL } from '@umbraco-cms/backoffice/modal';
29-
30-
@customElement('my-element')
31-
export class MyElement extends UmbElementMixin(LitElement) {
27+
import {
28+
html,
29+
LitElement,
30+
customElement,
31+
} from "@umbraco-cms/backoffice/external/lit";
32+
import { UmbElementMixin } from "@umbraco-cms/backoffice/element-api";
33+
import { umbOpenModal, UMB_CONFIRM_MODAL } from "@umbraco-cms/backoffice/modal";
3234

35+
@customElement("my-confirmation-modal")
36+
export class MyConfirmationModal extends UmbElementMixin(LitElement) {
3337
#onRequestDisable() {
34-
const modalContext = umbOpenModal(
35-
this, UMB_CONFIRM_MODAL,
36-
{
37-
data: {
38-
headline: this.localize.term("actions_disable"),
39-
content: this.localize.term("defaultdialogs_confirmdisable"),
40-
color: "danger",
41-
confirmLabel: this.localize.term("actions_disable"),
42-
}
43-
}
44-
)
38+
umbOpenModal(this, UMB_CONFIRM_MODAL, {
39+
data: {
40+
headline: this.localize.term("actions_disable"),
41+
content: this.localize.term("defaultdialogs_confirmdisable"),
42+
color: "danger",
43+
confirmLabel: this.localize.term("actions_disable"),
44+
},
45+
})
4546
.then(() => {
4647
console.log("User has approved");
4748
})
@@ -52,10 +53,11 @@ export class MyElement extends UmbElementMixin(LitElement) {
5253

5354
render() {
5455
return html`<uui-button
55-
look="primary"
56-
color="danger"
57-
@click=${this.#onRequestDisable}
58-
label=${this.localize.term("actions_disable")}></uui-button>`;
56+
look="primary"
57+
color="danger"
58+
@click=${this.#onRequestDisable}
59+
label=${this.localize.term("actions_disable")}
60+
></uui-button>`;
5961
}
6062
}
6163
```

0 commit comments

Comments
 (0)