Alert Dialog source

Inspect and copy the reviewed source included with this Free component.

Free source · 4 files

recipe.rs

// SPDX-FileCopyrightText: 2026 Proa Labs, Inc.
// SPDX-License-Identifier: MIT OR Apache-2.0

//! Alert Dialog recipe — one const named-slot table for every public part.
//!
//! Static modal primitives are sourced from Dialog where the two components
//! are visually identical. Alert-specific action and cancel controls remain
//! local to this recipe.

use crate::components::dialog::{DialogSize, DIALOG_RECIPE, DIALOG_SIZE_MD};
use crate::tw_join;

const ALERT_DIALOG_ROOT: &str = "group/alert-dialog";
const ALERT_DIALOG_CONTENT: &str = tw_join!(DIALOG_RECIPE.content, DIALOG_SIZE_MD);

const ALERT_DIALOG_ACTION: &str = tw_join!(
    "inline-flex",
    "items-center",
    "justify-center",
    "gap-2",
    "whitespace-nowrap",
    "rounded-md",
    "text-sm",
    "font-medium",
    "transition-colors",
    "h-9",
    "px-4",
    "py-2",
    "bg-destructive",
    "text-destructive-foreground",
    "shadow-xs",
    "hover:bg-destructive/90",
    "focus-visible:outline-hidden",
    "focus-visible:ring-2",
    "focus-visible:ring-ring"
);

const ALERT_DIALOG_CANCEL: &str = tw_join!(
    "inline-flex",
    "items-center",
    "justify-center",
    "gap-2",
    "whitespace-nowrap",
    "rounded-md",
    "text-sm",
    "font-medium",
    "transition-colors",
    "h-9",
    "px-4",
    "py-2",
    "border",
    "border-input",
    "bg-background",
    "text-foreground",
    "shadow-xs",
    "hover:bg-accent",
    "hover:text-accent-foreground",
    "focus-visible:outline-hidden",
    "focus-visible:ring-2",
    "focus-visible:ring-ring"
);

/// Static named classes for every Alert Dialog part.
#[derive(Debug, Clone, Copy)]
pub struct AlertDialogRecipe {
    pub root: &'static str,
    pub trigger: &'static str,
    pub overlay: &'static str,
    pub content: &'static str,
    pub header: &'static str,
    pub footer: &'static str,
    pub title: &'static str,
    pub description: &'static str,
    pub action: &'static str,
    pub cancel: &'static str,
}

/// Global zero-initialization Alert Dialog recipe.
pub const ALERT_DIALOG_RECIPE: AlertDialogRecipe = AlertDialogRecipe {
    root: ALERT_DIALOG_ROOT,
    trigger: DIALOG_RECIPE.trigger,
    overlay: DIALOG_RECIPE.overlay,
    content: ALERT_DIALOG_CONTENT,
    header: DIALOG_RECIPE.header,
    footer: DIALOG_RECIPE.footer,
    title: DIALOG_RECIPE.title,
    description: DIALOG_RECIPE.description,
    action: ALERT_DIALOG_ACTION,
    cancel: ALERT_DIALOG_CANCEL,
};

pub const fn alert_dialog_recipe() -> &'static AlertDialogRecipe {
    &ALERT_DIALOG_RECIPE
}

impl crate::variant_spec::ComponentSpec for AlertDialogRecipe {
    const NAME: &'static str = "AlertDialog";

    fn base_classes(&self) -> &'static str {
        self.root
    }

    fn variant_metadata(&self) -> Vec<crate::variant_spec::VariantMetadata> {
        Vec::new()
    }

    fn anatomy(&self) -> Option<crate::Anatomy> {
        Some(super::ALERT_DIALOG_ANATOMY)
    }
}

/// Compatibility helpers for the former standalone class API.
pub const fn alert_dialog_action_classes() -> &'static str {
    ALERT_DIALOG_RECIPE.action
}

pub const fn alert_dialog_cancel_classes() -> &'static str {
    ALERT_DIALOG_RECIPE.cancel
}

pub const fn alert_dialog_content_base_classes() -> &'static str {
    DIALOG_RECIPE.content
}

pub const fn alert_dialog_content_size_classes() -> &'static str {
    DialogSize::Md.classes()
}

pub const fn alert_dialog_overlay_classes() -> &'static str {
    ALERT_DIALOG_RECIPE.overlay
}

