Skip to content

Dialog

The dialog component deliveres specific information to the users or requires a specific action from them. The information can be critical, while the actions can involve making one or multiple decisions, or realizing one or more tasks.

The dialog component is intended for quick actions and should be used thoughtfully to avoid disrupting the user's flow.

Dialog Usage Setup

Unlike static components, the Dialog must be triggered programmatically. To display the dialog, you should emit the open-dialog event on the dialog entity. You can also listen for actions emitted by the buttons.

Initial Setup Example

This is an example of how you could initialize a dialog and a trigger button in your project.

js
scene.addEventListener("loaded", () => {
    // Get references to the elements
    const button = document.getElementById("openDialogButton");
    const dialog = document.getElementById("dialogBox");

    // Open the dialog on button click
    button.addEventListener("click", () => {
        openDialog(dialog, button);
    });

    // Handle dialog actions
    dialog.addEventListener("dialogAction", (e) => {
        console.log("Dialog action:", e.detail.action);
        // Logic for custom actions like 'confirm', 'cancel', etc.
    });
});

function openDialog(dialog, button) {
    dialog.emit("open-dialog");

    button.setAttribute("visible", false);
    button.classList.remove("clickable");

    // Attach event to re-enable button
    dialog.addEventListener("dialogClosed", () => {
        enableButton(button);
    }); 
}

// Function to show the button again and re-enable interaction
function enableButton(button) {
    setTimeout(() => {
    button.setAttribute("visible", true);
    button.classList.add("clickable");
    }, 100);
}

Example

Basic Dialog

The first example demonstrates a standard dialog with a title, content, and the default "Close" button.

Customized Actions and Style

This example demonstrates a dialog with customized buttons (save/cancel), a prependicon, and a specific background color. It also uses a transition to animate from the bottom. As can be seen from the output, eventhough the text color is set to white, it is changed to black, for better contrast with the background.

Props

PropertyTypeDefaultDescription
visiblebooleantrueControls the dialog's visibility.
positionnumber[]0 0 0Specifies the dialog's position in 3D space.
opacitynumber1Specifies the opacity of the component.
colorstring (blue, #fff)""Defines the primary color of the dialog, affecting elements such as text.
textcolorstringblackSpecifies the color of the dialog's text. If the contrast with the background is insufficient, the text color will not be applied.
modestring (light, dark)"light"Specifies the color scheme of the dialog, supporting either a light or dark mode.
prependiconstring""Displays an icon before the dialog title.
closingiconbooleanfalseDetermines whether a closing (X) icon is displayed.
titlestring"Dialog Title"Sets the title text displayed at the top of the dialog.
contentstring"This is an example of the basic dialog component."Sets the main body text of the dialog.
buttonsarray[{ label: "Close", action: "close" }]Defines the action buttons displayed at the bottom of the dialog. Supports up to two buttons. Buttons emit a dialogAction event containing their action string.
transitionstring (bottom-top, top-bottom)""Specifies the enter animation direction, either sliding in from the bottom or from the top.