1use serde::Serialize;
8
9#[derive(Debug, Clone, PartialEq, Serialize)]
13pub struct Confirm {
14 title: String,
15 message: String,
16 #[serde(skip_serializing_if = "Option::is_none")]
17 confirm_label: Option<String>,
18 #[serde(skip_serializing_if = "Option::is_none")]
19 cancel_label: Option<String>,
20 #[serde(skip_serializing_if = "std::ops::Not::not")]
21 destructive: bool,
22}
23
24impl Confirm {
25 #[must_use]
26 pub fn new(title: impl Into<String>, message: impl Into<String>) -> Self {
27 Self { title: title.into(), message: message.into(), confirm_label: None, cancel_label: None, destructive: false }
28 }
29
30 #[must_use]
32 pub fn confirm_label(mut self, label: impl Into<String>) -> Self {
33 self.confirm_label = Some(label.into());
34 self
35 }
36
37 #[must_use]
39 pub fn cancel_label(mut self, label: impl Into<String>) -> Self {
40 self.cancel_label = Some(label.into());
41 self
42 }
43
44 #[must_use]
46 pub fn destructive(mut self) -> Self {
47 self.destructive = true;
48 self
49 }
50
51 pub(crate) fn to_input(&self) -> String {
52 serde_json::to_string(self).expect("serialize confirm")
53 }
54}
55
56#[derive(Debug, Clone, Default, PartialEq, Serialize)]
59pub struct Picker {
60 #[serde(skip_serializing_if = "Option::is_none")]
61 title: Option<String>,
62 #[serde(skip_serializing_if = "Option::is_none")]
63 confirm_label: Option<String>,
64 #[serde(skip_serializing_if = "Option::is_none")]
65 cancel_label: Option<String>,
66}
67
68impl Picker {
69 #[must_use]
70 pub fn new() -> Self {
71 Self::default()
72 }
73
74 #[must_use]
78 pub fn title(mut self, title: impl Into<String>) -> Self {
79 self.title = Some(title.into());
80 self
81 }
82
83 #[must_use]
85 pub fn confirm_label(mut self, label: impl Into<String>) -> Self {
86 self.confirm_label = Some(label.into());
87 self
88 }
89
90 #[must_use]
92 pub fn cancel_label(mut self, label: impl Into<String>) -> Self {
93 self.cancel_label = Some(label.into());
94 self
95 }
96
97 pub(crate) fn to_input(&self) -> String {
98 serde_json::to_string(self).expect("serialize picker")
99 }
100}
101
102#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize)]
104#[serde(rename_all = "lowercase")]
105pub enum SnackbarDuration {
106 #[default]
107 Short,
108 Long,
109}
110
111#[derive(Debug, Clone, PartialEq, Serialize)]
114pub struct Snackbar {
115 text: String,
116 #[serde(skip_serializing_if = "Option::is_none")]
117 action_label: Option<String>,
118 duration: SnackbarDuration,
119}
120
121impl Snackbar {
122 #[must_use]
123 pub fn new(text: impl Into<String>) -> Self {
124 Self { text: text.into(), action_label: None, duration: SnackbarDuration::Short }
125 }
126
127 #[must_use]
129 pub fn action(mut self, label: impl Into<String>) -> Self {
130 self.action_label = Some(label.into());
131 self
132 }
133
134 #[must_use]
136 pub fn long(mut self) -> Self {
137 self.duration = SnackbarDuration::Long;
138 self
139 }
140
141 pub(crate) fn to_input(&self) -> String {
142 serde_json::to_string(self).expect("serialize snackbar")
143 }
144}