Component
dialog
dx components add dialogA dialog component for displaying modal content.
Installation
Use the CLI command for the common path, or copy the component files manually.
Manual installation files
Copy the component source and CSS into your app. Import the shared theme CSS once near your app root.
use dioxus::prelude::*;
use dioxus_primitives::dialog::{self, DialogDescriptionProps, DialogRootProps, DialogTitleProps};
use dioxus_primitives::{dioxus_attributes::attributes, merge_attributes};
#[component]
pub fn Dialog(props: DialogRootProps) -> Element {
let base = attributes!(div {
class: "dx-dialog",
});
let merged = merge_attributes(vec![base, props.attributes]);
rsx! {
document::Link { rel: "stylesheet", href: asset!("/src/components/dialog/style.css") }
dialog::DialogRoot {
class: "dx-dialog-backdrop",
id: props.id,
is_modal: props.is_modal,
open: props.open,
default_open: props.default_open,
on_open_change: props.on_open_change,
dialog::DialogContent {
class: None,
attributes: merged,
{props.children}
}
}
}
}
#[component]
pub fn DialogTitle(props: DialogTitleProps) -> Element {
let base = attributes!(h2 {
class: "dx-dialog-title",
});
let merged = merge_attributes(vec![base, props.attributes]);
rsx! {
document::Link { rel: "stylesheet", href: asset!("/src/components/dialog/style.css") }
dialog::DialogTitle {
id: props.id,
attributes: merged,
{props.children}
}
}
}
#[component]
pub fn DialogDescription(props: DialogDescriptionProps) -> Element {
let base = attributes!(p {
class: "dx-dialog-description",
});
let merged = merge_attributes(vec![base, props.attributes]);
rsx! {
document::Link { rel: "stylesheet", href: asset!("/src/components/dialog/style.css") }
dialog::DialogDescription {
id: props.id,
attributes: merged,
{props.children}
}
}
}Usage notes
The dialog component can be used to display additional information or actions related to an item. It is a simple modal dialog that can be opened and closed by the user.
Component Structure
// The dialog component must wrap all dialog elements.
Dialog {
// The open prop determines if the dialog is currently open or closed.
open: open(),
// The dialog title defines the heading of the dialog.
DialogTitle {
"Item information"
}
// The dialog description provides additional information about the dialog.
DialogDescription {
"Here is some additional information about the item."
}
}