windjammer_ui/components/generated/
toast.rs1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5#[derive(Clone, Debug, PartialEq, Copy)]
6pub enum ToastVariant {
7 Success,
8 Error,
9 Warning,
10 Info,
11}
12
13#[derive(Clone, Debug, PartialEq, Copy)]
14pub enum ToastPosition {
15 TopRight,
16 TopLeft,
17 BottomRight,
18 BottomLeft,
19 TopCenter,
20 BottomCenter,
21}
22
23#[derive(Debug, Clone, PartialEq)]
24pub struct Toast {
25 pub message: String,
26 pub variant: ToastVariant,
27 pub position: ToastPosition,
28 pub duration: i32,
29 pub show_close: bool,
30}
31
32impl Toast {
33 #[inline]
34 pub fn new(message: String) -> Toast {
35 Toast {
36 message,
37 variant: ToastVariant::Info,
38 position: ToastPosition::TopRight,
39 duration: 3000,
40 show_close: true,
41 }
42 }
43 #[inline]
44 pub fn variant(mut self, variant: ToastVariant) -> Toast {
45 self.variant = variant;
46 self
47 }
48 #[inline]
49 pub fn position(mut self, position: ToastPosition) -> Toast {
50 self.position = position;
51 self
52 }
53 #[inline]
54 pub fn duration(mut self, duration: i32) -> Toast {
55 self.duration = duration;
56 self
57 }
58 #[inline]
59 pub fn show_close(mut self, show: bool) -> Toast {
60 self.show_close = show;
61 self
62 }
63}
64
65impl Renderable for Toast {
66 #[inline]
67 fn render(self) -> String {
68 let variant_class = match self.variant {
69 ToastVariant::Success => "wj-toast-success".to_string(),
70 ToastVariant::Error => "wj-toast-error".to_string(),
71 ToastVariant::Warning => "wj-toast-warning".to_string(),
72 ToastVariant::Info => "wj-toast-info".to_string(),
73 };
74 let position_class = match self.position {
75 ToastPosition::TopRight => "wj-toast-top-right".to_string(),
76 ToastPosition::TopLeft => "wj-toast-top-left".to_string(),
77 ToastPosition::BottomRight => "wj-toast-bottom-right".to_string(),
78 ToastPosition::BottomLeft => "wj-toast-bottom-left".to_string(),
79 ToastPosition::TopCenter => "wj-toast-top-center".to_string(),
80 ToastPosition::BottomCenter => "wj-toast-bottom-center".to_string(),
81 };
82 let icon = match self.variant {
83 ToastVariant::Success => "✓".to_string(),
84 ToastVariant::Error => "✗".to_string(),
85 ToastVariant::Warning => "⚠".to_string(),
86 ToastVariant::Info => "ℹ".to_string(),
87 };
88 let close_button = {
89 if self.show_close {
90 "<button class='wj-toast-close'>×</button>".to_string()
91 } else {
92 "".to_string()
93 }
94 };
95 format!(
96 "<div class='wj-toast {} {}' data-duration='{}'>
97 <span class='wj-toast-icon'>{}</span>
98 <span class='wj-toast-message'>{}</span>
99 {}
100</div>",
101 variant_class, position_class, self.duration, icon, self.message, close_button
102 )
103 }
104}