82 lines
2.2 KiB
Rust
82 lines
2.2 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,
|
||
|
}
|
||
|
|
||
|
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(),
|
||
|
..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,
|
||
|
..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,
|
||
|
..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,
|
||
|
..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(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
|
||
|
}
|
||
|
}
|