You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pages/components/page-menu.js

42 lines
930 B
JavaScript

3 years ago
export class PageMenu extends HTMLElement {
constructor() {
super()
this.attachShadow({mode: 'open'})
}
connectedCallback() {
const style = document.createElement('style')
style.textContent = `
:host {
background: #222;
color: #ddd;
padding: 3px;
3 years ago
display: flex;
flex-direction: column;
align-items: stretch;
min-width: 180px;
3 years ago
}
button {
background: #222;
font-size: 120%;
border: none;
color: inherit;
padding: 4px 10px;
text-align: left;
3 years ago
}
`
this.shadowRoot.append(style)
}
add(text, handler) {
const btn = document.createElement('button')
btn.innerText = text
this.shadowRoot.appendChild(btn)
btn.addEventListener('click', () => {
this.dispatchEvent(new CustomEvent(
'close-menu', {bubbles: true}
))
handler()
})
}
3 years ago
}