From 58e0cc1365b6af4ecf6997ec624b746152605eb7 Mon Sep 17 00:00:00 2001 From: luoxiao Date: Thu, 16 Nov 2023 20:25:22 +0800 Subject: [PATCH] feat: input component add prefix slot --- demo/Cargo.toml | 1 + demo/src/pages/input/mod.rs | 66 ++++++++++++++++++++++++++++++++----- src/input/input.css | 7 ++++ src/input/mod.rs | 11 +++++++ 4 files changed, 77 insertions(+), 8 deletions(-) diff --git a/demo/Cargo.toml b/demo/Cargo.toml index a69f90c..7f34678 100644 --- a/demo/Cargo.toml +++ b/demo/Cargo.toml @@ -16,6 +16,7 @@ icondata = { version = "0.1.0", features = [ "AiCloseOutlined", "AiCheckOutlined", "AiGithubOutlined", + "AiUserOutlined", ] } prisms = { git = "https://github.com/luoxiaozero/prisms", rev = "16d4d34b93fc20578ebf03137d54ecc7eafa4d4b" } diff --git a/demo/src/pages/input/mod.rs b/demo/src/pages/input/mod.rs index 83cffaf..cf2dfd9 100644 --- a/demo/src/pages/input/mod.rs +++ b/demo/src/pages/input/mod.rs @@ -13,11 +13,46 @@ pub fn InputPage() -> impl IntoView { + + + + + + } + "#, + "rust" + ) + > + + "" + "" + + +

"Prefix & Suffix"

+ + + + + + + "$" + + + + + impl IntoView { let value = create_rw_signal(String::from("o")); view! { - - - - - "$" - - + + + + + + + + + "$" + + + + + + + + } "#, "rust" @@ -102,10 +147,15 @@ pub fn InputPage() -> impl IntoView { + + "InputPrefix" + "None" + "InputPrefix content." + "InputSuffix" "None" - "Input content." + "InputSuffix content." diff --git a/src/input/input.css b/src/input/input.css index 5d4edd6..7c6cd64 100644 --- a/src/input/input.css +++ b/src/input/input.css @@ -36,6 +36,13 @@ color: var(--thaw-placeholder-color); } +.thaw-input__prefix { + display: inline-flex; + align-items: center; + justify-content: center; + margin-right: 4px; +} + .thaw-input__suffix { display: inline-flex; align-items: center; diff --git a/src/input/mod.rs b/src/input/mod.rs index eda84f2..d91396e 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -23,6 +23,11 @@ impl InputVariant { } } +#[slot] +pub struct InputPrefix { + children: Children, +} + #[slot] pub struct InputSuffix { children: Children, @@ -36,6 +41,7 @@ pub fn Input( #[prop(optional, into)] placeholder: MaybeSignal, #[prop(optional, into)] on_focus: Option>, #[prop(optional, into)] on_blur: Option>, + #[prop(optional)] input_prefix: Option, #[prop(optional)] input_suffix: Option, ) -> impl IntoView { let theme = use_theme(Theme::light); @@ -92,6 +98,11 @@ pub fn Input( }); view! {
+ {if let Some(prefix) = input_prefix { + view! {
{(prefix.children)()}
}.into() + } else { + None + }}