Appearance
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
| Property | Type | Default | Description |
|---|---|---|---|
| visible | boolean | true | Controls the dialog's visibility. |
| position | number[] | 0 0 0 | Specifies the dialog's position in 3D space. |
| opacity | number | 1 | Specifies the opacity of the component. |
| color | string (blue, #fff) | "" | Defines the primary color of the dialog, affecting elements such as text. |
| textcolor | string | black | Specifies the color of the dialog's text. If the contrast with the background is insufficient, the text color will not be applied. |
| mode | string (light, dark) | "light" | Specifies the color scheme of the dialog, supporting either a light or dark mode. |
| prependicon | string | "" | Displays an icon before the dialog title. |
| closingicon | boolean | false | Determines whether a closing (X) icon is displayed. |
| title | string | "Dialog Title" | Sets the title text displayed at the top of the dialog. |
| content | string | "This is an example of the basic dialog component." | Sets the main body text of the dialog. |
| buttons | array | [{ 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. |
| transition | string (bottom-top, top-bottom) | "" | Specifies the enter animation direction, either sliding in from the bottom or from the top. |
