77 lines
1.7 KiB
Rust
77 lines
1.7 KiB
Rust
use crate::{Input, InputKind};
|
|
|
|
#[derive(Debug, Default)]
|
|
pub struct TextInput {
|
|
pub(crate) input: Input,
|
|
pub(crate) title: Option<String>,
|
|
pub(crate) classes: Vec<String>,
|
|
pub(crate) error: Option<String>,
|
|
dark: bool,
|
|
}
|
|
|
|
impl TextInput {
|
|
pub fn new(name: &str) -> Self {
|
|
TextInput {
|
|
input: Input::new(name, InputKind::Text),
|
|
..Default::default()
|
|
}
|
|
}
|
|
|
|
pub fn password(&mut self) -> &mut Self {
|
|
self.input.kind(InputKind::Password);
|
|
self
|
|
}
|
|
|
|
pub fn textarea(&mut self) -> &mut Self {
|
|
self.input.kind(InputKind::TextArea);
|
|
self
|
|
}
|
|
|
|
pub fn title(&mut self, title: &str) -> &mut Self {
|
|
self.title = Some(title.to_owned());
|
|
self
|
|
}
|
|
|
|
pub fn value(&mut self, value: &str) -> &mut Self {
|
|
self.input.value(value);
|
|
self
|
|
}
|
|
|
|
pub fn placeholder(&mut self, placeholder: &str) -> &mut Self {
|
|
self.input.placeholder(placeholder);
|
|
self
|
|
}
|
|
|
|
pub fn classes(&mut self, classes: &[&str]) -> &mut Self {
|
|
self.classes = classes.into_iter().map(|s| s.to_string()).collect();
|
|
self
|
|
}
|
|
|
|
pub fn value_opt(&mut self, value: Option<String>) -> &mut Self {
|
|
self.input.value_opt(value);
|
|
self
|
|
}
|
|
|
|
pub fn error_opt(&mut self, error: Option<String>) -> &mut Self {
|
|
self.error = error;
|
|
self
|
|
}
|
|
|
|
pub fn dark(&mut self, dark: bool) -> &mut Self {
|
|
self.dark = dark;
|
|
self
|
|
}
|
|
|
|
pub(crate) fn class_string(&self) -> String {
|
|
let mut classes = self.classes.clone();
|
|
|
|
classes.push("toolkit-input".to_owned());
|
|
|
|
if self.dark {
|
|
classes.push("toolkit-dark".to_owned());
|
|
}
|
|
|
|
classes.join(" ")
|
|
}
|
|
}
|