made a simple password visibility toggler

modified:   Cargo.lock
	modified:   Cargo.toml
	modified:   src/pages/signup.rs
	modified:   style/signup.scss
This commit is contained in:
Danny Zou 2024-02-23 20:31:25 -05:00
parent 5650882ba8
commit f4bea8aa33
4 changed files with 178 additions and 135 deletions

10
Cargo.lock generated
View File

@ -1296,11 +1296,21 @@ version = "0.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f41f2deec9249d16ef6b1a8442fbe16013f67053797052aa0b7d2f5ebd0f0098"
dependencies = [
"icondata_ai",
"icondata_bs",
"icondata_core",
"icondata_io",
]
[[package]]
name = "icondata_ai"
version = "0.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c8fe5fa2eed7715d5388e046d97f09d3baddd155b487454eb9cda3168c79d4b"
dependencies = [
"icondata_core",
]
[[package]]
name = "icondata_bs"
version = "0.0.8"

View File

@ -23,7 +23,9 @@ leptos_icons = { version = "0.1.0", default_features = false, features = [
"BsPauseFill",
"BsSkipStartFill",
"BsSkipEndFill",
"IoReturnUpBackSharp"
"IoReturnUpBackSharp",
"AiEyeFilled",
"AiEyeInvisibleFilled"
] }
dotenv = { version = "0.15.0", optional = true }
diesel = { version = "2.1.4", features = ["postgres", "r2d2"], optional = true }

View File

@ -1,10 +1,11 @@
use leptos::leptos_dom::*;
use leptos::*;
use leptos_icons::IoIcon::*;
use leptos_icons::*;
use crate::auth::signup;
use crate::models::User;
use leptos::ev::input;
use leptos::leptos_dom::*;
use leptos::*;
use leptos_icons::AiIcon::*;
use leptos_icons::IoIcon::*;
use leptos_icons::*;
#[component]
pub fn Signup() -> impl IntoView {
@ -12,6 +13,13 @@ pub fn Signup() -> impl IntoView {
let (email, set_email) = create_signal("".to_string());
let (password, set_password) = create_signal("".to_string());
let (show_password, set_show_password) = create_signal(false);
let toggle_password = move |_| {
set_show_password.update(|show_password| *show_password = !*show_password);
log!("showing password");
};
let on_submit = move |ev: leptos::ev::SubmitEvent| {
ev.prevent_default();
let new_user = User {
@ -63,7 +71,7 @@ pub fn Signup() -> impl IntoView {
<i></i>
</div>
<div class="input-box">
<input class="signup-password" type="text" required
<input class="signup-password" type={move || if show_password() { "text" } else { "password"} } required style="width: 90%;"
on:input = move |ev| {
set_password(event_target_value(&ev));
log!("password changed to: {}", password.get());
@ -71,6 +79,18 @@ pub fn Signup() -> impl IntoView {
/>
<span>Password</span>
<i></i>
<Show
when=move || {show_password() == false}
fallback=move || view!{ <button on:click=toggle_password class="password-visibility">
<Icon icon=Icon::from(AiEyeInvisibleFilled) />
</button> /> }
>
<button on:click=toggle_password class="password-visibility">
<Icon icon=Icon::from(AiEyeFilled) />
</button>
</Show>
</div>
<input type="submit" value="Sign Up" />
<span class="go-to-login">

View File

@ -1,4 +1,4 @@
@import 'theme.scss';
@import "theme.scss";
.signup-container {
display: flex;
@ -121,9 +121,20 @@
display: flex;
align-items: center;
justify-content: center;
padding: .3rem;
padding: 0.3rem;
}
.signup-container .return:hover {
background-color: rgba(0, 0, 0, 0.4);
}
.password-visibility {
position: absolute;
font-size: 1.7rem;
top: 28%;
right: 5px;
z-index: 5;
cursor: pointer;
border: none;
background-color: transparent;
color: white;
}