Qwik
TypeScript Configuration
Add the Web Component types to your TypeScript configuration:
{ "compilerOptions": { "types": [ // Required: Enables JSX type support for Qwik // Or a single component: "@staticview/ui/types/qwik/[component-name]" "@staticview/ui/types/qwik",
// Optional: Adds native DOM types (e.g. `querySelector`, `document`) // Or a single component: "@staticview/ui/types/dom/[component-name]" "@staticview/ui/types/dom",
// Optional: Exposes component types globally (no imports needed) // Or a single component: "@staticview/ui/types/global/[component-name]" "@staticview/ui/types/global", ], },}This provides TypeScript support for the web components in your Qwik application.
Importing Web Components
Web components are registered globally in the browser. Import them once in your application's entry point:
import "@staticview/ui/[component-name]";Important: Do not import web components in multiple files. Import them only once at application startup.
Setting Properties and Attributes
If the web component has a JavaScript property, Qwik will automatically set it, otherwise, it sets it as an HTML attribute.
<component-name opened={isOpen.value}></component-name>Boolean Attributes
A boolean attribute is on whenever it is present, whatever its value: close-button="false" turns the close button on. Qwik removes an attribute whose value is false and sets it to "" when it is true, so pass a boolean:
<component-name close-button={hasCloseButton.value}></component-name>Prefer the matching JavaScript property when the component has one. Qwik assigns it directly on the element, so the value reaches the component as a boolean instead of as markup. The component decides whether to reflect it back to the attribute:
<component-name closeButton={hasCloseButton.value}></component-name>Handling Events
Use on[EventName]$ syntax to listen for custom events:
<component-name onOpened$={handleOpened}></component-name>Using Slots
Use children to render the content of the web component:
<component-name> <span slot="title">Title</span> <span>Content</span></component-name>