storybook-astro 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +330 -0
  3. package/dist/index.cjs +397 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +88 -0
  6. package/dist/index.d.ts +88 -0
  7. package/dist/index.js +390 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/integration/index.cjs +50 -0
  10. package/dist/integration/index.cjs.map +1 -0
  11. package/dist/integration/index.d.cts +26 -0
  12. package/dist/integration/index.d.ts +26 -0
  13. package/dist/integration/index.js +44 -0
  14. package/dist/integration/index.js.map +1 -0
  15. package/dist/integration/toolbar-app.cjs +91 -0
  16. package/dist/integration/toolbar-app.cjs.map +1 -0
  17. package/dist/integration/toolbar-app.d.cts +10 -0
  18. package/dist/integration/toolbar-app.d.ts +10 -0
  19. package/dist/integration/toolbar-app.js +89 -0
  20. package/dist/integration/toolbar-app.js.map +1 -0
  21. package/dist/preset.cjs +294 -0
  22. package/dist/preset.cjs.map +1 -0
  23. package/dist/preset.d.cts +49 -0
  24. package/dist/preset.d.ts +49 -0
  25. package/dist/preset.js +285 -0
  26. package/dist/preset.js.map +1 -0
  27. package/dist/render-BR-BGSWL.d.cts +36 -0
  28. package/dist/render-BR-BGSWL.d.ts +36 -0
  29. package/dist/renderer/entry-preview.cjs +315 -0
  30. package/dist/renderer/entry-preview.cjs.map +1 -0
  31. package/dist/renderer/entry-preview.d.cts +26 -0
  32. package/dist/renderer/entry-preview.d.ts +26 -0
  33. package/dist/renderer/entry-preview.js +311 -0
  34. package/dist/renderer/entry-preview.js.map +1 -0
  35. package/dist/renderer/index.cjs +216 -0
  36. package/dist/renderer/index.cjs.map +1 -0
  37. package/dist/renderer/index.d.cts +21 -0
  38. package/dist/renderer/index.d.ts +21 -0
  39. package/dist/renderer/index.js +211 -0
  40. package/dist/renderer/index.js.map +1 -0
  41. package/dist/sourceTransformer-CsgaPbY9.d.cts +38 -0
  42. package/dist/sourceTransformer-CsgaPbY9.d.ts +38 -0
  43. package/package.json +100 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ryan Hughes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,330 @@
