Skip to content

Astro

No adapter package needed — web components work directly in Astro templates.

Terminal window
npm install @voidable/ui @voidable/theme

Import the component definitions in a <script> tag and the theme CSS globally:

---
import '@voidable/theme';
---
<html data-theme="dark">
<head>
<title>My App</title>
</head>
<body>
<void-button variant="filled">Click me</void-button>
<void-input placeholder="Your name"></void-input>
<script>
import '@voidable/ui';
document.querySelector('void-button')!.addEventListener('void-click', () => {
console.log('clicked');
});
</script>
</body>
</html>

Scoped styles don’t reach Light DOM internals

Section titled “Scoped styles don’t reach Light DOM internals”

Astro’s scoped <style> tags add data-astro-* attributes to selectors, which won’t match Light DOM component internals. Use is:global on style tags or import theme CSS globally:

<style is:global>
void-button {
--void-button-radius: 8px;
}
</style>

Curly braces {} are expression delimiters in Astro templates. If you’re rendering CSS or code content that contains braces, use set:html:

<pre><code set:html={`void-button { --void-button-radius: 8px; }`}></code></pre>

Set the theme via the data-theme attribute on the root element:

<html data-theme="dark">

For dynamic switching, use a client-side script:

<script>
document.documentElement.dataset.theme =
window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
</script>