Archived
generated from mitchell/rust_template
control flow
This commit is contained in:
+19
-11
@@ -1,29 +1,37 @@
|
||||
use super::{BuilderFn, ControlBuilder, ControlData, ControlRenderData};
|
||||
use super::{
|
||||
BuilderFn, ControlRenderData, GetterVanityControlData, VanityControlBuilder, VanityControlData,
|
||||
};
|
||||
use crate::{form::FormToolData, form_builder::FormBuilder, styles::FormStyle};
|
||||
use leptos::{Signal, View};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||
pub struct HiddenData;
|
||||
|
||||
impl ControlData for HiddenData {
|
||||
type ReturnType = String;
|
||||
pub struct HiddenData {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
impl VanityControlData for HiddenData {
|
||||
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>>,
|
||||
value_getter: Option<Signal<String>>,
|
||||
) -> View {
|
||||
fs.hidden(control, value_getter)
|
||||
}
|
||||
}
|
||||
impl GetterVanityControlData for HiddenData {}
|
||||
|
||||
impl<FD: FormToolData> FormBuilder<FD> {
|
||||
pub fn hidden<FDT: Clone + PartialEq + 'static>(
|
||||
pub fn hidden(
|
||||
self,
|
||||
builder: impl BuilderFn<ControlBuilder<FD, HiddenData, FDT>, FD::Context>,
|
||||
builder: impl BuilderFn<VanityControlBuilder<FD, HiddenData>, FD::Context>,
|
||||
) -> Self {
|
||||
self.new_control(builder)
|
||||
self.new_vanity(builder)
|
||||
}
|
||||
}
|
||||
|
||||
impl<FD: FormToolData> VanityControlBuilder<FD, HiddenData> {
|
||||
pub fn named(mut self, control_name: impl ToString) -> Self {
|
||||
self.data.name = control_name.to_string();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user