use leptos::{Signal, View}; use super::{ControlBuilder, ControlData, ControlRenderData}; use crate::{ form::{FormBuilder, FormData}, styles::FormStyle, }; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] pub struct SelectData { pub(crate) name: String, pub(crate) options: Vec, } impl ControlData for SelectData { type ReturnType = String; fn build_control( fs: &FS, control: ControlRenderData, validation_state: Signal>, ) -> (View, Signal) { fs.select(control, validation_state) } } impl FormBuilder { pub fn select( self, builder: impl Fn( ControlBuilder, ) -> ControlBuilder, ) -> Self { self.new_control(builder) } } impl ControlBuilder { pub fn options(mut self, options: Vec) -> Self { self.data.options = options; self } pub fn and_option(mut self, option: impl ToString) -> Self { self.data.options.push(option.to_string()); self } }