-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds a view-router we can use to switch out the browser action main element based on ... things. Also i add a generic message-screen factory, so we can simply add more with one func call :) https://github.com/user-attachments/assets/e159f60e-d9be-40f3-84fa-979f02fd5ec9
- Loading branch information
Showing
15 changed files
with
981 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { html, LitElement } from "../vendor/lit-all.min.js"; | ||
|
||
/** | ||
* `ConditionalView` | ||
* | ||
* Takes N elements each with a slot="" attribute, | ||
* the active rendered view can be controlled using slotName="slot" | ||
* if no view matches "slotName" the slot named "default" will be rendered. | ||
* | ||
* | ||
* <conditional-view slotName="b"> | ||
* <h1 slot="a">Hidden</h1> | ||
* <h1 slot="b">This is rendered</h1> | ||
* </conditional-view> | ||
*/ | ||
|
||
export class ConditionalView extends LitElement { | ||
static properties = { | ||
slotName: { reflect: true }, | ||
}; | ||
constructor() { | ||
super(); | ||
this.slotName = "default"; | ||
} | ||
|
||
hasSlot(slotName) { | ||
return Array.from(this.children).some((e) => { | ||
return e.slot === slotName; | ||
}); | ||
} | ||
getTargetSlot() { | ||
const slot = this.slotName; | ||
if (slot == "") { | ||
return "default"; | ||
} | ||
if (!this.hasSlot(slot)) { | ||
return "default"; | ||
} | ||
return slot; | ||
} | ||
render() { | ||
return html` <slot name=${this.getTargetSlot()}></slot> `; | ||
} | ||
} | ||
customElements.define("conditional-view", ConditionalView); |
Oops, something went wrong.