icons 0.6.0

Icons for Rust fullstack applications — Leptos and Dioxus.
Documentation
/// Macro to create Dioxus icon components with cached SVG parsing
///
/// This macro generates both a per-icon cache and the component function.
/// SVG parsing is performed only once per icon type using OnceLock.
///
/// Usage:
/// ```rust
/// create_dioxus_icons!(AArrowDown, a_arrow_down);
/// create_dioxus_icons!(Activity, activity);
/// ```
#[macro_export]
macro_rules! create_dioxus_icons {
    ($component_name:ident, $snake_name:ident) => {
        // Generate a unique cache for this icon using paste for hygiene
        paste::paste! {
            static [<$component_name:upper _CACHE>]: std::sync::OnceLock<Vec<$crate::dioxus::parser::SvgElement>> = std::sync::OnceLock::new();
        }

        #[component]
        pub fn $component_name(class: Option<String>) -> Element {
            use dioxus::prelude::*;

            use super::parser::parse_svg_elements;
            use super::svg_icon::SvgIcon;

            // Get cached parsed elements (parse only once per icon type)
            paste::paste! {
                let elements = [<$component_name:upper _CACHE>].get_or_init(|| {
                    // Read SVG content at compile time
                    const SVG_CONTENT: &str = include_str!(concat!("../../ICONS/", stringify!($snake_name), ".txt"));
                    parse_svg_elements(SVG_CONTENT)
                });
            }

            rsx! {
                SvgIcon { class,
                    title { "Rust UI Icons - {stringify!($component_name)}" }

                    for element in elements.iter() {
                        {element.to_dioxus_element()}
                    }
                }
            }
        }
    };
}