fox-send/app/templates/setPasswordSection/index.js

43 lines
1.2 KiB
JavaScript
Raw Normal View History

const html = require('choo/html');
const passwordInput = require('../passwordInput');
2018-07-31 18:09:18 +00:00
module.exports = function(state) {
const checked = state.password ? 'checked' : '';
const label = state.password ? 'addPasswordLabel' : 'addPasswordMessage';
2018-02-16 20:56:53 +00:00
return html`
<div class="setPasswordSection">
<div class="checkbox">
<input
2018-07-31 18:09:18 +00:00
class="checkbox__input" id="add-password"
type="checkbox"
2018-07-31 18:09:18 +00:00
${checked}
autocomplete="off"
onchange=${togglePasswordInput}/>
<label class="checkbox__label" for="add-password">
2018-07-31 18:09:18 +00:00
${state.translate(label)}
</label>
</div>
2018-07-31 18:09:18 +00:00
${passwordInput(state)}
</div>`;
function togglePasswordInput(e) {
const unlockInput = document.getElementById('password-input');
const boxChecked = e.target.checked;
document
2018-02-21 20:35:52 +00:00
.querySelector('.passwordInput')
.classList.toggle('passwordInput--hidden', !boxChecked);
2018-07-31 18:09:18 +00:00
const label = document.querySelector('.checkbox__label');
if (boxChecked) {
2018-07-31 18:09:18 +00:00
label.innerHTML = state.translate('addPasswordLabel');
unlockInput.focus();
} else {
2018-07-31 18:09:18 +00:00
label.innerHTML = state.translate('addPasswordMessage');
unlockInput.value = '';
}
}
};