-
-
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
CSF: Add base factories #30416
Merged
+500
−147
Merged
CSF: Add base factories #30416
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
8ceedc1
Base definePreview
kasperpeulen 2085d4b
Add type tests
kasperpeulen b93d96a
Make storybook/internal/csf
kasperpeulen fccc0df
Adjust runtime
kasperpeulen bd5f88c
Adjust runtime
kasperpeulen c5cb4b1
Fix TODO
kasperpeulen 209cdeb
Use default export for preview
kasperpeulen d5b592a
Fix type inference issue
kasperpeulen 1f5a406
Fix
kasperpeulen 1f4c92f
Fix import
kasperpeulen 1a356cb
Fix build
kasperpeulen 03ec593
Fix test
kasperpeulen cecfd85
Fix eslint
kasperpeulen 815c778
Fix eslint
kasperpeulen 43ac425
Fix vitest
kasperpeulen 70429c2
Re-export definePreview
kasperpeulen a838e73
Adjust codemod
kasperpeulen dc79392
Move csf4 stories
kasperpeulen 3847a11
add csfFactory modification option for sandboxes
yannbf b5b0420
fix tests
yannbf aa305bb
fix issues
yannbf ce00ea5
fix sandboxes
yannbf 1d637ec
Merge branch 'kasper/csf-factories' into kasper/base-factories
yannbf e383e7d
Merge remote-tracking branch 'origin/kasper/csf-factories' into kaspe…
kasperpeulen 0f00a18
Fix react-webpack/17-ts
kasperpeulen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading status checks…
Add type tests
commit 2085d4b6434a214599d8e9f35de391efd6faf905
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,10 +10,10 @@ import type { | |
} from 'storybook/internal/types'; | ||
import { definePreview as definePreviewBase } from 'storybook/internal/types'; | ||
|
||
import type { ArgsStoryFn } from '@storybook/csf'; | ||
import type { ArgsStoryFn, DecoratorFunction, LoaderFunction, Renderer } from '@storybook/csf'; | ||
|
||
import type { AddMocks } from 'src/public-types'; | ||
import type { Exact, SetOptional } from 'type-fest'; | ||
import type { RemoveIndexSignature, SetOptional, Simplify, UnionToIntersection } from 'type-fest'; | ||
|
||
import * as reactAnnotations from './entry-preview'; | ||
import * as reactDocsAnnotations from './entry-preview-docs'; | ||
|
@@ -27,15 +27,31 @@ export function definePreview(preview: ReactPreview['input']) { | |
} | ||
|
||
export interface ReactPreview extends Preview<ReactRenderer> { | ||
meta<TArgs extends Args, TMetaArgs extends Exact<Partial<TArgs>, TMetaArgs>>( | ||
meta< | ||
TArgs extends Args, | ||
Decorators extends DecoratorFunction<ReactRenderer, any>, | ||
// Try to make Exact<Partial<TArgs>, TMetaArgs> work | ||
TMetaArgs extends Partial<TArgs>, | ||
>( | ||
meta: { | ||
render?: ArgsStoryFn<ReactRenderer, TArgs>; | ||
component?: ComponentType<TArgs>; | ||
decorators?: Decorators | Decorators[]; | ||
args?: TMetaArgs; | ||
} & ComponentAnnotations<ReactRenderer, TArgs> | ||
): ReactMeta<{ args: TArgs }, { args: TMetaArgs }>; | ||
} & Omit<ComponentAnnotations<ReactRenderer, TArgs>, 'decorators'> | ||
): ReactMeta< | ||
{ | ||
args: Simplify< | ||
TArgs & Simplify<RemoveIndexSignature<DecoratorsArgs<ReactRenderer, Decorators>>> | ||
>; | ||
}, | ||
{ args: Partial<TArgs> extends TMetaArgs ? {} : TMetaArgs } | ||
>; | ||
} | ||
|
||
type DecoratorsArgs<TRenderer extends Renderer, Decorators> = UnionToIntersection< | ||
Decorators extends DecoratorFunction<TRenderer, infer TArgs> ? TArgs : unknown | ||
>; | ||
Comment on lines
+51
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: DecoratorsArgs type uses UnionToIntersection which could lead to 'never' type in some edge cases with incompatible decorator args |
||
interface ReactMeta< | ||
Context extends { args: Args }, | ||
MetaInput extends ComponentAnnotations<ReactRenderer>, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
logic: Decorator is modifying args but not preserving them between Story renders, which could cause issues with state management