autumn_plugin_vanilla/behaviors/
mod.rs1mod autosubmit;
9mod confirm;
10mod copy;
11mod count;
12mod dismiss;
13mod local_time;
14mod toggle;
15
16use std::fmt;
17
18use autumn_web::Markup;
19
20pub use autosubmit::AutoSubmit;
21pub use confirm::Confirm;
22pub use copy::CopyText;
23pub use count::{Count, CountMode, OutputSlot};
24pub use dismiss::Dismiss;
25pub use local_time::{LocalTime, TimeFormat};
26pub use toggle::Toggle;
27
28#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
38#[non_exhaustive]
39pub enum Behavior {
40 AutoSubmit,
42 Confirm,
44 Copy,
46 Count,
48 Dismiss,
50 LocalTime,
52 Toggle,
54}
55
56impl Behavior {
57 pub const ALL: &'static [Self] = &[
59 Self::AutoSubmit,
60 Self::Confirm,
61 Self::Copy,
62 Self::Count,
63 Self::Dismiss,
64 Self::LocalTime,
65 Self::Toggle,
66 ];
67
68 #[must_use]
70 pub const fn name(self) -> &'static str {
71 match self {
72 Self::AutoSubmit => "autosubmit",
73 Self::Confirm => "confirm",
74 Self::Copy => "copy",
75 Self::Count => "count",
76 Self::Dismiss => "dismiss",
77 Self::LocalTime => "local-time",
78 Self::Toggle => "toggle",
79 }
80 }
81}
82
83impl fmt::Display for Behavior {
84 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
85 f.write_str(self.name())
86 }
87}
88
89impl maud::Render for Behavior {
90 fn render_to(&self, buffer: &mut String) {
91 buffer.push_str(self.name());
93 }
94}
95
96fn marker(behavior: Behavior) -> (&'static str, String) {
98 ("data-vanilla", behavior.name().to_owned())
99}
100
101fn button(attributes: Vec<(&'static str, String)>, content: Markup) -> Markup {
103 let mut all = Vec::with_capacity(attributes.len() + 1);
104 all.push(("type", "button".to_owned()));
105 all.extend(attributes);
106 crate::markup::element("button", &all, content)
107}