-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add preview type and update CLI template #21205
Conversation
@@ -193,21 +208,27 @@ describe('configurePreview', () => { | |||
|
|||
expect(previewConfigPath).toEqual('./.storybook/preview.ts'); | |||
expect(previewConfigContent).toMatchInlineSnapshot(` | |||
"import { setCompodocJson } from \\"@storybook/addon-docs/angular\\"; | |||
"import type { Preview } from '@storybook/angular' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the end result should be like the other import?
import type { Preview } from \\"@storybook/angular\\"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, maybe we should run prettier on it, using user config, if possible. The main.js
template you wrote is actually using single quotes everywhere:
if (isTypescript) {
imports.push(`import type { StorybookConfig } from '${frameworkPackage}';`);
} else {
imports.push(`/** @type { import('${frameworkPackage}').StorybookConfig } */`);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prettified the files based on user config
@@ -114,20 +115,34 @@ export async function configurePreview(options: ConfigurePreviewOptions) { | |||
return; | |||
} | |||
|
|||
const prefix = [ | |||
isTypescript ? `import type { Preview } from '@storybook/${options.rendererId}'` : '', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder how this is going to work with community frameworks/renderers, it's better if the entire package comes as a parameter, rather than half of the import
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure as well. Do we have an community framework example that I could test?
@JReinhold Do you know more about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
I'm quite curious regarding the types coming from renderers. Checking this PR it got me thinking that React users would have the same types experience if they're using @storybook/react-vite or @storybook/react-webpack, however they probably want different types if they're using @storybook/nextjs, given that Nextjs provides out of the box routing and other features that can be configured at the parameter level. Does this make sense? Or should we just do some sort of augmentation in the future for scenarios like this? |
@yannbf I think module augmentation would suffice: declare module '@storybook/react' {
interface Parameters
extends StorybookParameters,
ChromaticParameters,
DocsParameters,
NextjsParameters {}
} I like that the csf files only import types from preview, and are kind of decoupled from the builder. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome stuff!!
Closes #20950
What I did
I didn't update the documentation yet, or added a runtime warning for old style preview.js files. Maybe we can outscope that for now?
How to test
yarn task --task sandbox --start-from auto --template react-vite/default-ts
-->
Checklist
MIGRATION.MD
Maintainers
make sure to add the
ci:merged
orci:daily
GH label to it.["cleanup", "BREAKING CHANGE", "feature request", "bug", "documentation", "maintenance", "dependencies", "other"]