use leptos::prelude::CustomAttribute;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Size {
Large,
Medium,
Normal,
Small,
}
impl Size {
pub fn bulma(self) -> &'static str {
match self {
Size::Small => "is-small",
Size::Normal => "",
Size::Medium => "is-medium",
Size::Large => "is-large",
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TestAttr {
pub key: String,
pub value: String,
}
impl TestAttr {
pub fn new<K: Into<String>, V: Into<String>>(key: K, value: V) -> Self {
Self {
key: key.into(),
value: value.into(),
}
}
pub fn test_id<V: Into<String>>(value: V) -> Self {
Self {
key: "data-testid".to_string(),
value: value.into(),
}
}
}
impl From<String> for TestAttr {
fn from(value: String) -> Self {
TestAttr::test_id(value)
}
}
impl From<&str> for TestAttr {
fn from(value: &str) -> Self {
TestAttr::test_id(value.to_string())
}
}
pub fn test_attr_attr(test_attr: Option<TestAttr>) -> impl CustomAttribute<String, String> {
let ta = test_attr;
move || {
ta.as_ref()
.map(|attr| (attr.key.clone(), attr.value.clone()))
}
}