use leptos::{prelude::*, svg};
#[component]
pub fn Icon(
#[prop(into)]
icon: Signal<icondata_core::Icon>,
#[prop(into, optional)] style: MaybeProp<String>,
#[prop(into, optional)] width: MaybeProp<String>,
#[prop(into, optional)] height: MaybeProp<String>,
) -> impl IntoView {
move || {
let icon = icon.get();
svg::svg()
.style(match (style.get(), icon.style) {
(Some(a), Some(b)) => Some(format!("{b} {a}")),
(Some(a), None) => Some(a),
(None, Some(b)) => Some(b.to_string()),
_ => None,
})
.attr("x", icon.x)
.attr("y", icon.y)
.attr("width", width.get().unwrap_or_else(|| "1em".to_string()))
.attr("height", height.get().unwrap_or_else(|| "1em".to_string()))
.attr("viewBox", icon.view_box)
.attr("stroke-linecap", icon.stroke_linecap)
.attr("stroke-linejoin", icon.stroke_linejoin)
.attr("stroke-width", icon.stroke_width)
.attr("stroke", icon.stroke)
.attr("fill", icon.fill.unwrap_or("currentColor"))
.attr("role", "graphics-symbol")
.child(svg::InertElement::new(icon.data))
}
}
#[component]
pub fn Symbol(
#[prop(into)]
id: String,
#[prop(into)]
icon: Signal<icondata_core::Icon>,
#[prop(into, optional)] style: MaybeProp<String>,
) -> impl IntoView {
move || {
let icon = icon.get();
let sym = svg::symbol()
.style(match (style.get(), icon.style) {
(Some(a), Some(b)) => Some(format!("{b} {a}")),
(Some(a), None) => Some(a),
(None, Some(b)) => Some(b.to_string()),
_ => None,
})
.attr("id", id.clone())
.attr("x", icon.x)
.attr("y", icon.y)
.attr("viewBox", icon.view_box)
.attr("stroke-linecap", icon.stroke_linecap)
.attr("stroke-linejoin", icon.stroke_linejoin)
.attr("stroke-width", icon.stroke_width)
.attr("stroke", icon.stroke)
.attr("fill", icon.fill.unwrap_or("currentColor"))
.attr("role", "graphics-symbol")
.child(svg::InertElement::new(icon.data));
svg::svg().style("display: none;").child(sym)
}
}