feat: change input type

This commit is contained in:
luoxiao 2023-06-19 21:53:39 +08:00
parent 164e495265
commit 317905d0f4
4 changed files with 27 additions and 9 deletions

View file

@ -8,7 +8,7 @@ pub fn InputPage(cx: Scope) -> impl IntoView {
<> <>
{move || value.get()} {move || value.get()}
<Input value/> <Input value/>
<Input value type_="password" /> <Input value type_=InputType::PASSWORD />
</> </>
} }
} }

View file

@ -8,7 +8,7 @@ pub fn InputPage(cx: Scope) -> impl IntoView {
<> <>
{move || value.get()} {move || value.get()}
<Input value/> <Input value/>
<Input value type_="password" /> <Input value type_=InputType::PASSWORD />
</> </>
} }
} }

View file

@ -5,10 +5,12 @@ use melt_ui::*;
pub fn MenuPage(cx: Scope) -> impl IntoView { pub fn MenuPage(cx: Scope) -> impl IntoView {
let selected = create_rw_signal(cx, String::from("o")); let selected = create_rw_signal(cx, String::from("o"));
view! { cx, view! { cx,
<div>
{ move || selected.get() } { move || selected.get() }
<Menu selected> <Menu selected>
<MenuItem key="a" label="and"/> <MenuItem key="a" label="and"/>
<MenuItem key="o" label="or"/> <MenuItem key="o" label="or"/>
</Menu> </Menu>
</div>
} }
} }

View file

@ -7,11 +7,27 @@ use leptos::*;
use stylers::style_sheet_str; use stylers::style_sheet_str;
pub use theme::InputTheme; pub use theme::InputTheme;
#[derive(Default, Clone)]
pub enum InputType {
#[default]
TEXT,
PASSWORD,
}
impl InputType {
pub fn as_str(&self) -> &'static str {
match self {
InputType::TEXT => "text",
InputType::PASSWORD => "password",
}
}
}
#[component] #[component]
pub fn Input( pub fn Input(
cx: Scope, cx: Scope,
#[prop(into)] value: RwSignal<String>, #[prop(into)] value: RwSignal<String>,
#[prop(default = MaybeSignal::Static(String::from("text")), into)] type_: MaybeSignal<String>, #[prop(optional, into)] type_: MaybeSignal<InputType>,
) -> impl IntoView { ) -> impl IntoView {
let theme = use_theme(cx, Theme::light); let theme = use_theme(cx, Theme::light);
let class_name = mount_style("input", || style_sheet_str!("./src/input/input.css")); let class_name = mount_style("input", || style_sheet_str!("./src/input/input.css"));
@ -35,7 +51,7 @@ pub fn Input(
view! { view! {
cx, class=class_name, cx, class=class_name,
<div class:melt-input=true style=move || css_vars.get()> <div class:melt-input=true style=move || css_vars.get()>
<input type=move || type_.get() prop:value=move || value.get() ref=input_ref class="melt-input__input-el"/> <input type=move || type_.get().as_str() prop:value=move || value.get() ref=input_ref class="melt-input__input-el"/>
</div> </div>
} }
} }