Created
March 14, 2024 02:48
-
-
Save kristoferjoseph/fe9fe965d9d11127c3bf2f65c0fe6bce to your computer and use it in GitHub Desktop.
Declarative Shadow DOM Playground
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>Declarative Shadow DOM Playground</title> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
</head> | |
<body> | |
<my-paragraph> | |
<template shadowrootmode="open"> | |
<style> | |
:host { | |
font-size: 2rem; | |
font-weight: 900; | |
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | |
} | |
</style> | |
<p> | |
<slot name="my-text"> | |
My default text | |
</slot> | |
</p> | |
</template> | |
<span slot="my-text">Declarative Shadow DOM Content.</span> | |
</my-paragraph> | |
<my-paragraph> | |
<template shadowrootmode="open"> | |
<style> | |
:host { | |
font-size: 2rem; | |
font-weight: 900; | |
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | |
} | |
</style> | |
<p> | |
<slot name="my-text"> | |
My default text | |
</slot> | |
</p> | |
</template> | |
<span slot="my-text">New content</span> | |
</my-paragraph> | |
<my-paragraph> | |
<template shadowrootmode="open"> | |
<style> | |
:host { | |
font-size: 2rem; | |
font-weight: 900; | |
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | |
} | |
</style> | |
<p> | |
<slot name="my-text"> | |
My default text | |
</slot> | |
</p> | |
</template> | |
</my-paragraph> | |
<script type="module"> | |
customElements.define( | |
'my-paragraph', | |
class MyParagraph extends HTMLElement { | |
constructor() { | |
super() | |
console.log('DSD in action') | |
} | |
} | |
) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment