Skip to content

Astro

Use staticview components in Astro pages.

TypeScript Configuration

Add the component types to your TypeScript configuration:

tsconfig.json
{
"compilerOptions": {
"types": [
// Required: types the component tags in Astro templates
// For one component: "@staticview/ui/types/astro/[component-name]"
"@staticview/ui/types/astro",
// Optional: types what `querySelector` and `createElement` return for each tag
// For one component: "@staticview/ui/types/dom/[component-name]"
"@staticview/ui/types/dom",
// Optional: declares each component type globally, with no import
// For one component: "@staticview/ui/types/global/[component-name]"
"@staticview/ui/types/global",
],
},
}

Importing Web Components

Import each component in a <script> of the page or layout that uses it:

<script>
import "@staticview/ui/[component-name]";
</script>

Using Components With Astro

Since Astro renders a web component as a plain HTML element, the template sets only its attributes, in their HTML form, like close-button="" to turn a boolean on. Set properties and listen to events from a client <script>.