windjammer_ui/components/generated/
button.rs1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5pub enum ButtonVariant {
6 Primary,
7 Secondary,
8 Success,
9 Danger,
10 Ghost,
11}
12
13pub enum ButtonSize {
14 Small,
15 Medium,
16 Large,
17}
18
19pub struct Button {
20 label: String,
21 variant: ButtonVariant,
22 size: ButtonSize,
23 disabled: bool,
24}
25
26impl Button {
27 #[inline]
28 pub fn new(label: String) -> Button {
29 Button {
30 label,
31 variant: ButtonVariant::Primary,
32 size: ButtonSize::Medium,
33 disabled: false,
34 }
35 }
36 #[inline]
37 pub fn variant(mut self, variant: ButtonVariant) -> Button {
38 self.variant = variant;
39 self
40 }
41 #[inline]
42 pub fn size(mut self, size: ButtonSize) -> Button {
43 self.size = size;
44 self
45 }
46 #[inline]
47 pub fn disabled(mut self, disabled: bool) -> Button {
48 self.disabled = disabled;
49 self
50 }
51}
52
53impl Renderable for Button {
54 #[inline]
55 fn render(self) -> String {
56 let variant_class = match self.variant {
57 ButtonVariant::Primary => "wj-button-primary",
58 ButtonVariant::Secondary => "wj-button-secondary",
59 ButtonVariant::Success => "wj-button-success",
60 ButtonVariant::Danger => "wj-button-danger",
61 ButtonVariant::Ghost => "wj-button-ghost",
62 };
63 let size_class = match self.size {
64 ButtonSize::Small => "wj-button-sm",
65 ButtonSize::Medium => "wj-button-md",
66 ButtonSize::Large => "wj-button-lg",
67 };
68 let disabled_attr = {
69 if self.disabled {
70 " disabled='true'"
71 } else {
72 ""
73 }
74 };
75 format!(
76 "<button class='wj-button {} {}'{}>{}</button>",
77 variant_class, size_class, disabled_attr, self.label
78 )
79 }
80}