cronixui 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,70 @@
1
+ use std::fmt;
2
+
3
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
4
+ pub enum ToastType {
5
+ Success,
6
+ Error,
7
+ Warning,
8
+ Info,
9
+ }
10
+
11
+ impl fmt::Display for ToastType {
12
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13
+ match self {
14
+ ToastType::Success => write!(f, "success"),
15
+ ToastType::Error => write!(f, "error"),
16
+ ToastType::Warning => write!(f, "warning"),
17
+ ToastType::Info => write!(f, "info"),
18
+ }
19
+ }
20
+ }
21
+
22
+ #[derive(Debug, Clone)]
23
+ pub struct Toast {
24
+ pub title: Option<String>,
25
+ pub message: String,
26
+ pub toast_type: ToastType,
27
+ pub duration: u32,
28
+ }
29
+
30
+ impl Toast {
31
+ pub fn show(message: impl Into<String>) -> Self {
32
+ Self {
33
+ title: None,
34
+ message: message.into(),
35
+ toast_type: ToastType::Info,
36
+ duration: 4000,
37
+ }
38
+ }
39
+
40
+ pub fn title(mut self, title: impl Into<String>) -> Self {
41
+ self.title = Some(title.into());
42
+ self
43
+ }
44
+
45
+ pub fn toast_type(mut self, toast_type: ToastType) -> Self {
46
+ self.toast_type = toast_type;
47
+ self
48
+ }
49
+
50
+ pub fn duration(mut self, duration: u32) -> Self {
51
+ self.duration = duration;
52
+ self
53
+ }
54
+
55
+ pub fn success(message: impl Into<String>) -> Self {
56
+ Self::show(message).toast_type(ToastType::Success)
57
+ }
58
+
59
+ pub fn error(message: impl Into<String>) -> Self {
60
+ Self::show(message).toast_type(ToastType::Error)
61
+ }
62
+
63
+ pub fn warning(message: impl Into<String>) -> Self {
64
+ Self::show(message).toast_type(ToastType::Warning)
65
+ }
66
+
67
+ pub fn info(message: impl Into<String>) -> Self {
68
+ Self::show(message).toast_type(ToastType::Info)
69
+ }
70
+ }
@@ -0,0 +1,27 @@
1
+ pub struct Toggle {
2
+ on: bool,
3
+ }
4
+
5
+ impl Toggle {
6
+ pub fn new() -> Self {
7
+ Self { on: false }
8
+ }
9
+
10
+ pub fn toggle(&mut self) {
11
+ self.on = !self.on;
12
+ }
13
+
14
+ pub fn is_on(&self) -> bool {
15
+ self.on
16
+ }
17
+
18
+ pub fn set_on(&mut self, value: bool) {
19
+ self.on = value;
20
+ }
21
+ }
22
+
23
+ impl Default for Toggle {
24
+ fn default() -> Self {
25
+ Self::new()
26
+ }
27
+ }
@@ -0,0 +1,2 @@
1
+ export { default as CronixUI } from './cronixui.js';
2
+ export * from './cronixui.js';
@@ -0,0 +1,2 @@
1
+ export { default as CronixUI } from './cronixui.js';
2
+ export * from './cronixui.js';