use leptos::{component, html, slot, view, Children, ChildrenFn, IntoView};
use crate::components::elevation::Elevation;
#[derive(Default, PartialEq)]
pub enum CardStyle {
#[default]
Elevated,
Filled,
Outlined,
}
impl CardStyle {
pub fn get_class_name(&self) -> String {
match self {
CardStyle::Elevated => "elevated",
CardStyle::Filled => "filled",
CardStyle::Outlined => "outlined",
}
.into()
}
}
#[component]
pub fn Card(
style: CardStyle,
#[prop(optional)] headline: Option<Headline>,
children: Children,
) -> impl IntoView {
let elevation = style.eq(&CardStyle::Elevated).then(|| Elevation());
let classes = format!("leptos-material-card {}", style.get_class_name());
let headline_view = headline.map(|value| {
view! { <div class="leptos-material-card-headline">{(value.children)()}</div> }
});
view! { <div class=classes>{elevation} {headline_view} {children()}</div> }
}
#[slot]
pub struct Headline {
children: ChildrenFn,
}