2021-01-06 08:16:50 +00:00
|
|
|
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,
|
2021-01-07 05:38:52 +00:00
|
|
|
pub(crate) group: bool,
|
2021-01-09 04:32:02 +00:00
|
|
|
dark: bool,
|
2021-01-06 08:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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(),
|
2021-01-07 05:38:52 +00:00
|
|
|
group: true,
|
2021-01-06 08:16:50 +00:00
|
|
|
..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,
|
2021-01-07 05:38:52 +00:00
|
|
|
group: true,
|
2021-01-06 08:16:50 +00:00
|
|
|
..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,
|
2021-01-07 05:38:52 +00:00
|
|
|
group: true,
|
2021-01-06 08:16:50 +00:00
|
|
|
..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,
|
2021-01-07 05:38:52 +00:00
|
|
|
group: true,
|
2021-01-06 08:16:50 +00:00
|
|
|
..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
|
|
|
|
}
|
|
|
|
|
2021-01-07 05:38:52 +00:00
|
|
|
pub fn no_group(&mut self) -> &mut Self {
|
|
|
|
self.group = false;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-01-09 04:32:02 +00:00
|
|
|
pub fn dark(&mut self, dark: bool) -> &mut Self {
|
|
|
|
self.dark = dark;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-01-06 08:16:50 +00:00
|
|
|
pub(crate) fn class_string(&self) -> String {
|
|
|
|
use ButtonKind::*;
|
|
|
|
|
2021-01-09 04:32:02 +00:00
|
|
|
let mut classes = self.classes.clone();
|
|
|
|
|
2021-01-06 08:16:50 +00:00
|
|
|
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",
|
|
|
|
};
|
|
|
|
|
2021-01-09 04:32:02 +00:00
|
|
|
classes.push(static_classes.to_owned());
|
|
|
|
|
|
|
|
if self.dark {
|
|
|
|
classes.push("toolkit-dark".to_owned());
|
|
|
|
}
|
|
|
|
|
|
|
|
classes.join(" ")
|
2021-01-06 08:16:50 +00:00
|
|
|
}
|
|
|
|
}
|