Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added my webblock of simple password toggle button #429

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/blocks/cck-simplePwToggle/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions src/blocks/cck-simplePwToggle/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge ,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Simple Password Toggle Visibility</title>
</head>
<link rel="stylesheet" href="style.css" />
<link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.3.0/css/all.min.css" rel="stylesheet" />

<body>
<div class="wrapper">
<div class="form-box">
<h1>Login Here</h1>
<div class="input-box">
<i class="fa-solid fa-envelope"></i>
<input type="email" placeholder="Email" />
</div>
<div class="input-box">
<i class="fa-solid fa-key"></i>
<input id="inp_pw" type="password" placeholder="Password" />
<span class="eye" onclick="toggleShowHide()">
<!-- toggle between "fa-eye-slash" & "fa-eye" class -->
<i class="fa-sharp fa-regular fa-eye"></i>
</span>
</div>
<button class="login-btn">LOGIN</button>
</div>
</div>
<span class="shout-out">
Photo by
<a
href="https://unsplash.com/@amgras?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">MarkoSun</a>
on
<a
href="https://unsplash.com/photos/-Mbs5_RHkNI?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>
</span>
<script src="index.js"></script>
</body>

</html>
26 changes: 26 additions & 0 deletions src/blocks/cck-simplePwToggle/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// βœ… this will work, acquire input node once script is loading, and the reference is not change even node attribute change
// const input_password = document.querySelector(`input[type="password"]`);

function toggleShowHide() {
// βœ… Acquire input node with id name, this works since id is fixed
const input_password = document.getElementById(`inp_pw`);
// β›” reference DOM node every click using type attribute will NOT work, as type will change after clicking
// const input_password = document.querySelector(`input[type="password"]`);

// Acquire the eye icon
const eyeIcon = document.getElementsByClassName("fa-regular")[0];

if (input_password.type === "password") {
input_password.type = "text";
input_password.focus();
//toggle between "fa-eye-slash" & "fa-eye" class
eyeIcon.classList.remove("fa-eye");
eyeIcon.classList.add("fa-eye-slash");
} else {
input_password.type = "password";
input_password.focus();
//toggle between "fa-eye-slash" & "fa-eye" class
eyeIcon.classList.remove("fa-eye-slash");
eyeIcon.classList.add("fa-eye");
}
}
5 changes: 5 additions & 0 deletions src/blocks/cck-simplePwToggle/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"block_name": "CCK visible password button",
"author_name": "CCK Sam",
"author_github_url": "https://github.com/ccksam/"
}
70 changes: 70 additions & 0 deletions src/blocks/cck-simplePwToggle/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
height: 100vh;
background-image: url("./assets/marko-sun--Mbs5_RHkNI-unsplash.jpg");
background-size: cover;
font-family: sans-serif;
padding: 12% 33%;
}
.form-box {
background: rgba(0, 0, 0, 0.8);
padding: 50px 0;
color: white;
box-shadow: 0 0 20px 2px rgba(0, 0, 0, 0.5);
}
h1 {
text-align: center;
margin-bottom: 40px;
}
.input-box {
width: 80%;
margin: 2rem auto;
padding: 10px 0 5px;
border-bottom: 1px solid white;
}
.input-box > input {
width: 87%;
border: none;
outline: none;
background-color: transparent;
color: white;
}
::placeholder {
color: #cccccc;
}
.fa-solid {
margin-right: 10px;
}
.eye {
position: absolute;
}
#hide {
display: none;
}
.login-btn {
display: block;
width: 80%;
margin: 40px auto 20px;
padding: 10px 0;
outline: none;
border: 1px solid white;
letter-spacing: 0.3em;
background-color: transparent;
color: white;
cursor: pointer;
font-size: 1rem;
}

.shout-out {
position: fixed;
bottom: 30px;
right: 10px;
color: white;
}
.shout-out a {
text-decoration: none;
}