mirror of
https://github.com/adoyle0/thaw.git
synced 2025-02-02 08:34:15 -05:00
feat: Input component adds the suffix attribute
This commit is contained in:
parent
f2ed362782
commit
0279ace8d0
5 changed files with 46 additions and 1 deletions
|
@ -13,6 +13,11 @@ pub fn InputPage() -> impl IntoView {
|
||||||
<Space vertical=true>
|
<Space vertical=true>
|
||||||
<Input value/>
|
<Input value/>
|
||||||
<Input value variant=InputVariant::Password/>
|
<Input value variant=InputVariant::Password/>
|
||||||
|
<Input value>
|
||||||
|
<InputSuffix slot>
|
||||||
|
"$"
|
||||||
|
</InputSuffix>
|
||||||
|
</Input>
|
||||||
</Space>
|
</Space>
|
||||||
<DemoCode
|
<DemoCode
|
||||||
slot
|
slot
|
||||||
|
@ -23,6 +28,11 @@ pub fn InputPage() -> impl IntoView {
|
||||||
view! {
|
view! {
|
||||||
<Input value/>
|
<Input value/>
|
||||||
<Input value variant=InputVariant::Password />
|
<Input value variant=InputVariant::Password />
|
||||||
|
<Input value>
|
||||||
|
<InputSuffix slot>
|
||||||
|
"$"
|
||||||
|
</InputSuffix>
|
||||||
|
</Input>
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
"rust"
|
"rust"
|
||||||
|
|
|
@ -25,3 +25,10 @@
|
||||||
border: none;
|
border: none;
|
||||||
outline: none;
|
outline: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.melt-input__suffix {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
margin-left: 4px;
|
||||||
|
}
|
||||||
|
|
|
@ -23,6 +23,11 @@ impl InputVariant {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[slot]
|
||||||
|
pub struct InputSuffix {
|
||||||
|
children: Children,
|
||||||
|
}
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Input(
|
pub fn Input(
|
||||||
#[prop(optional, into)] value: MaybeRwSignal<String>,
|
#[prop(optional, into)] value: MaybeRwSignal<String>,
|
||||||
|
@ -31,6 +36,7 @@ pub fn Input(
|
||||||
#[prop(optional, into)] placeholder: MaybeSignal<String>,
|
#[prop(optional, into)] placeholder: MaybeSignal<String>,
|
||||||
#[prop(optional, into)] on_focus: Option<Callback<ev::FocusEvent>>,
|
#[prop(optional, into)] on_focus: Option<Callback<ev::FocusEvent>>,
|
||||||
#[prop(optional, into)] on_blur: Option<Callback<ev::FocusEvent>>,
|
#[prop(optional, into)] on_blur: Option<Callback<ev::FocusEvent>>,
|
||||||
|
#[prop(optional)] input_suffix: Option<InputSuffix>,
|
||||||
) -> impl IntoView {
|
) -> impl IntoView {
|
||||||
let theme = use_theme(Theme::light);
|
let theme = use_theme(Theme::light);
|
||||||
mount_style("input", include_str!("./input.css"));
|
mount_style("input", include_str!("./input.css"));
|
||||||
|
@ -65,7 +71,7 @@ pub fn Input(
|
||||||
css_vars
|
css_vars
|
||||||
});
|
});
|
||||||
view! {
|
view! {
|
||||||
<div class:melt-input=true style=move || css_vars.get()>
|
<div class="melt-input" style=move || css_vars.get()>
|
||||||
<input
|
<input
|
||||||
type=move || variant.get().as_str()
|
type=move || variant.get().as_str()
|
||||||
prop:value=move || value.get()
|
prop:value=move || value.get()
|
||||||
|
@ -75,6 +81,17 @@ pub fn Input(
|
||||||
class="melt-input__input-el"
|
class="melt-input__input-el"
|
||||||
placeholder=move || placeholder.get()
|
placeholder=move || placeholder.get()
|
||||||
/>
|
/>
|
||||||
|
{
|
||||||
|
if let Some(suffix) = input_suffix {
|
||||||
|
view! {
|
||||||
|
<div class="melt-input__suffix">
|
||||||
|
{(suffix.children)()}
|
||||||
|
</div>
|
||||||
|
}.into()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
9
src/input_number/mod.rs
Normal file
9
src/input_number/mod.rs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
use crate::Input;
|
||||||
|
use leptos::*;
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn InputNumber() -> impl IntoView {
|
||||||
|
view! {
|
||||||
|
<Input />
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,6 +13,7 @@ mod grid;
|
||||||
mod icon;
|
mod icon;
|
||||||
mod image;
|
mod image;
|
||||||
mod input;
|
mod input;
|
||||||
|
mod input_number;
|
||||||
mod layout;
|
mod layout;
|
||||||
mod menu;
|
mod menu;
|
||||||
pub mod mobile;
|
pub mod mobile;
|
||||||
|
@ -42,6 +43,7 @@ pub use grid::*;
|
||||||
pub use icon::*;
|
pub use icon::*;
|
||||||
pub use image::*;
|
pub use image::*;
|
||||||
pub use input::*;
|
pub use input::*;
|
||||||
|
pub use input_number::*;
|
||||||
pub use layout::*;
|
pub use layout::*;
|
||||||
pub use menu::*;
|
pub use menu::*;
|
||||||
pub use modal::*;
|
pub use modal::*;
|
||||||
|
|
Loading…
Add table
Reference in a new issue