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