mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-05 20:32:27 +00:00
41 lines
1020 B
JavaScript
41 lines
1020 B
JavaScript
function createElement(doc, tag, className, text) {
|
|
const element = doc.createElement(tag);
|
|
if (className) {
|
|
element.className = className;
|
|
}
|
|
if (typeof text === "string") {
|
|
element.textContent = text;
|
|
}
|
|
return element;
|
|
}
|
|
|
|
export function NotificationCenter({ document: doc, notices = [] } = {}) {
|
|
if (!doc) {
|
|
throw new Error("NotificationCenter requires a document reference.");
|
|
}
|
|
|
|
const root = createElement(doc, "section", "dm-notification-center");
|
|
|
|
if (!notices.length) {
|
|
const placeholder = createElement(
|
|
doc,
|
|
"div",
|
|
"dm-notification-center__empty",
|
|
"You're all caught up.",
|
|
);
|
|
root.appendChild(placeholder);
|
|
return root;
|
|
}
|
|
|
|
notices.forEach((notice) => {
|
|
const item = createElement(doc, "div", "dm-notification-center__item");
|
|
if (notice.variant) {
|
|
item.classList.add(`dm-notification-center__item--${notice.variant}`);
|
|
}
|
|
item.textContent = notice.message || "";
|
|
root.appendChild(item);
|
|
});
|
|
|
|
return root;
|
|
}
|