use yew::prelude::*;
pub fn intl_slug(key: &str) -> String {
key.chars()
.map(|x| {
if x.is_ascii_alphanumeric() {
x.to_ascii_lowercase()
} else {
'-'
}
})
.collect()
}
pub fn intl_content_style(var: &str) -> String {
format!("--psp-label--content: var(--psp-label--{var}--content)")
}
#[derive(Properties, PartialEq)]
pub struct IntlLabelProps {
pub name: String,
#[prop_or_default]
pub group: bool,
#[prop_or_default]
pub class: Classes,
}
#[function_component(IntlLabel)]
pub fn intl_label(props: &IntlLabelProps) -> Html {
let slug = intl_slug(&props.name);
let (id, var) = if props.group {
(
format!("{}-group-label", props.name),
format!("group-{slug}"),
)
} else {
(format!("{}-label", props.name), slug)
};
let style = intl_content_style(&var);
let class = classes!("intl-label", props.class.clone());
html! { <label {class} {id} {style} /> }
}