use dioxus::prelude::*;
use crate::class::{Glass, compose};
#[derive(Props, Clone, PartialEq)]
pub struct EyebrowProps {
#[props(into)]
pub class: Option<String>,
#[props(extends = GlobalAttributes, extends = p)]
pub attributes: Vec<Attribute>,
pub children: Element,
}
#[component]
pub fn Eyebrow(props: EyebrowProps) -> Element {
let class = compose([Some("ui-eyebrow"), props.class.as_deref()]);
rsx! {
p { class, ..props.attributes, {props.children} }
}
}
#[derive(Props, Clone, PartialEq)]
pub struct FloatingBadgeProps {
#[props(into)]
pub class: Option<String>,
#[props(extends = GlobalAttributes, extends = span)]
pub attributes: Vec<Attribute>,
pub children: Element,
}
#[component]
pub fn FloatingBadge(props: FloatingBadgeProps) -> Element {
let class = compose([Some("ui-floating-badge"), props.class.as_deref()]);
rsx! {
span { class, ..props.attributes, {props.children} }
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub enum ItemElement {
#[default]
Div,
Article,
Li,
Section,
}
#[derive(Props, Clone, PartialEq)]
pub struct ItemProps {
#[props(default)]
pub r#as: ItemElement,
#[props(default, into)]
pub glass: Glass,
#[props(into)]
pub class: Option<String>,
#[props(extends = GlobalAttributes)]
pub attributes: Vec<Attribute>,
pub children: Element,
}
#[component]
pub fn Item(props: ItemProps) -> Element {
let glass = props.glass.class("ui-item");
let class = compose([Some("ui-item"), glass.as_deref(), props.class.as_deref()]);
match props.r#as {
ItemElement::Div => rsx! {
div { class, "data-slot": "item", ..props.attributes, {props.children} }
},
ItemElement::Article => rsx! {
article { class, "data-slot": "item", ..props.attributes, {props.children} }
},
ItemElement::Li => rsx! {
li { class, "data-slot": "item", ..props.attributes, {props.children} }
},
ItemElement::Section => rsx! {
section { class, "data-slot": "item", ..props.attributes, {props.children} }
},
}
}
#[derive(Props, Clone, PartialEq)]
pub struct KbdProps {
#[props(into)]
pub class: Option<String>,
#[props(extends = GlobalAttributes, extends = kbd)]
pub attributes: Vec<Attribute>,
pub children: Element,
}
#[component]
pub fn Kbd(props: KbdProps) -> Element {
let class = compose([Some("ui-kbd"), props.class.as_deref()]);
rsx! {
kbd { class, ..props.attributes, {props.children} }
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub enum MarkerVariant {
#[default]
Default,
Success,
Warning,
Danger,
}
impl MarkerVariant {
pub fn as_str(self) -> &'static str {
match self {
Self::Default => "default",
Self::Success => "success",
Self::Warning => "warning",
Self::Danger => "danger",
}
}
}
#[derive(Props, Clone, PartialEq)]
pub struct MarkerProps {
#[props(default)]
pub variant: MarkerVariant,
#[props(into)]
pub class: Option<String>,
#[props(extends = GlobalAttributes, extends = span)]
pub attributes: Vec<Attribute>,
pub children: Element,
}
#[component]
pub fn Marker(props: MarkerProps) -> Element {
let variant = (props.variant != MarkerVariant::Default)
.then(|| format!("ui-marker--{}", props.variant.as_str()));
let class = compose([
Some("ui-marker"),
variant.as_deref(),
props.class.as_deref(),
]);
rsx! {
span {
class,
"data-variant": props.variant.as_str(),
..props.attributes,
{props.children}
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub enum NoteBorderPosition {
#[default]
Left,
Right,
None,
}
impl NoteBorderPosition {
pub fn as_str(self) -> &'static str {
match self {
Self::Left => "left",
Self::Right => "right",
Self::None => "none",
}
}
}
#[derive(Props, Clone, PartialEq)]
pub struct NoteProps {
#[props(into)]
pub label: Option<String>,
#[props(default)]
pub border_position: NoteBorderPosition,
#[props(into)]
pub class: Option<String>,
#[props(extends = GlobalAttributes, extends = div)]
pub attributes: Vec<Attribute>,
pub children: Element,
}
#[component]
pub fn Note(props: NoteProps) -> Element {
let border = format!("ui-note--border-{}", props.border_position.as_str());
let class = compose([
Some("ui-note"),
Some(border.as_str()),
props.class.as_deref(),
]);
let label = props.label.filter(|label| !label.is_empty());
rsx! {
div { class, ..props.attributes,
if let Some(label) = label {
p { class: "ui-note__label", {label} }
}
div { class: "ui-note__content", {props.children} }
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub enum PillVariant {
#[default]
Neutral,
Brand,
Outline,
}
impl PillVariant {
pub fn as_str(self) -> &'static str {
match self {
Self::Neutral => "neutral",
Self::Brand => "brand",
Self::Outline => "outline",
}
}
}
#[derive(Props, Clone, PartialEq)]
pub struct PillProps {
#[props(default)]
pub variant: PillVariant,
#[props(into)]
pub count: Option<String>,
#[props(into)]
pub href: Option<String>,
#[props(into)]
pub class: Option<String>,
#[props(extends = GlobalAttributes)]
pub attributes: Vec<Attribute>,
pub children: Element,
}
#[component]
pub fn Pill(props: PillProps) -> Element {
let variant = (props.variant != PillVariant::Neutral)
.then(|| format!("ui-pill--{}", props.variant.as_str()));
let class = compose([Some("ui-pill"), variant.as_deref(), props.class.as_deref()]);
let content = rsx! {
{props.children}
if let Some(count) = props.count {
span { class: "ui-pill__count", {count} }
}
};
if let Some(href) = props.href {
rsx! {
a {
class,
"data-variant": props.variant.as_str(),
href,
..props.attributes,
{content}
}
}
} else {
rsx! {
span {
class,
"data-variant": props.variant.as_str(),
..props.attributes,
{content}
}
}
}
}
#[derive(Props, Clone, PartialEq)]
pub struct TypographyProps {
#[props(into)]
pub class: Option<String>,
#[props(extends = GlobalAttributes, extends = div)]
pub attributes: Vec<Attribute>,
pub children: Element,
}
#[component]
pub fn Typography(props: TypographyProps) -> Element {
let class = compose([Some("ui-typography"), props.class.as_deref()]);
rsx! {
div { class, ..props.attributes, {props.children} }
}
}