icons 0.3.5

Icons for Rust fullstack applications — Leptos and Dioxus.
Documentation
/// Macro to create Leptos 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_leptos_icons!(AArrowDown, a_arrow_down);
/// create_leptos_icons!(Activity, activity);
/// ```
#[macro_export]
macro_rules! create_leptos_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::leptos::parser::SvgElement>> = std::sync::OnceLock::new();
        }

        #[component]
        pub fn $component_name(#[prop(into, optional)] class: Signal<String>) -> impl IntoView {
            use leptos::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_TXT/", stringify!($snake_name), ".txt"));
                    parse_svg_elements(SVG_CONTENT)
                });
            }

            view! {
                <SvgIcon class=class>
                    <title>{format!("Rust UI Icons - {}", stringify!($component_name))}</title>

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