hyaenidae/toolkit/src/card.rs

50 lines
1 KiB
Rust
Raw Normal View History

2020-12-16 02:40:41 +00:00
#[derive(Debug, Default)]
pub struct Card {
pub(crate) full_width: bool,
pub(crate) classes: Vec<String>,
2021-01-09 04:32:02 +00:00
dark: bool,
2020-12-16 02:40:41 +00:00
}
impl Card {
pub fn new() -> Self {
Default::default()
}
2020-12-16 21:43:43 +00:00
pub fn full_width() -> Self {
Card {
full_width: true,
..Default::default()
}
2020-12-16 02:40:41 +00:00
}
pub fn centered(mut self) -> Self {
2020-12-16 02:40:41 +00:00
self.classes.push("toolkit-centered".to_owned());
self
}
pub fn classes(mut self, classes: &[&str]) -> Self {
2020-12-16 02:40:41 +00:00
self.classes = classes.into_iter().map(|s| s.to_string()).collect();
self
}
pub fn dark(mut self, dark: bool) -> Self {
2021-01-09 04:32:02 +00:00
self.dark = dark;
self
}
2020-12-16 02:40:41 +00:00
pub(crate) fn class_string(&self) -> String {
2021-01-09 04:32:02 +00:00
let mut classes = self.classes.clone();
classes.push("toolkit-card".to_owned());
if self.dark {
classes.push("toolkit-dark".to_owned());
}
2020-12-16 02:40:41 +00:00
if self.full_width {
2021-01-09 04:32:02 +00:00
classes.push("toolkit-card__full-width".to_owned());
2020-12-16 02:40:41 +00:00
}
2021-01-09 04:32:02 +00:00
classes.join(" ")
2020-12-16 02:40:41 +00:00
}
}