shopping-category implementiert

This commit is contained in:
Technoir committed 2026-10-14 13:37:01 +02:00
1 parent fd984529e7
commit b1aa5bec07
1 file changed
+27 -20
@@ -1,31 +1,24 @@
export class ShoppingCategory {
constructor(categoryName) {
this.categoryName = categoryName;
this.categoryID = null;
export class ShoppingCategory extends HTMLElement {
static get observedAttributes() { return ["category-name"] }
constructor() {
super();
this._rendered = false;
}
static fromJSON(categoryAsJSON) {
const category = new ShoppingCategory(categoryAsJSON.categoryName);
category.categoryID = categoryAsJSON.categoryID;
return category;
}
render() {
const li = document.createElement("li");
connectedCallback() {
if (this._rendered) return;
const categoryHeaderDiv = document.createElement("div");
const span = document.createElement("span");
const deleteCategoryButton = document.createElement("button");
const labelDeleteAllItems = document.createElement("label");
const deleteAllItemsCheckbox = document.createElement("input");
const innerUl = document.createElement("ul");
li.dataset.id = this.categoryID;
li.classList.add("category");
categoryHeaderDiv.classList.add("category__header");
categoryHeaderDiv.classList.add("category__div");
span.textContent = this.categoryName;
span.textContent = this.getAttribute("category-name");
span.classList.add("category__name", "category__name--bold", "category__name--big");
labelDeleteAllItems.classList.add("category__labelDeleteAll");
@@ -40,8 +33,22 @@ export class ShoppingCategory {
categoryHeaderDiv.append(span, deleteCategoryButton, labelDeleteAllItems);
li.append(categoryHeaderDiv, innerUl);
this.prepend(categoryHeaderDiv);
return li;
this._rendered = true;
}
attributeChangeCallback(name, oldVal, newVal) {
if (!this._rendered) return;
if (newVal == oldVal) return;
switch (name) {
case "category-name":
this.querySelector(".category__name").textContent = newVal;
break;
default:
break;
}
}
}