From 00e42b94a62c3c32ab972e3d819c513574636c79 Mon Sep 17 00:00:00 2001 From: kandrelczyk Date: Mon, 4 Dec 2023 12:19:47 +0000 Subject: [PATCH] Add disabled and invalid statuses to input (#35) * Add disabled and invalid statuses to input * pref: input component theme and style --------- Co-authored-by: Cristobal Andrada Co-authored-by: luoxiao --- demo/src/pages/auto_complete/mod.rs | 38 ++++++++++++++++++++++++ demo/src/pages/button/mod.rs | 2 +- demo/src/pages/components.rs | 2 +- demo/src/pages/input/mod.rs | 46 ++++++++++++++++++++++++++++- demo/src/pages/input_number/mod.rs | 44 +++++++++++++++++++++++++++ src/auto_complete/mod.rs | 4 +++ src/input/input.css | 21 +++++++++++-- src/input/mod.rs | 21 +++++++++++++ src/input/theme.rs | 6 ++++ src/input_number/mod.rs | 14 +++++---- 10 files changed, 187 insertions(+), 11 deletions(-) diff --git a/demo/src/pages/auto_complete/mod.rs b/demo/src/pages/auto_complete/mod.rs index 4a5a70f..b712319 100644 --- a/demo/src/pages/auto_complete/mod.rs +++ b/demo/src/pages/auto_complete/mod.rs @@ -52,6 +52,32 @@ pub fn AutoCompletePage() -> impl IntoView { +

"disabled"

+ + + + {highlight_str!( + r#" + + "#, + "rust" + )} + + + +

"invalid"

+ + + + {highlight_str!( + r#" + + "#, + "rust" + )} + + +

"AutoComplete Props"

@@ -81,6 +107,18 @@ pub fn AutoCompletePage() -> impl IntoView { + + + + + + + + + + + + diff --git a/demo/src/pages/button/mod.rs b/demo/src/pages/button/mod.rs index 749892e..cb4394c 100644 --- a/demo/src/pages/button/mod.rs +++ b/demo/src/pages/button/mod.rs @@ -269,7 +269,7 @@ fn LoadingButton() -> impl IntoView { ); }; view! { -

"Loading"

+

"loading"

- + @@ -109,6 +141,18 @@ pub fn InputPage() -> impl IntoView { + + + + + + + + + + + + diff --git a/demo/src/pages/input_number/mod.rs b/demo/src/pages/input_number/mod.rs index 695229d..a882411 100644 --- a/demo/src/pages/input_number/mod.rs +++ b/demo/src/pages/input_number/mod.rs @@ -33,6 +33,38 @@ pub fn InputNumberPage() -> impl IntoView { +

"disabled"

+ + + + + + + {highlight_str!( + r#" + + "#, + "rust" + )} + + + +

"invalid"

+ + + + + + + {highlight_str!( + r#" + + "#, + "rust" + )} + + +

"InputNumber Props"

"Vec::new()" "Options to autocomplete from."
"disabled""MaybeSignal""false""Whether the input is disabled."
"invalid""MaybeSignal""false""Whether the input is invalid."
"clear_after_select" "MaybeSignal" "variant" "MaybeSignal" "InputVariant::Text""Button's variant.""Input's variant."
"placeholder""Default::default()" "Placeholder of input."
"disabled""MaybeSignal""false""Whether the input is disabled."
"invalid""MaybeSignal""false""Whether the input is invalid."
"allow_value" "Option>"
@@ -64,6 +96,18 @@ pub fn InputNumberPage() -> impl IntoView { "The number which the current value is increased or decreased on key or button press." + + + + + + + + + + + +
"disabled""MaybeSignal""false""Whether the input is disabled."
"invalid""MaybeSignal""false""Whether the input is invalid."

"T impl"

diff --git a/src/auto_complete/mod.rs b/src/auto_complete/mod.rs index 03ba43b..bea9313 100644 --- a/src/auto_complete/mod.rs +++ b/src/auto_complete/mod.rs @@ -22,6 +22,8 @@ pub fn AutoComplete( #[prop(optional, into)] options: MaybeSignal>, #[prop(optional, into)] clear_after_select: MaybeSignal, #[prop(optional, into)] on_select: Option>, + #[prop(optional, into)] disabled: MaybeSignal, + #[prop(optional, into)] invalid: MaybeSignal, ) -> impl IntoView { mount_style("auto-complete", include_str!("./auto-complete.css")); let theme = use_theme(Theme::light); @@ -111,6 +113,8 @@ pub fn AutoComplete( , #[prop(optional, into)] on_focus: Option>, #[prop(optional, into)] on_blur: Option>, + #[prop(optional, into)] disabled: MaybeSignal, + #[prop(optional, into)] invalid: MaybeSignal, #[prop(optional)] input_prefix: Option, #[prop(optional)] input_suffix: Option, ) -> impl IntoView { @@ -89,10 +91,26 @@ pub fn Input( "--thaw-border-color: {};", theme.input.border_color )); + css_vars.push_str(&format!( + "--thaw-border-color-error: {};", + theme.common.color_error + )); css_vars.push_str(&format!( "--thaw-placeholder-color: {};", theme.input.placeholder_color )); + css_vars.push_str(&format!( + "--thaw-background-color-disabled: {};", + theme.input.background_color_disabled + )); + css_vars.push_str(&format!( + "--thaw-font-color-disabled: {};", + theme.input.font_color_disabled + )); + css_vars.push_str(&format!( + "--thaw-box-shadow-color-invalid: {}33;", + theme.common.color_error + )); }); css_vars }); @@ -100,6 +118,8 @@ pub fn Input(
{if let Some(prefix) = input_prefix { @@ -119,6 +139,7 @@ pub fn Input( on:focus=on_internal_focus on:blur=on_internal_blur class="thaw-input__input-el" + disabled=move || disabled.get() placeholder=move || placeholder.get() /> diff --git a/src/input/theme.rs b/src/input/theme.rs index faae0e8..b53e4d9 100644 --- a/src/input/theme.rs +++ b/src/input/theme.rs @@ -6,6 +6,8 @@ pub struct InputTheme { pub placeholder_color: String, pub border_color: String, pub background_color: String, + pub font_color_disabled: String, + pub background_color_disabled: String, } impl ThemeMethod for InputTheme { @@ -15,6 +17,8 @@ impl ThemeMethod for InputTheme { placeholder_color: "#c2c2c2".into(), border_color: "#e0e0e6".into(), background_color: "#fff".into(), + font_color_disabled: "#c2c2c2".into(), + background_color_disabled: "#fafafc".into(), } } @@ -24,6 +28,8 @@ impl ThemeMethod for InputTheme { placeholder_color: "#c2c2c2".into(), border_color: "#0000".into(), background_color: "#ffffff1a".into(), + font_color_disabled: "#ffffff61".into(), + background_color_disabled: "#ffffff0f".into(), } } } diff --git a/src/input_number/mod.rs b/src/input_number/mod.rs index 31acd5f..0c32d61 100644 --- a/src/input_number/mod.rs +++ b/src/input_number/mod.rs @@ -9,6 +9,8 @@ pub fn InputNumber( #[prop(optional, into)] value: RwSignal, #[prop(optional, into)] placeholder: MaybeSignal, #[prop(into)] step: MaybeSignal, + #[prop(optional, into)] disabled: MaybeSignal, + #[prop(optional, into)] invalid: MaybeSignal, ) -> impl IntoView where T: Add + Sub, @@ -35,19 +37,21 @@ where }); let step: StoredMaybeSignal<_> = step.into(); - let add = Callback::::new(move |_| { + let add = Callback::::new(move |e: ev::MouseEvent| { + e.prevent_default(); value.set(value.get_untracked() + step.get_untracked()); }); - let sub = Callback::::new(move |_| { + let sub = Callback::::new(move |e: ev::MouseEvent| { + e.prevent_default(); value.set(value.get_untracked() - step.get_untracked()); }); view! { - + - -