@merkur/tool-storybook
v1.0.3
Published
Merkur integration to storybook tool.
Downloads
501
Readme
Merkur - tool-storybook
Integrates Storybook with Merkur widgets. The package handles the widget lifecycle (create → mount → unmount) inside the Storybook loader pipeline, so your story files stay focused on rendering.
Full documentation and setup guide.
Installation
npm install --save-dev @merkur/tool-storybookAPI
| Export | Description |
|--------|-------------|
| createPreviewConfig(options) | Registers a widget with Merkur and returns a partial Storybook preview.mjs config ({ loaders }). Spread into your preview export. |
| createVanillaRenderer() | Creates a render/update pair for vanilla JS widgets that produce HTML strings. |
| createWidgetLoader(options) | Low-level loader factory used internally by createPreviewConfig. Use directly when you need full control over widget registration. |
createPreviewConfig options
| Option | Type | Required | Description |
|--------|------|----------|-------------|
| widgetProperties | Object | ✅ | Widget definition object — must include name and version. |
| render | Function | — | Called each time widget.update() fires, receives the widget instance. Defaults to a no-op. |
| createWidget | Function | — | Widget factory. Defaults to createMerkurWidget from @merkur/core. |
createVanillaRenderer
createVanillaRenderer() takes no arguments.
- Stories must provide
args.componentas a function(widget) => htmlString. - Event binding: define
bindEventListeners(widget, container)(and optionallyunbindEventListeners(widget, container)) directly on the widget inside itscreateWidgetfactory. The renderer callswidget.bindEventListeners(container)after each render andwidget.unbindEventListeners(container)before each re-render.widgetis auto-injected as the first argument by Merkur'sbindWidgetToFunctions, so the signature in the definition must includewidgetas the first parameter. - Security:
args.componentis responsible for HTML-escaping any dynamic values before returning the HTML string. Raw interpolation of user-controlled strings is injected viainnerHTMLas-is.
Peer dependencies
This package requires Storybook ≥ 10 (storybook/preview-api and storybook/internal/core-events are imported at runtime). Installing it alongside Storybook < 10 will cause a module-not-found error.
About Merkur
Merkur is a tiny extensible JavaScript library for front-end microservices. It supports server-side rendering out of the box and works with Preact, µhtml, Svelte, vanilla JS, and more.
