mirror of
https://codeberg.org/vlw/victorwesterlund.com.git
synced 2025-09-14 03:23:41 +02:00
30 lines
No EOL
635 B
JavaScript
30 lines
No EOL
635 B
JavaScript
// Copyright © Victor Westerlund - No libraries! 😲
|
|
|
|
// UI component constructor
|
|
class Component {
|
|
constructor(tag) {
|
|
this.element = document.createElement(tag); // Root element
|
|
}
|
|
}
|
|
|
|
// ⬇ UI Components ⬇
|
|
|
|
export class Button extends Component {
|
|
constructor(properties) {
|
|
super("div");
|
|
this.element.classList.add("button");
|
|
|
|
this.setText(properties.text);
|
|
this.setAction(properties.action);
|
|
}
|
|
|
|
setText(text) {
|
|
const textElement = document.createElement("p");
|
|
textElement.innerText = text;
|
|
this.element.appendChild(textElement);
|
|
}
|
|
|
|
setAction(action) {
|
|
this.element.setAttribute("data-action",action);
|
|
}
|
|
} |