Sha256: b0f5b10633d473fcc8c0086be19561b938b3862ccb61d1bc23fa9acf4990a6e5
Contents?: true
Size: 1.14 KB
Versions: 16
Compression:
Stored size: 1.14 KB
Contents
export class IngredientGroup extends HTMLDetailsElement { #localStorageKey = "Alchemy.expanded_ingredient_groups" constructor() { super() this.addEventListener("toggle", this) if (this.isInLocalStorage) { this.open = true } } /** * Toggle visibility of the ingredient fields in this group */ handleEvent() { let expanded_ingredient_groups = this.localStorageItem if (this.open) { if (!this.isInLocalStorage) expanded_ingredient_groups.push(this.id) } else { expanded_ingredient_groups = expanded_ingredient_groups.filter( (value) => value !== this.id ) } localStorage.setItem( this.#localStorageKey, JSON.stringify(expanded_ingredient_groups) ) } get isInLocalStorage() { return this.localStorageItem.includes(this.id) } get localStorageItem() { const item = localStorage.getItem(this.#localStorageKey) if (!item) return [] try { return JSON.parse(item) } catch (error) { console.error(error) return [] } } } customElements.define("alchemy-ingredient-group", IngredientGroup, { extends: "details" })
Version data entries
16 entries across 16 versions & 1 rubygems