From 5735b75528c2f729fd58fd94a4128b8c2b761b5a Mon Sep 17 00:00:00 2001 From: jamesxu1288 Date: Mon, 4 Mar 2024 23:03:11 -0800 Subject: [PATCH] Add password toggle on login form --- src/UI/UIWindowLogin.js | 21 +++++++++++++++++---- src/UI/UIWindowSignup.js | 1 + src/icons/eye-closed.svg | 1 + src/icons/eye-open.svg | 1 + 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 src/icons/eye-closed.svg create mode 100644 src/icons/eye-open.svg diff --git a/src/UI/UIWindowLogin.js b/src/UI/UIWindowLogin.js index 58ab4ed2..c7937884 100644 --- a/src/UI/UIWindowLogin.js +++ b/src/UI/UIWindowLogin.js @@ -26,6 +26,7 @@ async function UIWindowLogin(options){ options.reload_on_success = options.reload_on_success ?? false; options.has_head = options.has_head ?? true; options.send_confirmation_code = options.send_confirmation_code ?? false; + options.show_password = options.show_password ?? false; return new Promise(async (resolve) => { const internal_id = window.uuidv4(); @@ -45,10 +46,14 @@ async function UIWindowLogin(options){ h += ``; h += ``; h += ``; - // password - h += `
`; - h += ``; - h += ``; + // password with conditional type based based on options.show_password + h += `
`; + h += ``; + h += ``; + // show/hide icon + h += ` + + `; h += `
`; // login h += ``; @@ -183,6 +188,14 @@ async function UIWindowLogin(options){ if(signup) resolve(true); }) + + $(el_window).find(`#toggle-show-password-${internal_id}`).on("click", function (e) { + options.show_password = !options.show_password; + // hide/show password and update icon + $(el_window).find(".password").attr("type", options.show_password ? "text" : "password"); + $(el_window).find(".toggle-show-password-icon").attr("src", options.show_password ? window.icons["eye-closed.svg"] : window.icons["eye-open.svg"], + ) + }) }) } diff --git a/src/UI/UIWindowSignup.js b/src/UI/UIWindowSignup.js index c8a615d1..5c0e25c4 100644 --- a/src/UI/UIWindowSignup.js +++ b/src/UI/UIWindowSignup.js @@ -125,6 +125,7 @@ function UIWindowSignup(options){ window_options: options.window_options, show_close_button: options.show_close_button, send_confirmation_code: options.send_confirmation_code, + show_password: false, }); if(login) resolve(true); diff --git a/src/icons/eye-closed.svg b/src/icons/eye-closed.svg new file mode 100644 index 00000000..645e1735 --- /dev/null +++ b/src/icons/eye-closed.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/eye-open.svg b/src/icons/eye-open.svg new file mode 100644 index 00000000..2a2d14ac --- /dev/null +++ b/src/icons/eye-open.svg @@ -0,0 +1 @@ + \ No newline at end of file