This repository has been archived on 2024-08-06. You can view files and clone it, but cannot push or open issues or pull requests.
leptos_form_tool/src/controls/text_area.rs
2024-03-15 21:12:19 -05:00

42 lines
1.1 KiB
Rust

use leptos::View;
use crate::{ControlBuilder, ControlData, FormBuilder, FormData, FormStyleProvider};
pub struct TextAreaData {
pub(crate) name: String,
pub(crate) placeholder: Option<String>,
}
impl TextAreaData {
fn new(name: String) -> Self {
TextAreaData {
name,
placeholder: None,
}
}
}
impl<FS: FormStyleProvider> ControlData<FS> for TextAreaData {
fn build_control(self, fs: &FS, attributes: Vec<FS::StylingAttributes>) -> View {
fs.text_area(self, attributes)
}
}
impl<FD: FormData, FS: FormStyleProvider> FormBuilder<FD, FS> {
pub fn text_area(self, name: impl ToString) -> ControlBuilder<FD, FS, TextAreaData> {
ControlBuilder {
fb: self,
parse_fn: None,
style_attributes: Vec::new(),
data: TextAreaData::new(name.to_string()),
}
}
}
impl<FD: FormData, FS: FormStyleProvider> ControlBuilder<FD, FS, TextAreaData> {
pub fn placeholder(mut self, placeholder: impl ToString) -> Self {
self.data.placeholder = Some(placeholder.to_string());
self
}
}