windjammer_ui/components/generated/
button.rs

1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4use super::traits::RenderableVNode;
5use super::vnode::VNode;
6
7#[derive(Clone, Debug, PartialEq, Copy)]
8pub enum ButtonVariant {
9    Primary,
10    Secondary,
11    Success,
12    Danger,
13    Warning,
14    Ghost,
15}
16
17#[derive(Clone, Debug, PartialEq, Copy)]
18pub enum ButtonSize {
19    Small,
20    Medium,
21    Large,
22}
23
24#[derive(Debug, Clone, PartialEq)]
25pub struct Button {
26    pub label: String,
27    pub variant: ButtonVariant,
28    pub size: ButtonSize,
29    pub disabled: bool,
30}
31
32impl Button {
33    #[inline]
34    pub fn new(label: String) -> Button {
35        Button {
36            label,
37            variant: ButtonVariant::Primary,
38            size: ButtonSize::Medium,
39            disabled: false,
40        }
41    }
42    #[inline]
43    pub fn variant(mut self, variant: ButtonVariant) -> Button {
44        self.variant = variant;
45        self
46    }
47    #[inline]
48    pub fn size(mut self, size: ButtonSize) -> Button {
49        self.size = size;
50        self
51    }
52    #[inline]
53    pub fn disabled(mut self, disabled: bool) -> Button {
54        self.disabled = disabled;
55        self
56    }
57    #[inline]
58    pub fn get_variant_class(&self) -> String {
59        match self.variant {
60            ButtonVariant::Primary => "wj-button-primary".to_string(),
61            ButtonVariant::Secondary => "wj-button-secondary".to_string(),
62            ButtonVariant::Success => "wj-button-success".to_string(),
63            ButtonVariant::Danger => "wj-button-danger".to_string(),
64            ButtonVariant::Warning => "wj-button-warning".to_string(),
65            ButtonVariant::Ghost => "wj-button-ghost".to_string(),
66        }
67    }
68    #[inline]
69    pub fn get_size_class(&self) -> String {
70        match self.size {
71            ButtonSize::Small => "wj-button-sm".to_string(),
72            ButtonSize::Medium => "wj-button-md".to_string(),
73            ButtonSize::Large => "wj-button-lg".to_string(),
74        }
75    }
76    #[inline]
77    pub fn get_style(&self) -> String {
78        let base = "border: none; border-radius: 4px; cursor: pointer; font-weight: 500; transition: all 0.2s;".to_string();
79        let size_style = match self.size {
80            ButtonSize::Small => " padding: 4px 8px; font-size: 12px;".to_string(),
81            ButtonSize::Medium => " padding: 8px 16px; font-size: 14px;".to_string(),
82            ButtonSize::Large => " padding: 12px 24px; font-size: 16px;".to_string(),
83        };
84        let variant_style = match self.variant {
85            ButtonVariant::Primary => " background: #4A9EFF; color: white;".to_string(),
86            ButtonVariant::Secondary => {
87                " background: #333; color: #e0e0e0; border: 1px solid #555;".to_string()
88            }
89            ButtonVariant::Success => " background: #44AA44; color: white;".to_string(),
90            ButtonVariant::Danger => " background: #FF4444; color: white;".to_string(),
91            ButtonVariant::Warning => " background: #FFAA44; color: white;".to_string(),
92            ButtonVariant::Ghost => " background: transparent; color: #4A9EFF;".to_string(),
93        };
94        let disabled_style = {
95            if self.disabled {
96                " opacity: 0.5; cursor: not-allowed;".to_string()
97            } else {
98                "".to_string()
99            }
100        };
101        format!("{}{}{}{}", base, size_style, variant_style, disabled_style)
102    }
103}
104
105impl RenderableVNode for Button {
106    #[inline]
107    fn to_vnode(&self) -> VNode {
108        VNode::button()
109            .add_class("wj-button".to_string())
110            .add_class(self.get_variant_class())
111            .add_class(self.get_size_class())
112            .add_style(self.get_style())
113            .set_disabled(self.disabled)
114            .add_text(self.label.clone())
115    }
116}
117
118impl Renderable for Button {
119    #[inline]
120    fn render(self) -> String {
121        let variant_class = match self.variant {
122            ButtonVariant::Primary => "wj-button-primary".to_string(),
123            ButtonVariant::Secondary => "wj-button-secondary".to_string(),
124            ButtonVariant::Success => "wj-button-success".to_string(),
125            ButtonVariant::Danger => "wj-button-danger".to_string(),
126            ButtonVariant::Warning => "wj-button-warning".to_string(),
127            ButtonVariant::Ghost => "wj-button-ghost".to_string(),
128        };
129        let size_class = match self.size {
130            ButtonSize::Small => "wj-button-sm".to_string(),
131            ButtonSize::Medium => "wj-button-md".to_string(),
132            ButtonSize::Large => "wj-button-lg".to_string(),
133        };
134        let disabled_attr = {
135            if self.disabled {
136                " disabled='true'".to_string()
137            } else {
138                "".to_string()
139            }
140        };
141        format!(
142            "<button class='wj-button {} {}' style='{}'{}>{}</button>",
143            variant_class,
144            size_class,
145            self.get_style(),
146            disabled_attr,
147            self.label
148        )
149    }
150}