use dioxus::prelude::*; #[derive(Copy, Clone, PartialEq, Default)] #[non_exhaustive] pub enum ButtonVariant { #[default] Primary, Secondary, Destructive, Outline, Ghost, } impl ButtonVariant { pub fn class(&self) -> &'static str { match self { ButtonVariant::Primary => "primary", ButtonVariant::Secondary => "secondary", ButtonVariant::Destructive => "destructive", ButtonVariant::Outline => "outline", ButtonVariant::Ghost => "ghost", } } } #[component] pub fn Button( #[props(default)] variant: ButtonVariant, #[props(extends=GlobalAttributes)] #[props(extends=button)] attributes: Vec, onclick: Option>, onmousedown: Option>, onmouseup: Option>, children: Element, ) -> Element { rsx! { document::Link { rel: "stylesheet", href: asset!("/assets/styling/button.css") } button { class: "button", "data-style": variant.class(), onclick: move |event| { if let Some(f) = &onclick { f.call(event); } }, onmousedown: move |event| { if let Some(f) = &onmousedown { f.call(event); } }, onmouseup: move |event| { if let Some(f) = &onmouseup { f.call(event); } }, ..attributes, {children} } } }