@aqua-ds/web-components
Version:
AquaDS Web Components
44 lines (42 loc) • 1.4 kB
JavaScript
class ZIndex {
constructor(baseZIndex, step) {
this.aqZIndex = {};
this.numberZIndex = 1;
this.baseZIndex = baseZIndex;
this.step = step;
}
static getInstance() {
if (!ZIndex.instance) {
ZIndex.instance = new ZIndex(13000, 30);
}
return ZIndex.instance;
}
getZIndex(idComponent) {
if (this.aqZIndex[idComponent]?.zIndex) {
return this.aqZIndex[idComponent].zIndex;
}
return null;
}
setZIndex(idComponent) {
if (!(idComponent in this.aqZIndex)) {
const lastZIndex = Object.values(this.aqZIndex).reduce((max, entry) => Math.max(max, entry.zIndex), this.baseZIndex - this.step);
this.aqZIndex[idComponent] = {
zIndex: lastZIndex + this.step,
index: this.numberZIndex++,
};
}
return this.aqZIndex[idComponent].zIndex;
}
deleteZIndex(idComponent) {
delete this.aqZIndex[idComponent];
this.numberZIndex = this.numberZIndex - 1;
}
getLastIndex(idComponent) {
const lastZIndex = Object.values(this.aqZIndex).reduce((max, entry) => Math.max(max, entry.zIndex), this.baseZIndex - this.step);
if (this.aqZIndex[idComponent]?.zIndex === lastZIndex) {
return true;
}
return false;
}
}
export { ZIndex as Z };