Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
github.com/literalpie/storybook-framework-qwik
This is a framework to allow using Storybook with Qwik.
In an existing Qwik project, run npx storybook@next init
(Storybook 7 is required)
See the Storybook Docs for the best documentation on getting started with Storybook.
A basic story will look like this:
import Header, { HeaderProps } from "./header";
import { StoryObj } from "storybook-framework-qwik";
export default {
title: "Header",
component: Header, // component value may be a `component$`, or a "Lite component" (function component)
} as Meta<HeaderProps>;
export const Default: StoryObj<HeaderProps> = {};
You can include a custom renderer for each Meta, or for each story. However, the renderer cannot use Qwik features (such as useStore
). If you need Qwik features in the story, make a wrapper for the component. This is useful when a component expects its props to be reactive state (such as useStore
or useSignal
)
import {
ReactiveComponent,
ReactiveComponentProps,
} from "./reactive-component";
import { Meta, StoryObj } from "storybook-framework-qwik";
import { component$, useStore } from "@builder.io/qwik";
const ReactiveComponentWrapper = component$<ReactiveComponentProps>((args) => {
const state = useStore(args.state);
return <ReactiveComponent state={state} />;
});
export default {
title: "Reactive Component",
component: ReactiveComponent,
render: (args) => <ReactiveComponentWrapper state={args.state} />,
args: { state: { number: 1 } },
} as Meta<ReactiveComponentProps>;
export const Default: StoryObj<ReactiveComponentProps> = {};
To make a story decorator, create a function that returns JSX, including the StoryFn passed to the decorator as a parameter
import { JSXNode } from "@builder.io/qwik";
import { MyComponent } from "./my-component";
import { Decorator } from "storybook-framework-qwik";
export const myDecorator: Decorator = (Story) =>
// Cast is needed because something is out of sync with the JSXNode generated in tsx files and the type expected by Decorator
(<MyComponent>{Story()}</MyComponent>) as JSXNode;
If using QwikCity features in your components, you may want to import the qwikCityDecorator, which wraps stories in MockQwikCityProvider
. This can be added to all stories by exporting the decorator in a decorators array in .storybook/preview.ts
:
import { qwikCityDecorator } from "storybook-framework-qwik/qwik-city-decorator";
export const decorators = [qwikCityDecorator];
You can also add the decorator to individual stories or story files.
Because this framework is shipped only as an ESM module, this may require that you add "type": "module"
to your package.json
(or create a package.json inside your .storybook folder to only make this setting apply to storybook).
If you are using MDX
files and get an error like:
Failed to resolve import "react/jsx-dev-runtime"
you may need to install react
as a dev dependency.
There is a simple example Storybook using the latest version of this package here
Many parts of this package are based on code that I got from this PR, which got some ideas from this discussion.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.