#![doc = include_str!("../DIOXUS.md")]
use crate::common::{
Variant, base_card_style, base_content_style, base_description_style, base_footer_style,
base_header_style, base_title_style,
};
use dioxus::prelude::*;
#[derive(Props, Clone, PartialEq)]
pub struct CardProps {
#[props(default)]
pub children: Element,
#[props(default = Variant::Default)]
pub variant: Variant,
#[props(default)]
pub class: &'static str,
#[props(default)]
pub style: &'static str,
#[props(default)]
pub id: &'static str,
#[props(default = "article")]
pub role: &'static str,
#[props(default)]
pub aria_label: &'static str,
#[props(default)]
pub aria_labelledby: &'static str,
#[props(default)]
pub data_testid: &'static str,
}
#[component]
pub fn Card(props: CardProps) -> Element {
let variant_style = props.variant.to_style();
let user_style = props.style;
let effective_variant_style: String = if user_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,
user_style,
);
let card_class = format!("card {} {}", props.variant.to_class(), props.class);
rsx! {
div {
id: props.id,
class: "{card_class}",
style: "{full_style}",
role: props.role,
aria_label: props.aria_label,
aria_labelledby: props.aria_labelledby,
"data-testid": props.data_testid,
{props.children}
}
}
}
#[derive(Props, Clone, PartialEq)]
pub struct HeaderProps {
#[props(default)]
pub children: Element,
#[props(default)]
pub class: &'static str,
#[props(default)]
pub style: &'static str,
#[props(default)]
pub id: &'static str,
}
#[component]
pub fn Header(props: HeaderProps) -> Element {
let full_style = format!("{} {}", base_header_style(), props.style);
rsx! {
div {
id: props.id,
class: "card__header {props.class}",
style: "{full_style}",
{props.children}
}
}
}
#[derive(Props, Clone, PartialEq)]
pub struct TitleProps {
#[props(default)]
pub children: Element,
#[props(default)]
pub class: &'static str,
#[props(default)]
pub style: &'static str,
#[props(default)]
pub id: &'static str,
}
#[component]
pub fn Title(props: TitleProps) -> Element {
let full_style = format!("{} {}", base_title_style(), props.style);
rsx! {
h3 {
id: props.id,
class: "card__title {props.class}",
style: "{full_style}",
{props.children}
}
}
}
#[derive(Props, Clone, PartialEq)]
pub struct DescriptionProps {
#[props(default)]
pub children: Element,
#[props(default)]
pub class: &'static str,
#[props(default)]
pub style: &'static str,
#[props(default)]
pub id: &'static str,
}
#[component]
pub fn Description(props: DescriptionProps) -> Element {
let full_style = format!("{} {}", base_description_style(), props.style);
rsx! {
p {
id: props.id,
class: "card__description {props.class}",
style: "{full_style}",
{props.children}
}
}
}
#[derive(Props, Clone, PartialEq)]
pub struct ContentProps {
#[props(default)]
pub children: Element,
#[props(default)]
pub class: &'static str,
#[props(default)]
pub style: &'static str,
#[props(default)]
pub id: &'static str,
}
#[component]
pub fn Content(props: ContentProps) -> Element {
let full_style = format!("{} {}", base_content_style(), props.style);
rsx! {
div {
id: props.id,
class: "card__content {props.class}",
style: "{full_style}",
{props.children}
}
}
}
#[derive(Props, Clone, PartialEq)]
pub struct FooterProps {
#[props(default)]
pub children: Element,
#[props(default)]
pub class: &'static str,
#[props(default)]
pub style: &'static str,
#[props(default)]
pub id: &'static str,
}
#[component]
pub fn Footer(props: FooterProps) -> Element {
let full_style = format!("{} {}", base_footer_style(), props.style);
rsx! {
div {
id: props.id,
class: "card__footer {props.class}",
style: "{full_style}",
{props.children}
}
}
}