use dioxus::prelude::*;
use crate::types::Color;
#[derive(Clone, PartialEq, Props)]
pub struct BadgeProps {
#[props(default = Color::Primary)]
pub color: Color,
#[props(default)]
pub pill: bool,
#[props(default)]
pub class: String,
#[props(default)]
pub onclick: Option<EventHandler<MouseEvent>>,
#[props(extends = GlobalAttributes)]
attributes: Vec<Attribute>,
pub children: Element,
}
#[component]
pub fn Badge(props: BadgeProps) -> Element {
let pill = if props.pill { " rounded-pill" } else { "" };
let full_class = if props.class.is_empty() {
format!("badge text-bg-{}{pill}", props.color)
} else {
format!("badge text-bg-{}{pill} {}", props.color, props.class)
};
rsx! {
span {
class: "{full_class}",
onclick: move |evt| {
if let Some(handler) = &props.onclick {
handler.call(evt);
}
},
..props.attributes,
{props.children}
}
}
}