#![doc = include_str!("../LEPTOS.md")]
use crate::common::{
Color, Placement, Shape, Size, Variant, base_anchor_style, base_badge_style, base_label_style,
};
use leptos::prelude::*;
#[component]
pub fn Anchor(
children: Children,
#[prop(default = "")]
class: &'static str,
#[prop(default = "")]
style: &'static str,
#[prop(default = "")]
id: &'static str,
#[prop(default = "")]
data_testid: &'static str,
) -> impl IntoView {
view! {
<span
id=id
class=format!("badge-anchor {}", class)
style=format!("{} {}", base_anchor_style(), style)
data-testid=data_testid
>
{children()}
</span>
}
}
#[component]
pub fn Label(
children: Children,
#[prop(default = "")]
class: &'static str,
#[prop(default = "")]
style: &'static str,
#[prop(default = "")]
id: &'static str,
) -> impl IntoView {
view! {
<span
id=id
class=format!("badge__label {}", class)
style=format!("{} {}", base_label_style(), style)
>
{children()}
</span>
}
}
#[component]
pub fn Badge(
#[prop(optional)]
children: Option<Children>,
#[prop(default = Color::Default)]
color: Color,
#[prop(default = Variant::Primary)]
variant: Variant,
#[prop(default = Size::Md)]
size: Size,
#[prop(default = Placement::TopRight)]
placement: Placement,
#[prop(default = Shape::Rectangle)]
shape: Shape,
#[prop(default = "")]
class: &'static str,
#[prop(default = "")]
style: &'static str,
#[prop(default = "")]
id: &'static str,
#[prop(default = "Badge")]
aria_label: &'static str,
#[prop(default = "")]
data_testid: &'static str,
) -> impl IntoView {
let has_children = children.is_some();
let color_style = match variant {
Variant::Primary => color.to_primary_style(),
Variant::Secondary => color.to_secondary_style(),
Variant::Soft => color.to_soft_style(),
};
let size_style = if has_children {
size.to_label_style()
} else {
size.to_dot_style()
};
let full_style = format!(
"{} {} {} {} {}",
base_badge_style(),
color_style,
size_style,
placement.to_style(shape),
style,
);
let badge_class = format!(
"badge {} {} {} {} {}",
variant.to_class(),
color.to_class(),
size.to_class(),
placement.to_class(),
class,
);
view! {
<span
id=id
class=badge_class
style=full_style
role="status"
aria-label=aria_label
aria-atomic="true"
data-testid=data_testid
>
{children.map(|ch| view! { <Label>{ch()}</Label> }.into_any())}
</span>
}
}