use controls::{ heading::HeadingData, select::SelectData, submit::SubmitData, text_area::TextAreaData, text_input::TextInputData, }; use leptos::*; use std::marker::PhantomData; mod controls; mod provider_impl; pub trait FormStyleProvider { type StylingAttributes; fn heading(&self, data: HeadingData, attributes: Vec) -> View; fn text_input(&self, data: TextInputData, attributes: Vec) -> View; fn select(&self, data: SelectData, attributes: Vec) -> View; fn submit(&self, data: SubmitData, attributes: Vec) -> View; fn text_area(&self, data: TextAreaData, attributes: Vec) -> View; fn custom_component(&self, component: View) -> View; // TODO: add group } pub trait ControlData: 'static { fn build_control(self, fs: &FS, attributes: Vec) -> View; } pub struct FormBuilder { _fd: PhantomData, fs: FS, controls: Vec<(Box>, Vec)>, } pub trait FormData {} pub struct ControlBuilder> { fb: FormBuilder, parse_fn: Option>, style_attributes: Vec, data: C, } impl> ControlBuilder { pub fn parse_fn(mut self, parse_fn: Box) -> Self { self.parse_fn = Some(parse_fn); self } pub fn style(mut self, attribute: FS::StylingAttributes) -> Self { self.style_attributes.push(attribute); self } pub fn end(mut self) -> FormBuilder { self.fb .controls .push((Box::new(self.data), self.style_attributes)); self.fb } }