windjammer_ui/components/generated/
chip.rs1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5pub enum ChipVariant {
6 Default,
7 Primary,
8 Success,
9 Warning,
10 Danger,
11 Info,
12}
13
14pub enum ChipSize {
15 Small,
16 Medium,
17 Large,
18}
19
20pub struct Chip {
21 label: String,
22 variant: ChipVariant,
23 size: ChipSize,
24 removable: bool,
25 icon: String,
26}
27
28impl Chip {
29 #[inline]
30 pub fn new(label: String) -> Chip {
31 Chip {
32 label,
33 variant: ChipVariant::Default,
34 size: ChipSize::Medium,
35 removable: false,
36 icon: String::new(),
37 }
38 }
39 #[inline]
40 pub fn variant(mut self, variant: ChipVariant) -> Chip {
41 self.variant = variant;
42 self
43 }
44 #[inline]
45 pub fn size(mut self, size: ChipSize) -> Chip {
46 self.size = size;
47 self
48 }
49 #[inline]
50 pub fn removable(mut self, removable: bool) -> Chip {
51 self.removable = removable;
52 self
53 }
54 #[inline]
55 pub fn icon(mut self, icon: String) -> Chip {
56 self.icon = icon;
57 self
58 }
59}
60
61impl Renderable for Chip {
62 fn render(self) -> String {
63 let bg_color = match self.variant {
64 ChipVariant::Default => "#e2e8f0",
65 ChipVariant::Primary => "#3b82f6",
66 ChipVariant::Success => "#10b981",
67 ChipVariant::Warning => "#f59e0b",
68 ChipVariant::Danger => "#ef4444",
69 ChipVariant::Info => "#06b6d4",
70 };
71 let text_color = match self.variant {
72 ChipVariant::Default => "#2d3748",
73 ChipVariant::Primary => "white",
74 ChipVariant::Success => "white",
75 ChipVariant::Warning => "white",
76 ChipVariant::Danger => "white",
77 ChipVariant::Info => "white",
78 };
79 let border_color = match self.variant {
80 ChipVariant::Default => "#cbd5e0",
81 ChipVariant::Primary => "#2563eb",
82 ChipVariant::Success => "#059669",
83 ChipVariant::Warning => "#d97706",
84 ChipVariant::Danger => "#dc2626",
85 ChipVariant::Info => "#0891b2",
86 };
87 let padding = match self.size {
88 ChipSize::Small => "4px 8px",
89 ChipSize::Medium => "6px 12px",
90 ChipSize::Large => "8px 16px",
91 };
92 let font_size = match self.size {
93 ChipSize::Small => "12px",
94 ChipSize::Medium => "14px",
95 ChipSize::Large => "16px",
96 };
97 let mut html = String::new();
98 html.push_str(
99 "<span style='display: inline-flex; align-items: center; gap: 6px; padding: ",
100 );
101 html.push_str(padding);
102 html.push_str("; font-size: ");
103 html.push_str(font_size);
104 html.push_str("; font-weight: 500; border-radius: 16px; background: ");
105 html.push_str(bg_color);
106 html.push_str("; color: ");
107 html.push_str(text_color);
108 html.push_str("; border: 1px solid ");
109 html.push_str(border_color);
110 html.push_str(";'>");
111 if self.icon.len() > 0 {
112 html.push_str("<span>");
113 html.push_str(&self.icon);
114 html.push_str("</span>")
115 }
116 html.push_str("<span>");
117 html.push_str(&self.label);
118 html.push_str("</span>");
119 if self.removable {
120 html.push_str("<button onclick='this.parentElement.remove()' style='background: none; border: none; cursor: pointer; padding: 0; margin: 0; display: flex; align-items: center; color: ");
121 html.push_str(text_color);
122 html.push_str("; opacity: 0.7; font-size: 18px; line-height: 1;' onmouseover='this.style.opacity=\"1\"' onmouseout='this.style.opacity=\"0.7\"'>×</button>")
123 }
124 html.push_str("</span>");
125 html
126 }
127}