Dialog
A pure vanilla JS implementation of Zag JS Dialog
Anatomy
The Dialog component consists of the following data-part
trigger
backdrop
positioner
title
description
close-trigger
Title
Description
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Data attributes
Each dialog can be set with different settings with the following data-attribute.
Title
Description
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Callbacks
Each dialog component can receive callbacks that can be used to respond to user interaction with custom behavior.
You must add a custom id and an event listener for your event name
document.getElementById("my-callback-dialog")
?.addEventListener("my-callback-dialog-event", (event) => {
console.log("Received event:", (event as CustomEvent).detail);
});
Title
Description
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Open your browser's console to see the events received when you open or close the above dialog
Open State Control
Dialog open state can be control with data attributes on any element, it can also be outside of the dialog
You must set a custom id for your dialog, as the default is randomly generated
data-open-dialog="dialog-id"
data-close-dialog="dialog-id"
Title
Description
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
You also dispatch an event named dialog:set-open
to the dialog id with a boolean value
const el = document.getElementById("my-dialog");
if (el) {
el.dispatchEvent(
new CustomEvent("dialog:set-open", {
detail: { value: true },
})
);
} else {
console.warn("Element with ID 'my-dialog' not found");
}
Templates
Dialog components is available in the followng templates
-
Corex template
Default corex templates. It provides the global, semantic and components tokens
-
Modex template
Based on Corex default template, it adds dark and light mode option to the tokens
-
Themex template
Based on the Corex default template, it adds theming capabilities as well as light and dark mode options to the tokens.