#![doc = include_str!("../YEW.md")]
use crate::common::{
Variant, base_card_style, base_content_style, base_description_style, base_footer_style,
base_header_style, base_title_style,
};
use yew::prelude::*;
#[derive(Properties, PartialEq, Clone)]
pub struct CardProps {
#[prop_or_default]
pub children: Children,
#[prop_or_default]
pub variant: Variant,
#[prop_or_default]
pub class: &'static str,
#[prop_or_default]
pub style: &'static str,
#[prop_or_default]
pub id: &'static str,
#[prop_or("article")]
pub role: &'static str,
#[prop_or_default]
pub aria_label: &'static str,
#[prop_or_default]
pub aria_labelledby: &'static str,
#[prop_or_default]
pub data_testid: &'static str,
}
#[function_component(Card)]
pub fn card(props: &CardProps) -> Html {
let variant_style = props.variant.to_style();
let effective_variant_style: String = if props.style.contains("background") {
variant_style
.split(';')
.filter(|p| {
let t = p.trim().to_ascii_lowercase();
!t.starts_with("background")
})
.collect::<Vec<_>>()
.join(";")
} else {
variant_style.to_string()
};
let full_style = format!(
"{} {} {}",
base_card_style(),
effective_variant_style,
props.style,
);
let card_class = format!("card {} {}", props.variant.to_class(), props.class);
html! {
<div
id={props.id}
class={card_class}
style={full_style}
role={props.role}
aria-label={props.aria_label}
aria-labelledby={props.aria_labelledby}
data-testid={props.data_testid}
>
{ for props.children.iter() }
</div>
}
}
#[derive(Properties, PartialEq, Clone)]
pub struct HeaderProps {
#[prop_or_default]
pub children: Children,
#[prop_or_default]
pub class: &'static str,
#[prop_or_default]
pub style: &'static str,
#[prop_or_default]
pub id: &'static str,
}
#[function_component(Header)]
pub fn card_header(props: &HeaderProps) -> Html {
let full_style = format!("{} {}", base_header_style(), props.style);
html! {
<div
id={props.id}
class={format!("card__header {}", props.class)}
style={full_style}
>
{ for props.children.iter() }
</div>
}
}
#[derive(Properties, PartialEq, Clone)]
pub struct TitleProps {
#[prop_or_default]
pub children: Children,
#[prop_or_default]
pub class: &'static str,
#[prop_or_default]
pub style: &'static str,
#[prop_or_default]
pub id: &'static str,
}
#[function_component(Title)]
pub fn card_title(props: &TitleProps) -> Html {
let full_style = format!("{} {}", base_title_style(), props.style);
html! {
<h3
id={props.id}
class={format!("card__title {}", props.class)}
style={full_style}
>
{ for props.children.iter() }
</h3>
}
}
#[derive(Properties, PartialEq, Clone)]
pub struct DescriptionProps {
#[prop_or_default]
pub children: Children,
#[prop_or_default]
pub class: &'static str,
#[prop_or_default]
pub style: &'static str,
#[prop_or_default]
pub id: &'static str,
}
#[function_component(Description)]
pub fn card_description(props: &DescriptionProps) -> Html {
let full_style = format!("{} {}", base_description_style(), props.style);
html! {
<p
id={props.id}
class={format!("card__description {}", props.class)}
style={full_style}
>
{ for props.children.iter() }
</p>
}
}
#[derive(Properties, PartialEq, Clone)]
pub struct ContentProps {
#[prop_or_default]
pub children: Children,
#[prop_or_default]
pub class: &'static str,
#[prop_or_default]
pub style: &'static str,
#[prop_or_default]
pub id: &'static str,
}
#[function_component(Content)]
pub fn card_content(props: &ContentProps) -> Html {
let full_style = format!("{} {}", base_content_style(), props.style);
html! {
<div
id={props.id}
class={format!("card__content {}", props.class)}
style={full_style}
>
{ for props.children.iter() }
</div>
}
}
#[derive(Properties, PartialEq, Clone)]
pub struct FooterProps {
#[prop_or_default]
pub children: Children,
#[prop_or_default]
pub class: &'static str,
#[prop_or_default]
pub style: &'static str,
#[prop_or_default]
pub id: &'static str,
}
#[function_component(Footer)]
pub fn card_footer(props: &FooterProps) -> Html {
let full_style = format!("{} {}", base_footer_style(), props.style);
html! {
<div
id={props.id}
class={format!("card__footer {}", props.class)}
style={full_style}
>
{ for props.children.iter() }
</div>
}
}