use crate::common::ValueType; use crate::components::{CheckboxList, OutlinedTextField, RadioList, Row, Select, TextFieldType}; use leptos::prelude::*; use serde::{Deserialize, Serialize}; use std::collections::HashMap; /// 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, `String` label, and `String` placeholder. /// The entered value will be returned as a single `String` value. Text(String, String, String, bool), /// 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, bool), /// 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, bool), /// 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, bool), /// 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, bool), } impl InputType { /// Converts an `InputType` into an `impl IntoView`. A name must be specified in the case that /// the component is a checkbox/radio list, which requires a unique name to function properly. /// Many times, the name will be the same as the data member. pub fn into_view( self, data_map: RwSignal>, name: String, ) -> impl IntoView { view! { {match self { InputType::Text(member, label, placeholder, required) => view! { }.into_any(), InputType::Number(member, label, placeholder, required) => view! { }.into_any(), InputType::Checkbox(member, label, options, required) => view! { }.into_any(), InputType::Radio(member, label, options, required) => view! { }.into_any(), InputType::Select(member, label, options, required) => view! {