icons 0.6.3

Icons for Rust fullstack applications โ€” Leptos and Dioxus.
Documentation
use dioxus::prelude::*;

// * ๐Ÿงช cargo test --package icons --lib --features dioxus

#[derive(Debug, Clone)]
pub enum SvgElement {
    Path { d: String },
    Circle { cx: String, cy: String, r: String },
    Rect { x: String, y: String, width: String, height: String, rx: Option<String>, ry: Option<String> },
    Ellipse { cx: String, cy: String, rx: String, ry: String },
    Line { x1: String, y1: String, x2: String, y2: String },
    Polyline { points: String },
    Polygon { points: String },
    // Add more SVG elements as needed (g, defs, etc.)
}

impl SvgElement {
    pub fn to_dioxus_element(&self) -> Element {
        match self {
            SvgElement::Path { d } => rsx! {
                path { d: "{d}" }
            },
            SvgElement::Circle { cx, cy, r } => rsx! {
                circle { cx: "{cx}", cy: "{cy}", r: "{r}" }
            },
            SvgElement::Rect { x, y, width, height, rx, ry } => match (rx, ry) {
                (Some(rx), Some(ry)) => rsx! {
                    rect {
                        x: "{x}",
                        y: "{y}",
                        width: "{width}",
                        height: "{height}",
                        rx: "{rx}",
                        ry: "{ry}",
                    }
                },
                (Some(rx), None) => rsx! {
                    rect {
                        x: "{x}",
                        y: "{y}",
                        width: "{width}",
                        height: "{height}",
                        rx: "{rx}",
                    }
                },
                (None, Some(ry)) => rsx! {
                    rect {
                        x: "{x}",
                        y: "{y}",
                        width: "{width}",
                        height: "{height}",
                        ry: "{ry}",
                    }
                },
                (None, None) => rsx! {
                    rect {
                        x: "{x}",
                        y: "{y}",
                        width: "{width}",
                        height: "{height}",
                    }
                },
            },
            SvgElement::Ellipse { cx, cy, rx, ry } => rsx! {
                ellipse {
                    cx: "{cx}",
                    cy: "{cy}",
                    rx: "{rx}",
                    ry: "{ry}",
                }
            },
            SvgElement::Line { x1, y1, x2, y2 } => rsx! {
                line {
                    x1: "{x1}",
                    y1: "{y1}",
                    x2: "{x2}",
                    y2: "{y2}",
                }
            },
            SvgElement::Polyline { points } => rsx! {
                polyline { points: "{points}" }
            },
            SvgElement::Polygon { points } => rsx! {
                polygon { points: "{points}" }
            },
        }
    }
}