use crate::class::Class;
use dioxus::prelude::*;
use dioxus_free_icons::IconShape;
pub fn Icon(props: IconProps) -> Element {
if props.icon_class.is_empty() {
rsx! {
span {
class: props.class,
{ props.children }
}
}
} else {
rsx! {
span {
class: props.class,
i {
class: props.icon_class,
}
}
}
}
}
#[derive(Clone, PartialEq, Props)]
pub struct IconProps {
#[props(into, default = "icon")]
pub class: Class,
#[props(into, default)]
pub icon_class: Class,
children: Element,
}
pub fn SvgIcon<T: IconShape + Clone + PartialEq + 'static>(props: SvgIconProps<T>) -> Element {
let width = props.width;
let height = props.height.unwrap_or(width);
let style = if props.intrinsic {
format!("width:{width}px;height:{height}px")
} else {
String::new()
};
rsx! {
span {
class: props.class,
style: "{style}",
dioxus_free_icons::Icon {
icon: props.shape,
width: width,
height: height,
}
}
}
}
#[derive(Clone, PartialEq, Props)]
pub struct SvgIconProps<T: IconShape + Clone + PartialEq + 'static> {
#[props(into, default = "icon")]
pub class: Class,
pub shape: T,
#[props(default = 20)]
pub width: u32,
#[props(into)]
pub height: Option<u32>,
#[props(default = false)]
pub intrinsic: bool,
}
pub fn IconText(props: IconTextProps) -> Element {
rsx! {
span {
class: "{props.class}",
{ props.children }
}
}
}
#[derive(Clone, PartialEq, Props)]
pub struct IconTextProps {
#[props(into, default = "icon-text")]
pub class: Class,
children: Element,
}