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