Skip to content

Commit

Permalink
feat: add show password for input password
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-brtrd committed Jul 25, 2023
1 parent 78f5279 commit 8479096
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
1 change: 1 addition & 0 deletions assets/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import './js/headerFixed';
import './js/swiperArticle';
import './js/highlight';
import './js/rangeInput';
import './js/showPassword';
import Filter from './js/filter';
new Filter(document.querySelector('.js-filter'));

Expand Down
28 changes: 28 additions & 0 deletions assets/js/showPassword.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const inputsPassword = document.querySelectorAll('input[type="password"]');

if (inputsPassword) {
inputsPassword.forEach(input => {
const parent = document.createElement('div');
parent.classList.add('parent-password');

const icon = document.createElement('i');
icon.classList.add('bi', 'bi-eye-slash-fill', 'icon-password');

input.before(parent);
parent.append(input);
input.after(icon);

icon.addEventListener('click', e => {
const type = input.getAttribute('type') === 'password' ? 'text' : 'password';
input.setAttribute('type', type);

if (type === 'password') {
icon.classList.remove('bi-eye-fill');
icon.classList.add('bi-eye-slash-fill');
} else {
icon.classList.remove('bi-eye-slash-fill');
icon.classList.add('bi-eye-fill');
}
});
});
}
13 changes: 13 additions & 0 deletions assets/styles/_structure.scss
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,16 @@ pre {
width: 100%;
border-radius: $border-radius;
}

.parent-password {
position: relative;
}

.icon-password {
position: absolute;
top: 50%;
right: 1%;
transform: translate(-50%, -50%);
cursor: pointer;
color: $primary;
}
12 changes: 8 additions & 4 deletions templates/Security/login.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
{{ error.messageKey|trans(error.messageData, 'security') }}
</div>
{% endif %}
<label for="username" class="form-label">{{ 'form.user.fields.email.label'|trans(domain = 'forms') }}</label>
<input type="text" id="username" class="form-control" name="_username" placeholder="{{ 'form.user.fields.email.placeholder'|trans(domain = 'forms') }}" value="{{ lastUsername }}"/>
<div class="mb-3">
<label for="username" class="form-label">{{ 'form.user.fields.email.label'|trans(domain = 'forms') }}</label>
<input type="text" id="username" class="form-control" name="_username" placeholder="{{ 'form.user.fields.email.placeholder'|trans(domain = 'forms') }}" value="{{ lastUsername }}"/>
</div>

<label for="password" class="form-label">{{ 'form.user.fields.password.main'|trans(domain = 'forms') }}</label>
<input type="password" id="password" class="form-control" placeholder="{{ 'form.user.fields.password.placeholder'|trans(domain = 'forms') }}" name="_password"/>
<div class="mb-3">
<label for="password" class="form-label">{{ 'form.user.fields.password.main'|trans(domain = 'forms') }}</label>
<input type="password" id="password" class="form-control" placeholder="{{ 'form.user.fields.password.placeholder'|trans(domain = 'forms') }}" name="_password"/>
</div>

<div class="d-grid gap-2 d-md-block mt-4 text-center">
<button type="submit" class="btn btn-primary">{{ 'main.btn.login'|trans(domain = 'content') }}</button>
Expand Down

0 comments on commit 8479096

Please sign in to comment.