1
+ # storybook-astro
2
+
3
+ Storybook framework for Astro components. Render `.astro` files directly in Storybook with full support for props, controls, and automatic source code generation.
4
+
5
+ ## Features
6
+
7
+ - **Native Astro Support** - Render `.astro` components directly in Storybook
8
+ - **Storybook 10** - Built for the latest Storybook version
9
+ - **Controls Panel** - Interactive props editing with auto-detected controls
10
+ - **Auto Source Code** - Automatically generates Astro component code snippets in docs
11
+ - **Global Styles** - Import your global CSS into all stories
12
+ - **Inline Docs** - Components render at their natural size in docs mode
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install -D storybook-astro storybook @storybook/addon-docs @storybook/builder-vite
18
+ ```
19
+
20
+ ## Quick Start
21
+
22
+ ### 1. Create `.storybook/main.ts`
23
+
24
+ ```typescript
25
+ const config = {
26
+ stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'],
27
+
28
+ addons: ['@storybook/addon-docs'],
29
+
30
+ framework: {
31
+ name: 'storybook-astro',
32
+ options: {},
33
+ },
34
+
35
+ core: {
36
+ builder: '@storybook/builder-vite',
37
+ },
38
+ };
39
+
40
+ export default config;
41
+ ```
42
+
43
+ ### 2. Create `.storybook/preview.ts`
44
+
45
+ ```typescript
46
+ // Import your global styles
47
+ import '../src/styles/global.css';
48
+
49
+ const preview = {
50
+ parameters: {
51
+ layout: 'padded',
52
+ backgrounds: {
53
+ options: {
54
+ light: { name: 'Light', value: '#ffffff' },
55
+ dark: { name: 'Dark', value: '#1a1a2e' },
56
+ },
57
+ },
58
+ },
59
+ };
60
+
61
+ export default preview;
62
+ ```
63
+
64
+ ### 3. Write Stories
65
+
66
+ ```typescript
67
+ // src/stories/Button.stories.ts
68
+ import Button from '../components/Button.astro';
69
+
70
+ const meta = {
71
+ title: 'Components/Button',
72
+ component: Button,
73
+ parameters: {
74
+ layout: 'centered',
75
+ },
76
+ argTypes: {
77
+ variant: {
78
+ control: 'select',
79
+ options: ['primary', 'secondary'],
80
+ description: 'Visual style of the button',
81
+ },
82
+ label: {
83
+ control: 'text',
84
+ description: 'Button text',
85
+ },
86
+ },
87
+ };
88
+
89
+ export default meta;
90
+
91
+ export const Primary = {
92
+ args: {
93
+ variant: 'primary',
94
+ label: 'Click me',
95
+ },
96
+ };
97
+
98
+ export const Secondary = {
99
+ args: {
100
+ variant: 'secondary',
101
+ label: 'Click me',
102
+ },
103
+ };
104
+ ```
105
+
106
+ ### 4. Add Scripts to `package.json`
107
+
108
+ ```json
109
+ {
110
+ "scripts": {
111
+ "storybook": "storybook dev -p 6006",
112
+ "build-storybook": "storybook build"
113
+ }
114
+ }
115
+ ```
116
+
117
+ ### 5. Run Storybook
118
+
119
+ ```bash
120
+ npm run storybook
121
+ ```
122
+
123
+ ## Running Alongside Astro Dev Server
124
+
125
+ For the best development experience, run both Astro and Storybook together using `concurrently`:
126
+
127
+ ```bash
128
+ npm install -D concurrently
129
+ ```
130
+
131
+ Update your `package.json` scripts:
132
+
133
+ ```json
134
+ {
135
+ "scripts": {
136
+ "dev": "concurrently -n astro,storybook -c blue,magenta \"astro dev\" \"storybook dev -p 6006 --no-open\"",
137
+ "dev:astro": "astro dev",
138
+ "dev:storybook": "storybook dev -p 6006",
139
+ "storybook": "storybook dev -p 6006",
140
+ "build-storybook": "storybook build"
141
+ }
142
+ }
143
+ ```
144
+
145
+ Now `npm run dev` starts both servers:
146
+ - **Astro**: http://localhost:4321
147
+ - **Storybook**: http://localhost:6006
148
+
149
+ ## Story Format
150
+
151
+ ### Basic Story
152
+
153
+ ```typescript
154
+ import MyComponent from '../components/MyComponent.astro';
155
+
156
+ export default {
157
+ title: 'Components/MyComponent',
158
+ component: MyComponent,
159
+ };
160
+
161
+ export const Default = {
162
+ args: {
163
+ title: 'Hello World',
164
+ count: 42,
165
+ },
166
+ };
167
+ ```
168
+
169
+ ### Full-Width Components
170
+
171
+ For components like heroes that need full width:
172
+
173
+ ```typescript
174
+ export default {
175
+ title: 'Components/HeroSection',
176
+ component: HeroSection,
177
+ parameters: {
178
+ layout: 'fullscreen',
179
+ docs: {
180
+ story: {
181
+ inline: true, // Renders at natural size in docs
182
+ },
183
+ },
184
+ },
185
+ };
186
+ ```
187
+
188
+ ### With ArgTypes Documentation
189
+
190
+ ```typescript
191
+ export default {
192
+ title: 'Components/Card',
193
+ component: Card,
194
+ tags: ['autodocs'], // Auto-generate docs page
195
+ argTypes: {
196
+ title: {
197
+ control: 'text',
198
+ description: 'Card heading',
199
+ table: {
200
+ type: { summary: 'string' },
201
+ defaultValue: { summary: 'Untitled' },
202
+ },
203
+ },
204
+ variant: {
205
+ control: 'select',
206
+ options: ['default', 'outlined', 'elevated'],
207
+ description: 'Visual variant',
208
+ },
209
+ disabled: {
210
+ control: 'boolean',
211
+ description: 'Whether the card is interactive',
212
+ },
213
+ },
214
+ };
215
+ ```
216
+
217
+ ### Custom Source Code
218
+
219
+ By default, the "Show code" panel auto-generates Astro syntax. To customize:
220
+
221
+ ```typescript
222
+ export const CustomExample = {
223
+ args: {
224
+ title: 'Example',
225
+ },
226
+ parameters: {
227
+ docs: {
228
+ source: {
229
+ code: `---
230
+ import Card from '../components/Card.astro';
231
+ ---
232
+
233
+ <Card title="Example">
234
+ <p>Custom slot content</p>
235
+ </Card>`,
236
+ language: 'astro',
237
+ },
238
+ },
239
+ },
240
+ };
241
+ ```
242
+
243
+ ## Configuration Options
244
+
245
+ ### Framework Options
246
+
247
+ | Option | Type | Default | Description |
248
+ |--------|------|---------|-------------|
249
+ | `stylesheets` | `string[]` | `[]` | Global stylesheets to inject into stories |
250
+ | `scripts` | `string[]` | `[]` | Global scripts to inject into stories |
251
+
252
+ ### Example with Options
253
+
254
+ ```typescript
255
+ // .storybook/main.ts
256
+ const config = {
257
+ framework: {
258
+ name: 'storybook-astro',
259
+ options: {
260
+ stylesheets: [
261
+ '/src/styles/global.css',
262
+ '/src/styles/components.css',
263
+ ],
264
+ scripts: [
265
+ '/src/scripts/analytics.js',
266
+ ],
267
+ },
268
+ },
269
+ };
270
+ ```
271
+
272
+ ## TypeScript Support
273
+
274
+ For TypeScript support with `.astro` imports, add to your `tsconfig.json`:
275
+
276
+ ```json
277
+ {
278
+ "compilerOptions": {
279
+ "types": ["astro/client"]
280
+ }
281
+ }
282
+ ```
283
+
284
+ Note: TypeScript may show errors for `.astro` imports in story files. These are safe to ignore - the components will work correctly at runtime.
285
+
286
+ ## How It Works
287
+
288
+ 1. **Astro Vite Plugins** - The framework loads Astro's Vite plugins to compile `.astro` files
289
+ 2. **Component Compilation** - `.astro` files are compiled to JavaScript component factories
290
+ 3. **Direct Rendering** - Components render directly in the Storybook canvas
291
+ 4. **Source Transform** - Args are automatically transformed to Astro template syntax for docs
292
+
293
+ ## Requirements
294
+
295
+ - **Astro** 5.x
296
+ - **Storybook** 10.x
297
+ - **Node.js** 20+
298
+
299
+ ## Troubleshooting
300
+
301
+ ### Component not rendering
302
+
303
+ 1. Ensure the component path is correct
304
+ 2. Check the browser console for errors
305
+ 3. Verify your component works in Astro first
306
+
307
+ ### Styles not applying
308
+
309
+ 1. Import global styles in `.storybook/preview.ts`
310
+ 2. Component-scoped styles should work automatically
311
+ 3. Check that CSS file paths are correct
312
+
313
+ ### "Cannot find module" TypeScript errors
314
+
315
+ This is expected for `.astro` imports in TypeScript files. The components will still work - this is just a TypeScript limitation.
316
+
317
+ ### Build errors
318
+
319
+ Run `npm run build-storybook` to see detailed error messages. Common issues:
320
+ - Missing dependencies
321
+ - Invalid component syntax
322
+ - Circular imports
323
+
324
+ ## Disclaimer
325
+
326
+ This project is not affiliated with, endorsed by, or sponsored by [Astro](https://astro.build) or [Storybook](https://storybook.js.org). All trademarks belong to their respective owners.
327
+
328
+ ## License
329
+
330
+ MIT