diff --git a/src/common/form_schema.rs b/src/common/form_schema.rs index 5ebd963..8655c94 100644 --- a/src/common/form_schema.rs +++ b/src/common/form_schema.rs @@ -1,18 +1,120 @@ +use std::collections::HashMap; +use leptos::{view, IntoView}; +use leptos::either::EitherOf5; +use leptos::prelude::RwSignal; use serde::{Serialize, Deserialize}; +use crate::components::{CheckboxList, OutlinedTextField, RadioList, Row, Select, ValueType}; /// Defines a series of options that allow a user to define a form. #[derive(Serialize, Deserialize, Clone, Debug)] pub enum InputType{ - /// Represents a text input. Requires a `String` key. The entered value will be returned as a - /// single `String` value. - Text, - /// Represents a number input. Requires a `String` key. The entered value will be returned as a - /// single `i32` value. - Number, - /// Represents a radio input. Requires a `String` key and a series of options. The selected - /// value will be returned as a single `String` value. - Radio(Vec), - /// Represents a checkbox input. Requires a `String` key and a series of options. The selected - /// value will be returned as a `Vec`. - Checkbox(Vec) + /// Represents a text input. Requires a `String` key, `String` label, and `String` placeholder. + /// The entered value will be returned as a single `String` value. + Text(String, String, String), + /// Represents a number input. Requires a `String` key, `String` label, and a `String` placeholder. + /// The entered value will be returned as a `String`, and will be parseable into any number type + /// (i.e. an `i32`, `i64`, etc) + Number(String, String, String), + /// Represents a radio input. Requires a `String` key, `String` label, and a series of `String` + /// options. The selected value will be returned as a `String`. + Radio(String, String, Vec), + /// Represents a checkbox input. Requires a `String` key, `String` label, and a series of `String` + /// options. The selected values will be returned as a `Vec`. + Checkbox(String, String, Vec), + /// Represents a dropdown input. Requires a `String` key, `String` label, and a series + /// of `String` options. The selected value will be returned as a `String`. + Select(String, String, Vec) +} + +impl InputType { + pub fn into_view(self, data_map: RwSignal>) -> impl IntoView { + view! { + {match self { + InputType::Text(member, label, placeholder) => + EitherOf5::A(view! { + + + + }), + InputType::Number(member, label, placeholder) => + EitherOf5::B(view! { + + }), + InputType::Checkbox(member, label, options) => + EitherOf5::C(view! { + + }), + InputType::Radio(member, label, options) => + EitherOf5::D(view! { + + }), + InputType::Select(member, label, options) => + EitherOf5::E(view! { +