Skip to main content

ui_storybook/components/primitives/
card.rs

1//! Card — surface container with optional header + body slots.
2//!
3//! Mirrors rust-ui's `<Card>` / `<CardHeader>` / `<CardContent>` composition
4//! pattern (we use `CardBody` for the content slot to keep the prop name
5//! short).
6
7use leptos::prelude::*;
8
9#[component]
10pub fn Card(children: Children) -> impl IntoView {
11    view! {
12        <div class="card">
13            {children()}
14        </div>
15    }
16}
17
18#[component]
19pub fn CardHeader(
20    #[prop(into)] title: String,
21    #[prop(optional, into)] subtitle: String,
22) -> impl IntoView {
23    let has_subtitle = !subtitle.is_empty();
24    view! {
25        <div class="card-header">
26            <div class="card-title">{title}</div>
27            <Show when=move || has_subtitle>
28                <div class="card-subtitle">{subtitle.clone()}</div>
29            </Show>
30        </div>
31    }
32}
33
34#[component]
35pub fn CardBody(children: Children) -> impl IntoView {
36    view! {
37        <div class="card-body">
38            {children()}
39        </div>
40    }
41}