Skip to main content

tablo_ui/components/primitives/
alert_dialog.rs

1// SYNC: topcoat-ui-registry@0.10.0 sha256:59329070384145eceb1ac54aab6143862415024a10d461892395c11bf927db38 — do not hand-edit. Sync via `cargo xtask sync-topcoat-ui` (ADR-0007).
2use topcoat::{
3    Result,
4    runtime::Expr,
5    view::{Attributes, Child, View, attributes, component, view},
6};
7
8use super::dialog::dialog;
9
10/// A dialog that asks the user to respond to an important message.
11///
12/// Build its content with the dialog components and provide actions for answering or
13/// cancelling. It uses `role="alertdialog"` and has the same focus and dismissal
14/// requirements as [`dialog`].
15///
16/// Pass `aria-labelledby` and `aria-describedby` in `attrs`, pointing to the title and
17/// description IDs. Other attributes are forwarded to the `<dialog>`.
18///
19/// ```ignore
20/// view! {
21///     alert_dialog(
22///         open: confirming,
23///         dialog_content(
24///             dialog_header(
25///                 dialog_title("Delete this workspace?")
26///                 dialog_description("Its projects and deploys go with it.")
27///             )
28///             dialog_footer(
29///                 <a href="/workspace" class=(button_variants(
30///                     ButtonVariant::Ghost,
31///                     ButtonSize::Md,
32///                 ))>"Keep it"</a>
33///                 button(variant: ButtonVariant::Destructive, "Delete")
34///             )
35///         )
36///     )
37/// }
38/// ```
39#[component]
40pub async fn alert_dialog(
41    /// Whether the alert dialog shows.
42    #[into]
43    open: Expr<bool>,
44    /// Extra attributes for the `<dialog>` element.
45    #[default]
46    attrs: Attributes,
47    /// The alert dialog's content.
48    #[default]
49    child: Child<'_>,
50) -> Result<impl View> {
51    Ok(view! {
52        dialog(open: open, attrs: attributes! { role="alertdialog" (attrs) }, (child))
53    })
54}