#![doc = include_str!("../LEPTOS.md")]
use crate::common::{
Variant, base_card_style, base_content_style, base_description_style, base_footer_style,
base_header_style, base_title_style,
};
use leptos::prelude::*;
#[component]
pub fn Card(
children: Children,
#[prop(default = Variant::Default)]
variant: Variant,
#[prop(default = "")]
class: &'static str,
#[prop(default = "")]
style: &'static str,
#[prop(default = "")]
id: &'static str,
#[prop(default = "article")]
role: &'static str,
#[prop(default = "")]
aria_label: &'static str,
#[prop(default = "")]
aria_labelledby: &'static str,
#[prop(default = "")]
data_testid: &'static str,
) -> impl IntoView {
let variant_style = variant.to_style();
let effective_variant_style: String = if 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,
style,
);
let card_class = format!("card {} {}", variant.to_class(), class);
view! {
<div
id=id
class=card_class
style=full_style
role=role
aria-label=aria_label
aria-labelledby=aria_labelledby
data-testid=data_testid
>
{children()}
</div>
}
}
#[component]
pub fn Header(
children: Children,
#[prop(default = "")]
class: &'static str,
#[prop(default = "")]
style: &'static str,
#[prop(default = "")]
id: &'static str,
) -> impl IntoView {
let full_style = format!("{} {}", base_header_style(), style);
view! {
<div
id=id
class=format!("card__header {}", class)
style=full_style
>
{children()}
</div>
}
}
#[component]
pub fn Title(
children: Children,
#[prop(default = "")]
class: &'static str,
#[prop(default = "")]
style: &'static str,
#[prop(default = "")]
id: &'static str,
) -> impl IntoView {
let full_style = format!("{} {}", base_title_style(), style);
view! {
<h3
id=id
class=format!("card__title {}", class)
style=full_style
>
{children()}
</h3>
}
}
#[component]
pub fn Description(
children: Children,
#[prop(default = "")]
class: &'static str,
#[prop(default = "")]
style: &'static str,
#[prop(default = "")]
id: &'static str,
) -> impl IntoView {
let full_style = format!("{} {}", base_description_style(), style);
view! {
<p
id=id
class=format!("card__description {}", class)
style=full_style
>
{children()}
</p>
}
}
#[component]
pub fn Content(
children: Children,
#[prop(default = "")]
class: &'static str,
#[prop(default = "")]
style: &'static str,
#[prop(default = "")]
id: &'static str,
) -> impl IntoView {
let full_style = format!("{} {}", base_content_style(), style);
view! {
<div
id=id
class=format!("card__content {}", class)
style=full_style
>
{children()}
</div>
}
}
#[component]
pub fn Footer(
children: Children,
#[prop(default = "")]
class: &'static str,
#[prop(default = "")]
style: &'static str,
#[prop(default = "")]
id: &'static str,
) -> impl IntoView {
let full_style = format!("{} {}", base_footer_style(), style);
view! {
<div
id=id
class=format!("card__footer {}", class)
style=full_style
>
{children()}
</div>
}
}