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