@storybook/react 10.2.0-alpha.8 → 10.2.0-beta.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.
- package/dist/_browser-chunks/{chunk-BMWJYMA6.js → chunk-HWOFIGZP.js} +1 -1
- package/dist/_browser-chunks/{chunk-GLRRNWDU.js → chunk-L3JF7GGZ.js} +2 -1
- package/dist/entry-preview.js +1 -1
- package/dist/index.d.ts +128 -10
- package/dist/index.js +2 -2
- package/dist/preset.js +898 -713
- package/dist/preview.d.ts +128 -10
- package/dist/preview.js +2 -2
- package/package.json +5 -5
|
@@ -17,6 +17,7 @@ __export(entry_preview_exports, {
|
|
|
17
17
|
renderToCanvas: () => renderToCanvas
|
|
18
18
|
});
|
|
19
19
|
import * as React4 from "react";
|
|
20
|
+
import { Tag } from "storybook/internal/preview-api";
|
|
20
21
|
import { global as global2 } from "@storybook/global";
|
|
21
22
|
import { configure } from "storybook/test";
|
|
22
23
|
|
|
@@ -156,7 +157,7 @@ var decorators = [
|
|
|
156
157
|
return React4.createElement(React4.Suspense, null, story());
|
|
157
158
|
},
|
|
158
159
|
(story, context) => {
|
|
159
|
-
if (context.tags?.includes(
|
|
160
|
+
if (context.tags?.includes(Tag.TEST_FN) && !global2.FEATURES?.experimentalTestSyntax)
|
|
160
161
|
throw new Error(
|
|
161
162
|
"To use the experimental test function, you must enable the experimentalTestSyntax feature flag. See https://storybook.js.org/docs/api/main-config/main-config-features#experimentaltestsyntax"
|
|
162
163
|
);
|
package/dist/entry-preview.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -498,39 +498,157 @@ declare function composeStory<TArgs extends Args = Args>(story: StoryAnnotations
|
|
|
498
498
|
*/
|
|
499
499
|
declare function composeStories<TModule extends Store_CSFExports<ReactRenderer, any>>(csfExports: TModule, projectAnnotations?: ProjectAnnotations<ReactRenderer>): Omit<StoriesWithPartialProps<ReactRenderer, TModule>, keyof Store_CSFExports>;
|
|
500
500
|
|
|
501
|
+
/** Extracts and unions all args types from an array of decorators. */
|
|
502
|
+
type DecoratorsArgs<TRenderer extends Renderer, Decorators> = UnionToIntersection<Decorators extends DecoratorFunction<TRenderer, infer TArgs> ? TArgs : unknown>;
|
|
503
|
+
type InferArgs<TArgs, T, Decorators> = Simplify<TArgs & Simplify<RemoveIndexSignature<DecoratorsArgs<ReactTypes & T, Decorators>>>>;
|
|
504
|
+
type InferReactTypes<T, TArgs, Decorators> = ReactTypes & T & {
|
|
505
|
+
args: Simplify<InferArgs<TArgs, T, Decorators>>;
|
|
506
|
+
};
|
|
507
|
+
/**
|
|
508
|
+
* Creates a React-specific preview configuration with CSF factories support.
|
|
509
|
+
*
|
|
510
|
+
* This function wraps the base `definePreview` and adds React-specific annotations for rendering
|
|
511
|
+
* and documentation. It returns a `ReactPreview` that provides type-safe `meta()` and `story()`
|
|
512
|
+
* factory methods.
|
|
513
|
+
*
|
|
514
|
+
* @example
|
|
515
|
+
*
|
|
516
|
+
* ```ts
|
|
517
|
+
* // .storybook/preview.ts
|
|
518
|
+
* import { definePreview } from '@storybook/react';
|
|
519
|
+
*
|
|
520
|
+
* export const preview = definePreview({
|
|
521
|
+
* addons: [],
|
|
522
|
+
* parameters: { layout: 'centered' },
|
|
523
|
+
* });
|
|
524
|
+
* ```
|
|
525
|
+
*/
|
|
501
526
|
declare function __definePreview<Addons extends PreviewAddon<never>[]>(input: {
|
|
502
527
|
addons: Addons;
|
|
503
528
|
} & ProjectAnnotations<ReactTypes & InferTypes<Addons>>): ReactPreview<ReactTypes & InferTypes<Addons>>;
|
|
504
|
-
|
|
529
|
+
/**
|
|
530
|
+
* React-specific Preview interface that provides type-safe CSF factory methods.
|
|
531
|
+
*
|
|
532
|
+
* Use `preview.meta()` to create a meta configuration for a component, and then `meta.story()` to
|
|
533
|
+
* create individual stories. The type system will infer args from the component props, decorators,
|
|
534
|
+
* and any addon types.
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
*
|
|
538
|
+
* ```ts
|
|
539
|
+
* const meta = preview.meta({ component: Button });
|
|
540
|
+
* export const Primary = meta.story({ args: { label: 'Click me' } });
|
|
541
|
+
* ```
|
|
542
|
+
*/
|
|
505
543
|
/** @ts-expect-error We cannot implement the meta faithfully here, but that is okay. */
|
|
506
544
|
interface ReactPreview<T extends AddonTypes> extends Preview$1<ReactTypes & T> {
|
|
507
|
-
|
|
508
|
-
|
|
545
|
+
/**
|
|
546
|
+
* Narrows the type of the preview to include additional type information. This is useful when you
|
|
547
|
+
* need to add args that aren't inferred from the component.
|
|
548
|
+
*
|
|
549
|
+
* @example
|
|
550
|
+
*
|
|
551
|
+
* ```ts
|
|
552
|
+
* const meta = preview.type<{ args: { theme: 'light' | 'dark' } }>().meta({
|
|
553
|
+
* component: Button,
|
|
554
|
+
* });
|
|
555
|
+
* ```
|
|
556
|
+
*/
|
|
557
|
+
type<R>(): ReactPreview<T & R>;
|
|
558
|
+
meta<TArgs extends Args, Decorators extends DecoratorFunction<ReactTypes & T, any>, TMetaArgs extends Partial<TArgs & T['args']>>(meta: {
|
|
559
|
+
render?: ArgsStoryFn<ReactTypes & T, TArgs & T['args']>;
|
|
509
560
|
component?: ComponentType<TArgs>;
|
|
510
561
|
decorators?: Decorators | Decorators[];
|
|
511
562
|
args?: TMetaArgs;
|
|
512
|
-
} & Omit<ComponentAnnotations<ReactTypes & T, TArgs>, 'decorators' | 'component' | 'args' | 'render'>): ReactMeta<
|
|
513
|
-
args: InferArgs<TArgs, T, Decorators>;
|
|
514
|
-
}, Omit<ComponentAnnotations<ReactTypes & T & {
|
|
515
|
-
args: InferArgs<TArgs, T, Decorators>;
|
|
516
|
-
}>, 'args'> & {
|
|
563
|
+
} & Omit<ComponentAnnotations<ReactTypes & T, TArgs>, 'decorators' | 'component' | 'args' | 'render'>): ReactMeta<InferReactTypes<T, TArgs, Decorators>, Omit<ComponentAnnotations<InferReactTypes<T, TArgs, Decorators>>, 'args'> & {
|
|
517
564
|
args: Partial<TArgs> extends TMetaArgs ? {} : TMetaArgs;
|
|
518
565
|
}>;
|
|
519
566
|
}
|
|
520
|
-
|
|
567
|
+
/**
|
|
568
|
+
* React-specific Meta interface returned by `preview.meta()`.
|
|
569
|
+
*
|
|
570
|
+
* Provides the `story()` method to create individual stories with proper type inference. Args
|
|
571
|
+
* provided in meta become optional in stories, while missing required args must be provided at the
|
|
572
|
+
* story level.
|
|
573
|
+
*/
|
|
521
574
|
interface ReactMeta<T extends ReactTypes, MetaInput extends ComponentAnnotations<T>>
|
|
522
|
-
/** @ts-expect-error
|
|
575
|
+
/** @ts-expect-error ReactMeta requires two type parameters, but Meta's constraints differ */
|
|
523
576
|
extends Meta$1<T, MetaInput> {
|
|
577
|
+
/**
|
|
578
|
+
* Creates a story with a custom render function that takes no args.
|
|
579
|
+
*
|
|
580
|
+
* This overload allows you to define a story using just a render function or an object with a
|
|
581
|
+
* render function that doesn't depend on args. Since the render function doesn't use args, no
|
|
582
|
+
* args need to be provided regardless of what's required by the component.
|
|
583
|
+
*
|
|
584
|
+
* @example
|
|
585
|
+
*
|
|
586
|
+
* ```ts
|
|
587
|
+
* // Using just a render function
|
|
588
|
+
* export const CustomRender = meta.story(() => <div>Custom content</div>);
|
|
589
|
+
*
|
|
590
|
+
* // Using an object with render
|
|
591
|
+
* export const WithRender = meta.story({
|
|
592
|
+
* render: () => <MyComponent prop="static" />,
|
|
593
|
+
* });
|
|
594
|
+
* ```
|
|
595
|
+
*/
|
|
524
596
|
story<TInput extends (() => ReactTypes['storyResult']) | (StoryAnnotations<T, T['args']> & {
|
|
525
597
|
render: () => ReactTypes['storyResult'];
|
|
526
598
|
})>(story: TInput): ReactStory<T, TInput extends () => ReactTypes['storyResult'] ? {
|
|
527
599
|
render: TInput;
|
|
528
600
|
} : TInput>;
|
|
601
|
+
/**
|
|
602
|
+
* Creates a story with custom configuration including args, decorators, or other annotations.
|
|
603
|
+
*
|
|
604
|
+
* This is the primary overload for defining stories. Args that were already provided in meta
|
|
605
|
+
* become optional, while any remaining required args must be specified here.
|
|
606
|
+
*
|
|
607
|
+
* @example
|
|
608
|
+
*
|
|
609
|
+
* ```ts
|
|
610
|
+
* // Provide required args not in meta
|
|
611
|
+
* export const Primary = meta.story({
|
|
612
|
+
* args: { label: 'Click me', disabled: false },
|
|
613
|
+
* });
|
|
614
|
+
*
|
|
615
|
+
* // Override meta args and add story-specific configuration
|
|
616
|
+
* export const Disabled = meta.story({
|
|
617
|
+
* args: { disabled: true },
|
|
618
|
+
* decorators: [withCustomWrapper],
|
|
619
|
+
* });
|
|
620
|
+
* ```
|
|
621
|
+
*/
|
|
529
622
|
story<TInput extends Simplify<StoryAnnotations<T, AddMocks<T['args'], MetaInput['args']>, SetOptional<T['args'], keyof T['args'] & keyof MetaInput['args']>>>>(story: TInput
|
|
530
623
|
/** @ts-expect-error hard */
|
|
531
624
|
): ReactStory<T, TInput>;
|
|
625
|
+
/**
|
|
626
|
+
* Creates a story with no additional configuration.
|
|
627
|
+
*
|
|
628
|
+
* This overload is only available when all required args have been provided in meta. The
|
|
629
|
+
* conditional type `Partial<T['args']> extends SetOptional<...>` checks if the remaining required
|
|
630
|
+
* args (after accounting for args provided in meta) are all optional. If so, the function accepts
|
|
631
|
+
* zero arguments `[]`. Otherwise, it requires `[never]` which makes this overload unmatchable,
|
|
632
|
+
* forcing the user to provide args.
|
|
633
|
+
*
|
|
634
|
+
* @example
|
|
635
|
+
*
|
|
636
|
+
* ```ts
|
|
637
|
+
* // When meta provides all required args, story() can be called with no arguments
|
|
638
|
+
* const meta = preview.meta({ component: Button, args: { label: 'Hi', disabled: false } });
|
|
639
|
+
* export const Default = meta.story(); // Valid - all args provided in meta
|
|
640
|
+
* ```
|
|
641
|
+
*/
|
|
532
642
|
story(..._args: Partial<T['args']> extends SetOptional<T['args'], keyof T['args'] & keyof MetaInput['args']> ? [] : [never]): ReactStory<T, {}>;
|
|
533
643
|
}
|
|
644
|
+
/**
|
|
645
|
+
* React-specific Story interface returned by `meta.story()`.
|
|
646
|
+
*
|
|
647
|
+
* Represents a single story with its configuration and provides access to the composed story for
|
|
648
|
+
* testing via `story.run()`.
|
|
649
|
+
*
|
|
650
|
+
* Also includes a `Component` property for portable story compatibility.
|
|
651
|
+
*/
|
|
534
652
|
interface ReactStory<T extends ReactTypes, TInput extends StoryAnnotations<T, T['args']>> extends Story<T, TInput> {
|
|
535
653
|
Component: ComponentType<Partial<T['args']>>;
|
|
536
654
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__definePreview
|
|
3
|
-
} from "./_browser-chunks/chunk-
|
|
3
|
+
} from "./_browser-chunks/chunk-HWOFIGZP.js";
|
|
4
4
|
import {
|
|
5
5
|
entry_preview_exports,
|
|
6
6
|
renderToCanvas
|
|
7
|
-
} from "./_browser-chunks/chunk-
|
|
7
|
+
} from "./_browser-chunks/chunk-L3JF7GGZ.js";
|
|
8
8
|
import {
|
|
9
9
|
entry_preview_argtypes_exports
|
|
10
10
|
} from "./_browser-chunks/chunk-DX2KEMQY.js";
|