Skip to content

Instantly share code, notes, and snippets.

@kristoferjoseph
Created March 14, 2024 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kristoferjoseph/fe9fe965d9d11127c3bf2f65c0fe6bce to your computer and use it in GitHub Desktop.
Save kristoferjoseph/fe9fe965d9d11127c3bf2f65c0fe6bce to your computer and use it in GitHub Desktop.
Declarative Shadow DOM Playground
<!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