hyaenidae/toolkit/src/file_input.rs
asonix f008ca5fb9 Enable removing a file input's group div
Always style headings inside a card
Add vertical padding to paragraphs in a card
2021-01-06 23:38:52 -06:00

92 lines
2.4 KiB
Rust

use crate::ButtonKind;
#[derive(Debug, Default)]
pub struct FileInput {
pub(crate) name: String,
pub(crate) label: String,
pub(crate) id: String,
pub(crate) kind: ButtonKind,
pub(crate) accept: String,
pub(crate) classes: Vec<String>,
pub(crate) multiple: bool,
pub(crate) group: bool,
}
impl FileInput {
pub fn primary(name: &str, label: &str, id: &str) -> Self {
FileInput {
name: name.to_owned(),
label: label.to_owned(),
id: id.to_owned(),
group: true,
..Default::default()
}
}
pub fn primary_outline(name: &str, label: &str, id: &str) -> Self {
FileInput {
name: name.to_owned(),
label: label.to_owned(),
id: id.to_owned(),
kind: ButtonKind::PrimaryOutline,
group: true,
..Default::default()
}
}
pub fn outline(name: &str, label: &str, id: &str) -> Self {
FileInput {
name: name.to_owned(),
label: label.to_owned(),
id: id.to_owned(),
kind: ButtonKind::Outline,
group: true,
..Default::default()
}
}
pub fn secondary(name: &str, label: &str, id: &str) -> Self {
FileInput {
name: name.to_owned(),
label: label.to_owned(),
id: id.to_owned(),
kind: ButtonKind::Secondary,
group: true,
..Default::default()
}
}
pub fn multiple(&mut self) -> &mut Self {
self.multiple = true;
self
}
pub fn classes(&mut self, classes: &[&str]) -> &mut Self {
self.classes = classes.into_iter().map(|s| s.to_string()).collect();
self
}
pub fn accept(&mut self, accept: &str) -> &mut Self {
self.accept = accept.to_string();
self
}
pub fn no_group(&mut self) -> &mut Self {
self.group = false;
self
}
pub(crate) fn class_string(&self) -> String {
use ButtonKind::*;
let static_classes = match self.kind {
Primary => "toolkit-file toolkit-file__primary",
PrimaryOutline => "toolkit-file toolkit-file__primary-outline",
Outline => "toolkit-file toolkit-file__outline",
Secondary => "toolkit-file toolkit-file__secondary",
};
self.classes.join(" ") + " " + static_classes
}
}