bitburner-src/utils/uiHelpers/createPopup.ts

42 lines
1.1 KiB
TypeScript
Raw Normal View History

import { createElement } from "./createElement";
import { getElementById } from "./getElementById";
interface ICreatePopupOptions {
2021-09-05 01:09:30 +02:00
backgroundColor?: string;
}
/**
* Creates the necessary DOM elements to present an in-game popup to the player.
* @param id The (hopefully) unique identifier for the popup container.
* @param elems The collection of HTML Elements to show within the popup.
*/
2021-09-05 01:09:30 +02:00
export function createPopup(
id: string,
elems: HTMLElement[],
options: ICreatePopupOptions = {},
): HTMLDivElement {
const container: HTMLDivElement = createElement("div", {
class: "popup-box-container",
display: "flex",
id: id,
}) as HTMLDivElement;
const content: HTMLElement = createElement("div", {
class: "popup-box-content",
id: `${id}-content`,
});
2021-09-05 01:09:30 +02:00
for (const elem of elems) {
content.appendChild(elem);
}
2021-09-05 01:09:30 +02:00
// Configurable Options
if (options.backgroundColor) {
content.style.backgroundColor = options.backgroundColor;
}
2021-09-05 01:09:30 +02:00
container.appendChild(content);
getElementById("entire-game-container").appendChild(container);
2021-09-05 01:09:30 +02:00
return container;
}