generated from mitchell/rust_template
42 lines
1.3 KiB
Rust
42 lines
1.3 KiB
Rust
use super::{ControlBuilder, ControlData, ControlRenderData};
|
|
use crate::{form::FormToolData, form_builder::FormBuilder, styles::FormStyle};
|
|
use leptos::{Signal, View};
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
|
pub struct TextAreaData {
|
|
pub(crate) name: String,
|
|
pub(crate) placeholder: Option<String>,
|
|
}
|
|
|
|
impl ControlData for TextAreaData {
|
|
type ReturnType = String;
|
|
|
|
fn build_control<FS: FormStyle>(
|
|
fs: &FS,
|
|
control: ControlRenderData<FS, Self>,
|
|
value_getter: Signal<Self::ReturnType>,
|
|
value_setter: Box<dyn Fn(Self::ReturnType)>,
|
|
validation_state: Signal<Result<(), String>>,
|
|
) -> View {
|
|
fs.text_area(control, value_getter, value_setter, validation_state)
|
|
}
|
|
}
|
|
|
|
impl<FD: FormToolData, FS: FormStyle> FormBuilder<FD, FS> {
|
|
pub fn text_area<FDT: Clone + PartialEq + 'static>(
|
|
self,
|
|
builder: impl Fn(
|
|
ControlBuilder<FD, FS, TextAreaData, FDT>,
|
|
) -> ControlBuilder<FD, FS, TextAreaData, FDT>,
|
|
) -> Self {
|
|
self.new_control(builder)
|
|
}
|
|
}
|
|
|
|
impl<FD: FormToolData, FS: FormStyle, FDT> ControlBuilder<FD, FS, TextAreaData, FDT> {
|
|
pub fn placeholder(mut self, placeholder: impl ToString) -> Self {
|
|
self.data.placeholder = Some(placeholder.to_string());
|
|
self
|
|
}
|
|
}
|