81 lines
1.9 KiB
Rust
81 lines
1.9 KiB
Rust
|
|
use dioxus::prelude::*;
|
||
|
|
use dioxus_icons::lucide::BadgeCheck;
|
||
|
|
|
||
|
|
#[css_module("/src/components/badge/style.css")]
|
||
|
|
struct Styles;
|
||
|
|
|
||
|
|
// Variants beyond the ones this app currently uses are part of the
|
||
|
|
// component library's public API, not unused code — CI runs clippy with
|
||
|
|
// `-D warnings`, which would otherwise turn this dead_code lint into a
|
||
|
|
// build failure.
|
||
|
|
#[allow(dead_code)]
|
||
|
|
#[derive(Copy, Clone, PartialEq, Default)]
|
||
|
|
#[non_exhaustive]
|
||
|
|
pub enum BadgeVariant {
|
||
|
|
#[default]
|
||
|
|
Primary,
|
||
|
|
Secondary,
|
||
|
|
Destructive,
|
||
|
|
Outline,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl BadgeVariant {
|
||
|
|
#[allow(dead_code)]
|
||
|
|
pub fn class(&self) -> &'static str {
|
||
|
|
match self {
|
||
|
|
BadgeVariant::Primary => "primary",
|
||
|
|
BadgeVariant::Secondary => "secondary",
|
||
|
|
BadgeVariant::Destructive => "destructive",
|
||
|
|
BadgeVariant::Outline => "outline",
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// The props for the [`Badge`] component.
|
||
|
|
#[derive(Props, Clone, PartialEq)]
|
||
|
|
pub struct BadgeProps {
|
||
|
|
#[props(default)]
|
||
|
|
pub variant: BadgeVariant,
|
||
|
|
|
||
|
|
/// Additional attributes to extend the badge element
|
||
|
|
#[props(extends = GlobalAttributes)]
|
||
|
|
pub attributes: Vec<Attribute>,
|
||
|
|
|
||
|
|
/// The children of the badge element
|
||
|
|
pub children: Element,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[component]
|
||
|
|
pub fn Badge(props: BadgeProps) -> Element {
|
||
|
|
rsx! {
|
||
|
|
BadgeElement {
|
||
|
|
"padding": true,
|
||
|
|
variant: props.variant,
|
||
|
|
attributes: props.attributes,
|
||
|
|
{props.children}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#[component]
|
||
|
|
fn BadgeElement(props: BadgeProps) -> Element {
|
||
|
|
rsx! {
|
||
|
|
span {
|
||
|
|
class: Styles::dx_badge,
|
||
|
|
"data-style": props.variant.class(),
|
||
|
|
..props.attributes,
|
||
|
|
{props.children}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#[component]
|
||
|
|
pub fn VerifiedIcon() -> Element {
|
||
|
|
rsx! {
|
||
|
|
BadgeCheck {
|
||
|
|
size: "12px",
|
||
|
|
stroke: "var(--secondary-color-4)",
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|