35 lines
809 B
JavaScript
35 lines
809 B
JavaScript
class BaseUi {
|
|
constructor(id, label, onClick, additionalClasses) {
|
|
this.element = document.createElement('div');
|
|
this.element.setAttribute('id', id);
|
|
if (additionalClasses) {
|
|
this.element.classList.add(...additionalClasses);
|
|
}
|
|
if (onClick) {
|
|
this.element.addEventListener('click', onClick);
|
|
}
|
|
this.element.innerHTML = label;
|
|
}
|
|
|
|
disable() {
|
|
this.element.classList.add('disabled');
|
|
}
|
|
enable() {
|
|
this.element.classList.remove('disabled');
|
|
}
|
|
hide() {
|
|
this.element.classList.add('hidden');
|
|
}
|
|
show() {
|
|
this.element.classList.remove('hidden');
|
|
}
|
|
select() {
|
|
this.element.classList.add('selected');
|
|
}
|
|
unselect() {
|
|
this.element.classList.remove('selected');
|
|
}
|
|
appendTo(element) {
|
|
element.appendChild(this.element);
|
|
}
|
|
} |