Components for popup UI
This commit is contained in:
parent
981368b376
commit
ccafcd5285
29
js/lib/libghettoui/BaseUi.js
Normal file
29
js/lib/libghettoui/BaseUi.js
Normal 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);
|
||||
}
|
||||
}
|
11
js/lib/libghettoui/buttons/Button.js
Normal file
11
js/lib/libghettoui/buttons/Button.js
Normal file
@ -0,0 +1,11 @@
|
||||
class ShortcutButton extends BaseUi {
|
||||
constructor(id, label, onClick, additionalClasses) {
|
||||
super(
|
||||
id,
|
||||
label,
|
||||
onClick,
|
||||
additionalClasses
|
||||
);
|
||||
this.element.classList.add('button');
|
||||
}
|
||||
}
|
10
js/lib/libghettoui/buttons/ShortcutButton.js
Normal file
10
js/lib/libghettoui/buttons/ShortcutButton.js
Normal 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
|
||||
);
|
||||
}
|
||||
}
|
30
js/lib/libghettoui/popup/MenuItem.js
Normal file
30
js/lib/libghettoui/popup/MenuItem.js
Normal 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');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user