1use dioxus::prelude::*;
4
5use crate::class::{Glass, compose};
6
7#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
9#[non_exhaustive]
10pub enum CardDensity {
11 #[default]
13 Comfortable,
14 Compact,
16 Spacious,
18}
19
20impl CardDensity {
21 pub fn as_str(self) -> &'static str {
23 match self {
24 Self::Comfortable => "comfortable",
25 Self::Compact => "compact",
26 Self::Spacious => "spacious",
27 }
28 }
29}
30
31#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
33#[non_exhaustive]
34pub enum CardVariant {
35 #[default]
37 Default,
38 Interactive,
40 Muted,
42 Unstyled,
44}
45
46impl CardVariant {
47 pub fn as_str(self) -> &'static str {
49 match self {
50 Self::Default => "default",
51 Self::Interactive => "interactive",
52 Self::Muted => "muted",
53 Self::Unstyled => "unstyled",
54 }
55 }
56}
57
58#[derive(Props, Clone, PartialEq)]
60pub struct CardProps {
61 #[props(default)]
63 pub density: CardDensity,
64 #[props(default)]
66 pub variant: CardVariant,
67 #[props(default, into)]
69 pub glass: Glass,
70 #[props(into)]
72 pub class: Option<String>,
73 #[props(extends = GlobalAttributes, extends = div)]
75 pub attributes: Vec<Attribute>,
76 pub children: Element,
78}
79
80#[component]
83pub fn Card(props: CardProps) -> Element {
84 let density = format!("ui-card--{}", props.density.as_str());
85 let glass_class = props.glass.class("ui-card");
86 let class = compose([
87 Some("ui-card"),
88 Some(density.as_str()),
89 (props.variant == CardVariant::Muted).then_some("ui-card--muted"),
90 (props.variant == CardVariant::Interactive).then_some("ui-card--interactive"),
91 (props.variant == CardVariant::Unstyled).then_some("ui-card--unstyled"),
92 glass_class.as_deref(),
93 props.class.as_deref(),
94 ]);
95
96 rsx! {
97 div {
98 class,
99 "data-density": props.density.as_str(),
100 "data-slot": "card",
101 "data-variant": props.variant.as_str(),
102 ..props.attributes,
103 {props.children}
104 }
105 }
106}
107
108#[derive(Props, Clone, PartialEq)]
110pub struct CardPartProps {
111 #[props(into)]
113 pub class: Option<String>,
114 #[props(extends = GlobalAttributes, extends = div)]
116 pub attributes: Vec<Attribute>,
117 pub children: Element,
119}
120
121fn card_part(base: &str, slot: &str, props: CardPartProps) -> Element {
122 let class = compose([Some(base), props.class.as_deref()]);
123
124 rsx! {
125 div { class, "data-slot": slot.to_string(), ..props.attributes, {props.children} }
126 }
127}
128
129#[component]
131pub fn CardHeader(props: CardPartProps) -> Element {
132 card_part("ui-card__header", "card-header", props)
133}
134
135#[component]
137pub fn CardTitle(props: CardPartProps) -> Element {
138 card_part("ui-card__title", "card-title", props)
139}
140
141#[component]
143pub fn CardDescription(props: CardPartProps) -> Element {
144 card_part("ui-card__description", "card-description", props)
145}
146
147#[component]
149pub fn CardContent(props: CardPartProps) -> Element {
150 card_part("ui-card__content", "card-content", props)
151}
152
153#[component]
155pub fn CardFooter(props: CardPartProps) -> Element {
156 card_part("ui-card__footer", "card-footer", props)
157}
158
159#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
161#[non_exhaustive]
162pub enum BadgeVariant {
163 #[default]
165 Default,
166 Secondary,
168 Outline,
170 Success,
172 Warning,
174 Destructive,
176 Info,
178}
179
180impl BadgeVariant {
181 pub fn as_str(self) -> &'static str {
183 match self {
184 Self::Default => "default",
185 Self::Secondary => "secondary",
186 Self::Outline => "outline",
187 Self::Success => "success",
188 Self::Warning => "warning",
189 Self::Destructive => "destructive",
190 Self::Info => "info",
191 }
192 }
193}
194
195#[derive(Props, Clone, PartialEq)]
197pub struct BadgeProps {
198 #[props(default)]
200 pub variant: BadgeVariant,
201 #[props(default)]
203 pub dot: bool,
204 #[props(into)]
206 pub class: Option<String>,
207 #[props(extends = GlobalAttributes, extends = span)]
209 pub attributes: Vec<Attribute>,
210 pub children: Element,
212}
213
214#[component]
216pub fn Badge(props: BadgeProps) -> Element {
217 let variant = format!("ui-badge--{}", props.variant.as_str());
218 let class = compose([
219 Some("ui-badge"),
220 Some(variant.as_str()),
221 props.class.as_deref(),
222 ]);
223
224 rsx! {
225 span {
226 class,
227 "data-variant": props.variant.as_str(),
228 ..props.attributes,
229 if props.dot {
230 span { aria_hidden: "true", class: "ui-status-dot" }
231 }
232 {props.children}
233 }
234 }
235}
236
237#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
239#[non_exhaustive]
240pub enum AlertVariant {
241 #[default]
243 Default,
244 Success,
246 Warning,
248 Destructive,
250}
251
252impl AlertVariant {
253 pub fn as_str(self) -> &'static str {
255 match self {
256 Self::Default => "default",
257 Self::Success => "success",
258 Self::Warning => "warning",
259 Self::Destructive => "destructive",
260 }
261 }
262}
263
264#[derive(Props, Clone, PartialEq)]
266pub struct AlertProps {
267 #[props(default)]
269 pub variant: AlertVariant,
270 #[props(default, into)]
272 pub glass: Glass,
273 #[props(into)]
275 pub class: Option<String>,
276 #[props(extends = GlobalAttributes, extends = aside)]
278 pub attributes: Vec<Attribute>,
279 pub children: Element,
281}
282
283#[component]
285pub fn Alert(props: AlertProps) -> Element {
286 let variant = (props.variant != AlertVariant::Default)
287 .then(|| format!("ui-alert--{}", props.variant.as_str()));
288 let glass = props.glass.class("ui-alert");
289 let class = compose([
290 Some("ui-alert"),
291 variant.as_deref(),
292 glass.as_deref(),
293 props.class.as_deref(),
294 ]);
295
296 rsx! {
297 aside {
298 class,
299 "data-variant": props.variant.as_str(),
300 ..props.attributes,
301 {props.children}
302 }
303 }
304}