dialog
The dialog function wraps the <mdui-dialog> component. It provides a convenient way to open a dialog without writing any HTML.
<mdui-button class="example-button">open</mdui-button>
<script type="module">
import { dialog } from "mdui/functions/dialog.js";
const button = document.querySelector(".example-button");
button.addEventListener("click", () => {
dialog({
headline: "Dialog Title",
description: "Dialog description",
actions: [
{
text: "Cancel",
},
{
text: "OK",
onClick: () => {
console.log("confirmed");
return false;
},
}
]
});
});
</script>API
dialog(options: Options): Dialog
The dialog function takes an Options object and returns the <mdui-dialog> instance.
Options
| Property | Type | Default |
|---|---|---|
headline |
string |
- |
| The title of the dialog. | ||
description |
string |
- |
| The description of the dialog. | ||
body |
string | HTMLElement | JQ<HTMLElement> |
- |
| The content of the dialog's body, accepts HTML string, DOM element, or a JQ object. | ||
icon |
string |
- |
| The Material Icons name displayed at the top of the dialog. | ||
closeOnEsc |
boolean |
false |
Whether the dialog can be closed by pressing the Esc key. If set to true, the dialog closes when the Esc key is pressed. |
||
closeOnOverlayClick |
boolean |
false |
| Whether the dialog can be closed by clicking on the overlay. | ||
actions |
Action[] |
- |
| The array of bottom action buttons. | ||
stackedActions |
boolean |
false |
| Whether to stack the bottom action buttons vertically. | ||
queue |
string |
- |
|
The queue name. Queues are disabled by default. If this function is called multiple times, multiple dialogs will appear simultaneously. If you provide a queue name, dialogs with the same name open one after another. The |
||
onOpen |
(dialog: Dialog) => void |
- |
|
Called when the dialog starts to open. The callback receives the dialog instance as its argument, and |
||
onOpened |
(dialog: Dialog) => void |
- |
|
Called when the dialog's open animation completes. The callback receives the dialog instance as its argument, and |
||
onClose |
(dialog: Dialog) => void |
- |
|
Called when the dialog starts to close. The callback receives the dialog instance as its argument, and |
||
onClosed |
(dialog: Dialog) => void |
- |
|
Called when the dialog's close animation completes. The callback receives the dialog instance as its argument, and |
||
onOverlayClick |
(dialog: Dialog) => void |
- |
|
Called when the overlay is clicked. The callback receives the dialog instance as its argument, and |
||
Action
| Property | Type | Default |
|---|---|---|
text |
string |
- |
| Button text. | ||
onClick |
(dialog: Dialog) => void | boolean | Promise<void> |
- |
|
Called when the button is clicked. The callback receives the dialog instance as its argument, and By default, clicking the button closes the dialog. If the return value is |
||