You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Browse filesBrowse the repository at this point in the historyBrowse files
Jiřà Fencl
committed
feat: 🎸 feat(tool-storybook): add vanilla JS support and preview configuration helpers
- Add createPreviewConfig helper for simplified Storybook setup
- Add createVanillaRenderer for vanilla JavaScript widget rendering
- Add comprehensive JSDoc documentation for all exported functions
- Update documentation with Storybook 9 setup for both Preact and vanilla JS widgets
- Include separate configuration examples for Preact and vanilla frameworks
@@ -8,72 +8,149 @@ description: Learn how to integrate Storybook with your Merkur widget
8
8
9
9
[Storybook](https://storybook.js.org/) is an open source tool for developing UI components in isolation for React, Vue, Angular, and more. It makes building stunning UIs organized and efficient.
10
10
11
+
This guide requires Storybook version 9 or higher. Lower versions need a different setup, which is covered in previous versions of the documentation.
12
+
11
13
## Installation
12
14
13
-
At first we must install storybook to our Merkur project. The best way is using the [Storybook CLI](https://storybook.js.org/docs/react/get-started/install) to install it in a single command.
15
+
Since Preact and vanilla JavaScript are not in the automatic framework selection, you need to manually install Storybook packages.
16
+
17
+
### For Preact Widgets
14
18
15
19
```bash
16
-
npx storybook@latest init
20
+
npm i -D @storybook/preact-vite storybook
17
21
```
18
22
19
-
After that we install merkur module for easy integration.
23
+
### For Vanilla JavaScript Widgets
20
24
21
25
```bash
22
-
npm i @merkur/tool-storybook --save-dev
26
+
npm i -D @storybook/html-vite storybook
23
27
```
24
28
25
-
Now we must update storybook file `./storybook/preview.js` similarly to the example below.
29
+
### Merkur Integration Package
30
+
31
+
Then install the Merkur module for easy integration (required for both):
32
+
33
+
```bash
34
+
npm i -D @merkur/tool-storybook
35
+
```
36
+
37
+
## Configuration
38
+
39
+
### Preact Widget
40
+
41
+
For Preact widgets, configure Storybook to use the Preact framework and JSX transformation.
addons.getChannel().emit(FORCE_RE_RENDER); // widget must be able to update the storybook playground
90
+
return container;
50
91
},
51
-
widgetProperties, // created widget properties
52
-
})
53
-
];
54
-
55
-
// if you need Context in React or Preact widget you must define Context Provider.
56
-
exportconstdecorators= [
57
-
(Story, { loaded: { widget }}) => {
58
-
return (
59
-
<WidgetContext.Provider value={widget}>
60
-
<Story />
61
-
</WidgetContext.Provider>
62
-
);
63
-
},
64
-
];
92
+
};
93
+
94
+
exportdefaultpreview;
65
95
```
66
96
67
-
> Note: If you use any pre-processors (webpack loaders) for building CSS styles you should also define then in `webpackFinal` function by extending given `config` object. More on that topic can be found in [official Storybook documentation](https://storybook.js.org/docs/react/configure/styling-and-css).
97
+
### Vanilla JavaScript Widget
98
+
99
+
For vanilla JavaScript widgets that render HTML strings, configure Storybook to use the HTML framework.
You can use every [format](https://storybook.js.org/docs/react/writing-stories/introduction) which Storybook offers. For example we pick up `named exports` format and our counter component from demo page for `Preact`preview.
You can use any [story format](https://storybook.js.org/docs/react/writing-stories/introduction) that Storybook supports. Below are examples for both Preact and vanilla widgets.
147
+
148
+
### Preact Widget Stories
149
+
150
+
For Preact components that use context, wrap them in the appropriate provider:
0 commit comments