impulse_thaw/input/
types.rs1use leptos::{html, prelude::*};
2
3#[slot]
4pub struct InputPrefix {
5 #[prop(default = true)]
6 if_: bool,
7 children: Children,
8}
9
10#[slot]
11pub struct InputSuffix {
12 #[prop(default = true)]
13 if_: bool,
14 children: Children,
15}
16
17#[derive(Default, Clone)]
18pub enum InputType {
19 #[default]
20 Text,
21 Password,
22 Search,
23 Tel,
24 Url,
25 Email,
26 Time,
27 Date,
28 DatetimeLocal,
29 Month,
30 Week,
31}
32
33impl InputType {
34 pub fn as_str(&self) -> &'static str {
35 match self {
36 Self::Text => "text",
37 Self::Password => "password",
38 Self::Search => "search",
39 Self::Tel => "tel",
40 Self::Url => "url",
41 Self::Email => "email",
42 Self::Time => "time",
43 Self::Date => "date",
44 Self::DatetimeLocal => "datetime-local",
45 Self::Month => "month",
46 Self::Week => "week",
47 }
48 }
49}
50
51#[derive(Clone)]
52pub struct InputRef {
53 pub(super) input_ref: NodeRef<html::Input>,
54}
55
56impl InputRef {
57 pub fn focus(&self) {
59 if let Some(input_el) = self.input_ref.get_untracked() {
60 _ = input_el.focus();
61 }
62 }
63
64 pub fn blur(&self) {
66 if let Some(input_el) = self.input_ref.get_untracked() {
67 _ = input_el.blur();
68 }
69 }
70
71 pub fn select(&self) {
73 if let Some(input_el) = self.input_ref.get_untracked() {
74 _ = input_el.select();
75 }
76 }
77}
78
79#[derive(Debug, Default, PartialEq, Clone, Copy)]
80pub enum InputSize {
81 Small,
82 #[default]
83 Medium,
84 Large,
85}
86
87impl InputSize {
88 pub fn as_str(&self) -> &'static str {
89 match self {
90 Self::Small => "small",
91 Self::Medium => "medium",
92 Self::Large => "large",
93 }
94 }
95}