Components for popup UI

This commit is contained in:
Tamius Han 2018-11-11 02:25:47 +01:00
parent 981368b376
commit ccafcd5285
4 changed files with 80 additions and 0 deletions

View File

@ -0,0 +1,29 @@
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');
}
appendTo(element) {
element.appendChild(this.element);
}
}

View File

@ -0,0 +1,11 @@
class ShortcutButton extends BaseUi {
constructor(id, label, onClick, additionalClasses) {
super(
id,
label,
onClick,
additionalClasses
);
this.element.classList.add('button');
}
}

View File

@ -0,0 +1,10 @@
class ShortcutButton extends Button {
constructor(id, label, shortcutLabel, onClick, additionalClasses) {
super(
id,
`${label}<br/><span class="smallcaps small darker">(${shortcutLabel})`,
onClick,
additionalClasses
);
}
}

View File

@ -0,0 +1,30 @@
class MenuItem extends BaseUi {
constructor(id, label, sublabel, onClick, additionalClasses) {
super(
id,
`${label}<span class="menu-item-inline-desc"><br/>${sublabel}</span>`,
onClick,
additionalClasses
);
this.element.classList.add('menu-item');
this.element.subitemList = document.createElement('div');
}
insertSubitem(subitemElement) {
this.element.subitemList.appendChild(subitemElement);
}
removeSubitems() {
while (this.element.subitemList.firstChild) {
this.element.subitemList.removeChild(this.element.subitemList.firstChild);
}
}
showSubitems() {
this.element.subitemList.classList.remove('hidden');
}
hideSubitems() {
this.element.subitemList.classList.add('hidden');
}
}