-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathButtons.js
30 lines (26 loc) · 900 Bytes
/
Buttons.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function createButton(div, name, cmd) {
const button = document.createElement('button')
button.textContent = name
button.onclick = cmd
button.style.backgroundColor = 'skyblue'
button.style.padding = '10px 14px'
button.style.fontSize = '18px'
button.style.border = 'none'
// button.style.borderRadius = "5px";
button.style.cursor = 'pointer'
button.style.margin = '0 5px' // Add margin for spacing between buttons
div.appendChild(button)
return button
}
class Buttons {
constructor(divId, buttonTemplates) {
const div = document.getElementById(divId)
this.buttons = {}
buttonTemplates.forEach(obj => {
let { name, cmd } = obj
if (!(cmd && name)) throw Error('No cmd or name given for ' + obj)
this.buttons[name] = createButton(div, name, cmd)
})
}
}
export default Buttons