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