2018-02-13 19:32:59 +00:00
|
|
|
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`
|
2018-02-13 19:32:59 +00:00
|
|
|
<div class="setPasswordSection">
|
|
|
|
<div class="checkbox">
|
|
|
|
<input
|
2018-07-31 18:09:18 +00:00
|
|
|
class="checkbox__input" id="add-password"
|
2018-02-13 19:32:59 +00:00
|
|
|
type="checkbox"
|
2018-07-31 18:09:18 +00:00
|
|
|
${checked}
|
2018-02-13 19:32:59 +00:00
|
|
|
autocomplete="off"
|
|
|
|
onchange=${togglePasswordInput}/>
|
|
|
|
<label class="checkbox__label" for="add-password">
|
2018-07-31 18:09:18 +00:00
|
|
|
${state.translate(label)}
|
2018-02-13 19:32:59 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
2018-07-31 18:09:18 +00:00
|
|
|
|
|
|
|
${passwordInput(state)}
|
|
|
|
|
2018-02-13 19:32:59 +00:00
|
|
|
</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')
|
2018-02-13 19:32:59 +00:00
|
|
|
.classList.toggle('passwordInput--hidden', !boxChecked);
|
2018-07-31 18:09:18 +00:00
|
|
|
|
|
|
|
const label = document.querySelector('.checkbox__label');
|
2018-02-13 19:32:59 +00:00
|
|
|
if (boxChecked) {
|
2018-07-31 18:09:18 +00:00
|
|
|
label.innerHTML = state.translate('addPasswordLabel');
|
2018-02-13 19:32:59 +00:00
|
|
|
unlockInput.focus();
|
|
|
|
} else {
|
2018-07-31 18:09:18 +00:00
|
|
|
label.innerHTML = state.translate('addPasswordMessage');
|
2018-02-13 19:32:59 +00:00
|
|
|
unlockInput.value = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|