leptos_bootstrap/v5/
input.rs1use leptos::prelude::*;
2use std::fmt;
3
4#[component]
5pub fn FloatingLabel<'a>(
6 #[prop(optional, into)] label: &'a str,
7 #[prop(optional, into)] class: &'a str,
8 children: Children,
9) -> impl IntoView {
10 let class = format!("form-floating {}", class);
11 view! { <div class=class>{children()} <label>{label}</label></div> }
12}
13
14pub enum InputKind {
15 Text,
16 Email,
17 DateTimeLocal,
18 DateTime,
19 Number,
20 Password,
21}
22
23impl fmt::Display for InputKind {
24 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25 let s = match self {
26 Self::Text => "text",
27 Self::Email => "email",
28 Self::DateTimeLocal => "datetime-local",
29 Self::DateTime => "datetime",
30 Self::Number => "number",
31 Self::Password => "password",
32 };
33 write!(f, "{}", s)
34 }
35}
36
37#[component]
38pub fn Input<'a>(
39 value: RwSignal<String>,
40 #[prop(default = InputKind::Text)] kind: InputKind,
41 #[prop(optional, into)] placeholder: &'a str,
42 #[prop(optional, into)] class: &'a str,
43) -> impl IntoView {
44 let class = format!("form-control {}", class);
45 view! { <input type=kind.to_string() class=class placeholder=placeholder bind:value=value /> }
46}