Skip to content
Merged
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
13 changes: 13 additions & 0 deletions app/javascript/controllers/password_visibility_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Controller } from "@hotwired/stimulus";

export default class extends Controller {
static targets = ["password", "icon"];

toggle() {
const isPasswordVisible = this.passwordTarget.type === "text";

this.passwordTarget.type = isPasswordVisible ? "password" : "text";
this.iconTarget.classList.toggle("fa-eye", !isPasswordVisible);
this.iconTarget.classList.toggle("fa-eye-slash", isPasswordVisible);
}
}
23 changes: 21 additions & 2 deletions app/views/users/sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
<style>
.password-input-wrapper {
position: relative;
}

.toggle-password {
position: absolute;
right: 10px;
top: 70%;
transform: translateY(-50%);
cursor: pointer;
color: #999;
}
</style>
<%= render partial: "shared/flash" %>
<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="login-box">
Expand All @@ -11,8 +25,13 @@
<div class="form-inputs">
<%= f.input :email, autofocus: true %>
</div>
<div class="form-inputs">
<%= f.input :password, autofocus: true %>
<div class="form-inputs" data-controller="password-visibility">
<div class="password-input-wrapper">
<%= f.input :password, autofocus: true, input_html: { data: { password_visibility_target: 'password' } } %>
<span class="toggle-password">
<i class="fas fa-eye-slash" data-action="click->password-visibility#toggle" data-password-visibility-target="icon"></i>
</span>
</div>
</div>
<div class="col-12 text-center">
<%= f.button :submit, "Log in", class: "btn btn-primary btn-block" %>
Expand Down