loader/src/js/elements/Element.js
Llewellyn van der Merwe d9f5a1aebc
Implement enhanced UI elements with library detection and fallback
- Add modal implementation with automatic detection for four specific libraries.
- Introduce inline tooltips with library compatibility.
- Implement a default stand-alone fallback for environments without supported libraries.
2023-11-20 16:29:47 +02:00

44 lines
1.2 KiB
JavaScript

import { ModalElement } from './ModalElement.js';
import { InlineElement } from './InlineElement.js';
import { TooltipElement } from './TooltipElement.js';
/**
* Element class responsible for creating and managing different types of elements
* based on the specified format.
*/
export class Element {
/**
* Constructs an Element instance based on the given format.
*
* @param {HTMLElement} triggerElement - The trigger element.
* @param {string} format - The format type.
*/
constructor(triggerElement, format = 'tooltip') {
if (!(triggerElement instanceof HTMLElement)) {
throw new Error("triggerElement must be an instance of HTMLElement.");
}
const elementTypes = {
'modal': ModalElement,
'inline': InlineElement,
'tooltip': TooltipElement
};
const ElementType = elementTypes[format] || TooltipElement;
this.element = new ElementType(triggerElement);
if (process.env.DEBUG) {
console.log(`${format} element selected`);
}
}
/**
* Load the content into the element.
*
* @param {string} content - The content to load.
*/
load(content) {
this.element.load(content);
}
}