icons 0.7.2

Icons for Rust fullstack applications — Leptos and Dioxus.
Documentation
//! Single AnimatedIcon component using registry pattern
//!
//! This module provides a unified AnimatedIcon component that replaces individual
//! animated icon components with a single registry-based implementation.

use leptos::prelude::*;

use super::animated_icon_registry::get_animated_icon_elements;
use super::animated_icon_type::AnimatedIconType;
use super::css_registry::get_icon_css;
use super::svg_icon::SvgIcon;
// Import the leptos implementation for StaticSvgElement
use crate::leptos::static_svg_element;

/// Single AnimatedIcon component using registry lookup
///
/// This component replaces all individual animated icon components with a unified
/// registry-based implementation for better build performance while supporting CSS animations.
///
/// # Example
/// ```rust
/// use icons::leptos_animated::{AnimatedIcon, AnimatedIconType};
/// use leptos::prelude::*;
///
/// fn example() -> impl IntoView {
///     view! {
///         <AnimatedIcon icon=AnimatedIconType::Heart class="w-6 h-6" />
///         <AnimatedIcon icon=AnimatedIconType::Plus class="text-blue-500" />
///     }
/// }
/// ```
#[component]
pub fn AnimatedIcon(
    /// The animated icon type from the registry
    icon: AnimatedIconType,
    /// Optional CSS classes (reactive)
    #[prop(into, optional)]
    class: Signal<String>,
) -> impl IntoView {
    // Get elements from static registry (O(1) lookup, zero allocation)
    let elements = get_animated_icon_elements(icon).unwrap_or(&[]);

    // Get CSS for this icon (O(1) lookup, zero allocation)
    let icon_css = get_icon_css(icon);

    view! {
        // Inject CSS if this icon has animations
        {if let Some(css) = icon_css { view! { <style>{css}</style> }.into_any() } else { view! {}.into_any() }}

        <SvgIcon class=class data_name=icon.component_name().to_string()>
            <title>{format!("Rust UI Animated Icons - {}", icon.component_name())}</title>

            {elements.iter().map(|element| { element.to_leptos_view() }).collect::<Vec<_>>()}
        </SvgIcon>
    }
}