windjammer_ui/components/generated/
alert.rs1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5#[derive(Clone, Debug, PartialEq, Copy)]
6pub enum AlertVariant {
7 Error,
8 Warning,
9 Info,
10 Success,
11}
12
13#[derive(Debug, Clone, PartialEq)]
14pub struct Alert {
15 pub message: String,
16 pub variant: AlertVariant,
17}
18
19impl Alert {
20 #[inline]
21 pub fn error(message: String) -> Alert {
22 Alert {
23 message,
24 variant: AlertVariant::Error,
25 }
26 }
27 #[inline]
28 pub fn warning(message: String) -> Alert {
29 Alert {
30 message,
31 variant: AlertVariant::Warning,
32 }
33 }
34 #[inline]
35 pub fn info(message: String) -> Alert {
36 Alert {
37 message,
38 variant: AlertVariant::Info,
39 }
40 }
41 #[inline]
42 pub fn success(message: String) -> Alert {
43 Alert {
44 message,
45 variant: AlertVariant::Success,
46 }
47 }
48}
49
50impl Renderable for Alert {
51 #[inline]
52 fn render(self) -> String {
53 let variant_class = match self.variant {
54 AlertVariant::Error => "wj-alert-error".to_string(),
55 AlertVariant::Warning => "wj-alert-warning".to_string(),
56 AlertVariant::Info => "wj-alert-info".to_string(),
57 AlertVariant::Success => "wj-alert-success".to_string(),
58 };
59 let icon = match self.variant {
60 AlertVariant::Error => "❌".to_string(),
61 AlertVariant::Warning => "⚠️".to_string(),
62 AlertVariant::Info => "ℹ️".to_string(),
63 AlertVariant::Success => "✅".to_string(),
64 };
65 format!(
66 "<div class='wj-alert {}'>{} {}</div>",
67 variant_class, icon, self.message
68 )
69 }
70}