Skip to main content

adam_web_ui/components/card/
component.rs

1//! Styled upstream card implementation; see `../UPSTREAM.md`.
2use dioxus::prelude::*;
3use dioxus_primitives::dioxus_attributes::attributes;
4use dioxus_primitives::merge_attributes;
5
6include!(concat!(env!("OUT_DIR"), "/card-styles.rs"));
7
8/// Renders the card surface, grouping its children inside a bordered, rounded container.
9///
10/// - Complexity: O(attributes + children) render work.
11///
12/// # Examples
13/// ```
14/// use adam_web_ui::components::card::{Card, CardContent};
15/// use dioxus::prelude::*;
16/// fn app() -> Element {
17///     rsx! { Card { CardContent { "Body" } } }
18/// }
19/// ```
20#[component]
21pub fn Card(
22    #[props(extends=GlobalAttributes)] attributes: Vec<Attribute>,
23    children: Element,
24) -> Element {
25    crate::components::styles::use_control_styles();
26    let base = attributes!(div {
27        class: Styles::dx_card,
28        "data-slot": "card",
29    });
30    let merged = merge_attributes(vec![base, attributes]);
31
32    rsx! {
33        div { ..merged, {children} }
34    }
35}
36
37/// Renders the card's header region, placing an optional [`CardAction`] in its own column.
38///
39/// - Complexity: O(attributes + children) render work.
40///
41/// # Examples
42/// ```
43/// use adam_web_ui::components::card::{CardHeader, CardTitle};
44/// use dioxus::prelude::*;
45/// fn app() -> Element {
46///     rsx! { CardHeader { CardTitle { "Title" } } }
47/// }
48/// ```
49#[component]
50pub fn CardHeader(
51    #[props(extends=GlobalAttributes)] attributes: Vec<Attribute>,
52    children: Element,
53) -> Element {
54    crate::components::styles::use_control_styles();
55    let base = attributes!(div {
56        class: Styles::dx_card_header,
57        "data-slot": "card-header",
58    });
59    let merged = merge_attributes(vec![base, attributes]);
60
61    rsx! {
62        div { ..merged, {children} }
63    }
64}
65
66/// Renders the card's title text with the official heading weight and line height.
67///
68/// - Complexity: O(attributes + children) render work.
69///
70/// # Examples
71/// ```
72/// use adam_web_ui::components::card::CardTitle;
73/// use dioxus::prelude::*;
74/// fn app() -> Element {
75///     rsx! { CardTitle { "Title" } }
76/// }
77/// ```
78#[component]
79pub fn CardTitle(
80    #[props(extends=GlobalAttributes)] attributes: Vec<Attribute>,
81    children: Element,
82) -> Element {
83    crate::components::styles::use_control_styles();
84    let base = attributes!(div {
85        class: Styles::dx_card_title,
86        "data-slot": "card-title",
87    });
88    let merged = merge_attributes(vec![base, attributes]);
89
90    rsx! {
91        div { ..merged, {children} }
92    }
93}
94
95/// Renders the card's secondary description text beneath its title.
96///
97/// - Complexity: O(attributes + children) render work.
98///
99/// # Examples
100/// ```
101/// use adam_web_ui::components::card::CardDescription;
102/// use dioxus::prelude::*;
103/// fn app() -> Element {
104///     rsx! { CardDescription { "Details" } }
105/// }
106/// ```
107#[component]
108pub fn CardDescription(
109    #[props(extends=GlobalAttributes)] attributes: Vec<Attribute>,
110    children: Element,
111) -> Element {
112    crate::components::styles::use_control_styles();
113    let base = attributes!(div {
114        class: Styles::dx_card_description,
115        "data-slot": "card-description",
116    });
117    let merged = merge_attributes(vec![base, attributes]);
118
119    rsx! {
120        div { ..merged, {children} }
121    }
122}
123
124/// Renders the card header's action slot, placed in the header's trailing column.
125///
126/// - Complexity: O(attributes + children) render work.
127///
128/// # Examples
129/// ```
130/// use adam_web_ui::components::card::{CardAction, CardHeader};
131/// use dioxus::prelude::*;
132/// fn app() -> Element {
133///     rsx! { CardHeader { CardAction { "Action" } } }
134/// }
135/// ```
136#[component]
137pub fn CardAction(
138    #[props(extends=GlobalAttributes)] attributes: Vec<Attribute>,
139    children: Element,
140) -> Element {
141    crate::components::styles::use_control_styles();
142    let base = attributes!(div {
143        class: Styles::dx_card_action,
144        "data-slot": "card-action",
145    });
146    let merged = merge_attributes(vec![base, attributes]);
147
148    rsx! {
149        div { ..merged, {children} }
150    }
151}
152
153/// Renders the card's main content region beneath its optional header.
154///
155/// - Complexity: O(attributes + children) render work.
156///
157/// # Examples
158/// ```
159/// use adam_web_ui::components::card::{Card, CardContent};
160/// use dioxus::prelude::*;
161/// fn app() -> Element {
162///     rsx! { Card { CardContent { "Body" } } }
163/// }
164/// ```
165#[component]
166pub fn CardContent(
167    #[props(extends=GlobalAttributes)] attributes: Vec<Attribute>,
168    children: Element,
169) -> Element {
170    crate::components::styles::use_control_styles();
171    let base = attributes!(div {
172        class: Styles::dx_card_content,
173        "data-slot": "card-content",
174    });
175    let merged = merge_attributes(vec![base, attributes]);
176
177    rsx! {
178        div { ..merged, {children} }
179    }
180}
181
182/// Renders the card's footer region beneath its content.
183///
184/// - Complexity: O(attributes + children) render work.
185///
186/// # Examples
187/// ```
188/// use adam_web_ui::components::card::{Card, CardFooter};
189/// use dioxus::prelude::*;
190/// fn app() -> Element {
191///     rsx! { Card { CardFooter { "Footer" } } }
192/// }
193/// ```
194#[component]
195pub fn CardFooter(
196    #[props(extends=GlobalAttributes)] attributes: Vec<Attribute>,
197    children: Element,
198) -> Element {
199    crate::components::styles::use_control_styles();
200    let base = attributes!(div {
201        class: Styles::dx_card_footer,
202        "data-slot": "card-footer",
203    });
204    let merged = merge_attributes(vec![base, attributes]);
205
206    rsx! {
207        div { ..merged, {children} }
208    }
209}