Last active
April 28, 2023 06:54
-
-
Save jaredcwhite/0979a2c09763da7a8fb01910806fd67b to your computer and use it in GitHub Desktop.
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
customElements.define("paywalled-content", class extends HTMLElement { | |
static observedAttributes = ["open"] | |
attributeChangedCallback(name, oldValue, newValue) { | |
if (name === "open" && newValue !== null) { | |
this.shadowRoot.querySelector("slot").removeAttribute("name") | |
} else { | |
this.shadowRoot.querySelector("slot").name = "public" | |
} | |
} | |
}) |
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
<p>Intro content.</p> | |
<paywalled-content> | |
<template shadowrootmode="open"> | |
<slot name="public"></slot> | |
</template> | |
<aside slot="public"> | |
<p>And that's all! Sign up for the full thing.</p> | |
</aside> | |
<!-- a server fetch can just append paywalled content here and toggle the element attribute `open` --> | |
</paywalled-content> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment