Skip to content

Qwik

Use staticview components in Qwik JSX.

TypeScript Configuration

Add the component types to your TypeScript configuration:

tsconfig.json
{
"compilerOptions": {
"types": [
// Required: types the component tags in Qwik JSX
// For one component: "@staticview/ui/types/qwik/[component-name]"
"@staticview/ui/types/qwik",
// 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

Since components register globally, import each one once, in your app's entry point:

app.tsx
import "@staticview/ui/[component-name]";

Setting Properties and Attributes

Qwik sets a prop as a property when the element has one, and as an attribute otherwise:

<component-name opened={isOpen.value}></component-name>

Boolean Attributes

A boolean attribute is on whenever it is present, and close-button="false" turns the close button on. Pass a boolean, and Qwik sets the attribute to "" for true and removes it for false:

<component-name close-button={hasCloseButton.value}></component-name>

When the component has a matching property, prefer it, since Qwik assigns it on the element as a boolean:

<component-name closeButton={hasCloseButton.value}></component-name>

Handling Events

Listen to component events with on[Eventname]$, where only the first letter of the event name is uppercase:

<component-name onOpenedchange$={handleOpenedChange}></component-name>

Using Slots

Put the content between the tags, with a slot attribute for a named slot:

<component-name>
<span slot="title">Title</span>
<span>Content</span>
</component-name>