icons 0.6.3

Icons for Rust fullstack applications — Leptos and Dioxus.
Documentation
//! Single optimized Icon component for all icons
//!
//! This replaces 1,636+ individual component functions with a single
//! registry-based component for improved build performance.

use dioxus::prelude::*;

use super::icon_type::IconType;
use super::icon_registry::get_icon_data;
use super::svg_icon::SvgIcon;

/// Single optimized Icon component that renders any icon via registry lookup
#[component]
pub fn Icon(icon: IconType, class: Option<String>) -> Element {
    // Get icon data from registry
    let elements = get_icon_data(icon);

    match elements {
        Some(elements) => rsx! {
            SvgIcon { class,
                title { "Rust UI Icons - {icon:?}" }

                for element in elements.iter() {
                    {element.to_dioxus_element()}
                }
            }
        },
        None => rsx! {
            SvgIcon { class,
                title { "Rust UI Icons - Missing Icon: {icon:?}" }

                // Fallback for missing icons - show a question mark
                circle { cx: "12", cy: "12", r: "10" }
                path { d: "M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3" }
                circle { cx: "12", cy: "17", r: ".5" }
            }
        }
    }
}

/// Convenience function to create an Icon with just the icon type
pub fn icon(icon_type: IconType) -> Element {
    rsx! {
        Icon { icon: icon_type, class: None }
    }
}

/// Convenience function to create an Icon with a CSS class
pub fn icon_with_class(icon_type: IconType, class: &str) -> Element {
    rsx! {
        Icon { icon: icon_type, class: Some(class.to_string()) }
    }
}

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

    #[test]
    fn test_icon_component_renders() {
        // This would be a more complete test in a real application
        // For now, just verify the component can be created
        let _icon = Icon { icon: IconType::Activity, class: None };
    }
}