use leptos::{Signal, View}; use super::{Control, ControlBuilder, ControlData}; use crate::{ form::{FormBuilder, FormData}, styles::FormStyle, }; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct TextInputData { pub(crate) name: String, pub(crate) placeholder: Option, pub(crate) label: Option, pub(crate) initial_text: String, pub(crate) input_type: &'static str, } impl Default for TextInputData { fn default() -> Self { TextInputData { name: String::new(), placeholder: None, label: None, initial_text: String::new(), input_type: "input", } } } impl ControlData for TextInputData { type ReturnType = String; fn build_control( fs: &FS, control: Control, ) -> (View, Signal) { fs.text_input(control) } } impl FormBuilder { pub fn text_input( self, builder: impl Fn(ControlBuilder) -> Control, ) -> Self { self.new_control(builder) } } impl ControlBuilder { pub fn placeholder(mut self, placeholder: impl ToString) -> Self { self.data.placeholder = Some(placeholder.to_string()); self } pub fn label(mut self, label: impl ToString) -> Self { self.data.label = Some(label.to_string()); self } pub fn initial_text(mut self, text: impl ToString) -> Self { self.data.initial_text = text.to_string(); self } pub fn password(mut self) -> Self { self.data.input_type = "password"; self } }