forked from mozilla/send
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
beb3a6e
commit 7b4060f
Showing
22 changed files
with
1,159 additions
and
453 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const html = require('choo/html'); | ||
|
||
module.exports = function(selected, options, translate, changed) { | ||
const id = `select-${Math.random()}`; | ||
let x = selected; | ||
|
||
function close() { | ||
const ul = document.getElementById(id); | ||
const body = document.querySelector('body'); | ||
ul.classList.remove('active'); | ||
body.removeEventListener('click', close); | ||
} | ||
|
||
function toggle(event) { | ||
event.stopPropagation(); | ||
const ul = document.getElementById(id); | ||
if (ul.classList.contains('active')) { | ||
close(); | ||
} else { | ||
ul.classList.add('active'); | ||
const body = document.querySelector('body'); | ||
body.addEventListener('click', close); | ||
} | ||
} | ||
|
||
function choose(event) { | ||
event.stopPropagation(); | ||
const target = event.target; | ||
const value = +target.dataset.value; | ||
target.parentNode.previousSibling.firstElementChild.textContent = translate( | ||
value | ||
); | ||
if (x !== value) { | ||
x = value; | ||
changed(value); | ||
} | ||
close(); | ||
} | ||
return html` | ||
<div class="selectbox"> | ||
<div onclick=${toggle}> | ||
<span class="link">${translate(selected)}</span> | ||
<svg width="32" height="32"> | ||
<polygon points="8 18 17 28 26 18" fill="#0094fb"/> | ||
</svg> | ||
</div> | ||
<ul id="${id}" class="selectOptions"> | ||
${options.map( | ||
i => | ||
html`<li class="selectOption" onclick=${choose} data-value="${i}">${ | ||
i | ||
}</li>` | ||
)} | ||
</ul> | ||
</div>`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.