web/elements: allow multiple tabs with different state
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
		@ -13,6 +13,9 @@ import { getURLParams, updateURLParams } from "./router/RouteMatch";
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
@customElement("ak-tabs")
 | 
					@customElement("ak-tabs")
 | 
				
			||||||
export class Tabs extends LitElement {
 | 
					export class Tabs extends LitElement {
 | 
				
			||||||
 | 
					    @property()
 | 
				
			||||||
 | 
					    pageIdentifier: string = "page";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @property()
 | 
					    @property()
 | 
				
			||||||
    currentPage?: string;
 | 
					    currentPage?: string;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -66,9 +69,9 @@ export class Tabs extends LitElement {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    onClick(slot?: string): void {
 | 
					    onClick(slot?: string): void {
 | 
				
			||||||
        this.currentPage = slot;
 | 
					        this.currentPage = slot;
 | 
				
			||||||
        updateURLParams({
 | 
					        const params: { [key: string]: string | undefined } = {};
 | 
				
			||||||
            page: slot,
 | 
					        params[this.pageIdentifier] = slot;
 | 
				
			||||||
        });
 | 
					        updateURLParams(params);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    renderTab(page: Element): TemplateResult {
 | 
					    renderTab(page: Element): TemplateResult {
 | 
				
			||||||
@ -84,10 +87,10 @@ export class Tabs extends LitElement {
 | 
				
			|||||||
        const pages = Array.from(this.querySelectorAll("[slot^='page-']"));
 | 
					        const pages = Array.from(this.querySelectorAll("[slot^='page-']"));
 | 
				
			||||||
        if (window.location.hash.includes(ROUTE_SEPARATOR)) {
 | 
					        if (window.location.hash.includes(ROUTE_SEPARATOR)) {
 | 
				
			||||||
            const params = getURLParams();
 | 
					            const params = getURLParams();
 | 
				
			||||||
            if ("page" in params) {
 | 
					            if (this.pageIdentifier in params) {
 | 
				
			||||||
                if (this.querySelector(`[slot='${params.page}']`) !== null) {
 | 
					                if (this.querySelector(`[slot='${params[this.pageIdentifier]}']`) !== null) {
 | 
				
			||||||
                    // To update the URL to match with the current slot
 | 
					                    // To update the URL to match with the current slot
 | 
				
			||||||
                    this.currentPage = params.page;
 | 
					                    this.currentPage = params[this.pageIdentifier];
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user