| 19 | } |
| 20 | |
| 21 | render () { |
| 22 | const buttons = (this.constructor as typeof QuickMenu).buttons (); |
| 23 | |
| 24 | return buttons.map ((button) => { |
| 25 | // A user could create a custom element to display all or specific |
| 26 | // buttons. If no element was set on the button's definition, we'll |
| 27 | // assume it to be a simple button. |
| 28 | if (typeof button.element !== 'string') { |
| 29 | button.element = 'button'; |
| 30 | } |
| 31 | |
| 32 | const element = document.createElement (button.element); |
| 33 | |
| 34 | if (typeof button.data === 'object') { |
| 35 | for (const key of Object.keys (button.data)) { |
| 36 | element.dataset[key] = button.data[key]; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | element.setAttribute ('icon', button.icon); |
| 41 | element.setAttribute ('string', button.string); |
| 42 | element.setAttribute ('tabindex', '0'); |
| 43 | |
| 44 | element.innerHTML = ` |
| 45 | <span class="${button.icon}"></span> |
| 46 | <span data-string="${button.string}">${this.engine.string (button.string)}</span> |
| 47 | `; |
| 48 | |
| 49 | return element.outerHTML; |
| 50 | }).join (' '); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | export default QuickMenu; |