use serde::Serialize;
#[derive(Debug, Clone, PartialEq, Serialize)]
pub struct Confirm {
title: String,
message: String,
#[serde(skip_serializing_if = "Option::is_none")]
confirm_label: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
cancel_label: Option<String>,
#[serde(skip_serializing_if = "std::ops::Not::not")]
destructive: bool,
}
impl Confirm {
#[must_use]
pub fn new(title: impl Into<String>, message: impl Into<String>) -> Self {
Self { title: title.into(), message: message.into(), confirm_label: None, cancel_label: None, destructive: false }
}
#[must_use]
pub fn confirm_label(mut self, label: impl Into<String>) -> Self {
self.confirm_label = Some(label.into());
self
}
#[must_use]
pub fn cancel_label(mut self, label: impl Into<String>) -> Self {
self.cancel_label = Some(label.into());
self
}
#[must_use]
pub fn destructive(mut self) -> Self {
self.destructive = true;
self
}
pub(crate) fn to_input(&self) -> String {
serde_json::to_string(self).expect("serialize confirm")
}
}
#[derive(Debug, Clone, Default, PartialEq, Serialize)]
pub struct Picker {
#[serde(skip_serializing_if = "Option::is_none")]
title: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
confirm_label: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
cancel_label: Option<String>,
}
impl Picker {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn title(mut self, title: impl Into<String>) -> Self {
self.title = Some(title.into());
self
}
#[must_use]
pub fn confirm_label(mut self, label: impl Into<String>) -> Self {
self.confirm_label = Some(label.into());
self
}
#[must_use]
pub fn cancel_label(mut self, label: impl Into<String>) -> Self {
self.cancel_label = Some(label.into());
self
}
pub(crate) fn to_input(&self) -> String {
serde_json::to_string(self).expect("serialize picker")
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum SnackbarDuration {
#[default]
Short,
Long,
}
#[derive(Debug, Clone, PartialEq, Serialize)]
pub struct Snackbar {
text: String,
#[serde(skip_serializing_if = "Option::is_none")]
action_label: Option<String>,
duration: SnackbarDuration,
}
impl Snackbar {
#[must_use]
pub fn new(text: impl Into<String>) -> Self {
Self { text: text.into(), action_label: None, duration: SnackbarDuration::Short }
}
#[must_use]
pub fn action(mut self, label: impl Into<String>) -> Self {
self.action_label = Some(label.into());
self
}
#[must_use]
pub fn long(mut self) -> Self {
self.duration = SnackbarDuration::Long;
self
}
pub(crate) fn to_input(&self) -> String {
serde_json::to_string(self).expect("serialize snackbar")
}
}