pub const fn alert_dialog_header_classes() -> &'static str {
    ALERT_DIALOG_RECIPE.header
}

pub const fn alert_dialog_footer_classes() -> &'static str {
    ALERT_DIALOG_RECIPE.footer
}

pub const fn alert_dialog_title_classes() -> &'static str {
    ALERT_DIALOG_RECIPE.title
}

pub const fn alert_dialog_description_classes() -> &'static str {
    ALERT_DIALOG_RECIPE.description
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn recipe_exposes_every_named_slot() {
        let recipe = alert_dialog_recipe();
        assert!(recipe.root.contains("group/alert-dialog"));
        assert!(recipe.trigger.contains("inline-flex"));
        assert!(recipe.overlay.contains("bg-black/50"));
        assert!(recipe.content.contains("max-w-lg"));
        assert!(recipe.header.contains("sm:text-left"));
        assert!(recipe.footer.contains("sm:justify-end"));
        assert!(recipe.title.contains("text-foreground"));
        assert!(recipe.description.contains("text-muted-foreground"));
        assert!(recipe.action.contains("bg-destructive"));
        assert!(recipe.cancel.contains("border-input"));
    }

    #[test]
    fn identical_dialog_primitives_are_shared() {
        assert_eq!(ALERT_DIALOG_RECIPE.trigger, DIALOG_RECIPE.trigger);
        assert_eq!(ALERT_DIALOG_RECIPE.overlay, DIALOG_RECIPE.overlay);
        assert_eq!(ALERT_DIALOG_RECIPE.header, DIALOG_RECIPE.header);
        assert_eq!(ALERT_DIALOG_RECIPE.footer, DIALOG_RECIPE.footer);
        assert_eq!(ALERT_DIALOG_RECIPE.title, DIALOG_RECIPE.title);
        assert_eq!(ALERT_DIALOG_RECIPE.description, DIALOG_RECIPE.description);
    }

    #[test]
    fn compatibility_helpers_delegate_to_recipe() {
        assert_eq!(alert_dialog_action_classes(), ALERT_DIALOG_RECIPE.action);
        assert_eq!(alert_dialog_cancel_classes(), ALERT_DIALOG_RECIPE.cancel);
        assert_eq!(alert_dialog_content_base_classes(), DIALOG_RECIPE.content);
        assert_eq!(
            alert_dialog_content_size_classes(),
            DialogSize::Md.classes()
        );
    }

    #[test]
    fn component_metadata_uses_canonical_anatomy() {
        use crate::variant_spec::ComponentSpec;

        assert_eq!(
            ALERT_DIALOG_RECIPE.anatomy(),
            Some(super::super::ALERT_DIALOG_ANATOMY)
        );
        assert!(ALERT_DIALOG_RECIPE.variant_metadata().is_empty());
    }
}

Copy this source with the Free Proa UI components it imports; those component files remain available from their own source pages.

Licensed under MIT OR Apache-2.0. Third-party notices remain attached to the installed payload.

Open Markdown
FreeAlert Dialog

Accessible confirmation flows.

Install with the Proa CLI
proa ui add alert_dialog

Installs the reviewed component source, dependencies, shared support files, and required legal notices.

CLI and registry setup
recipe.rs
// SPDX-FileCopyrightText: 2026 Proa Labs, Inc.
// SPDX-License-Identifier: MIT OR Apache-2.0

//! Alert Dialog recipe — one const named-slot table for every public part.
//!
//! Static modal primitives are sourced from Dialog where the two components
//! are visually identical. Alert-specific action and cancel controls remain
//! local to this recipe.

use crate::components::dialog::{DialogSize, DIALOG_RECIPE, DIALOG_SIZE_MD};
use crate::tw_join;

const ALERT_DIALOG_ROOT: &str = "group/alert-dialog";
const ALERT_DIALOG_CONTENT: &str = tw_join!(DIALOG_RECIPE.content, DIALOG_SIZE_MD);

const ALERT_DIALOG_ACTION: &str = tw_join!(
    "inline-flex",
    "items-center",
    "justify-center",
    "gap-2",
    "whitespace-nowrap",
    "rounded-md",

Search

Type at least 2 characters

Customize

Make it yours

Palette

Radius

Overview
Components
Settings

Build your own

Themed Proa UI surface

Preview
Components52
RecipesTyped
customer-portal