@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
package/dist/preview.d.ts
CHANGED
|
@@ -389,39 +389,157 @@ type AddMocks<TArgs, DefaultArgs> = Simplify<{
|
|
|
389
389
|
} ? DefaultArgs[T] : TArgs[T] : TArgs[T];
|
|
390
390
|
}>;
|
|
391
391
|
|
|
392
|
+
/** Extracts and unions all args types from an array of decorators. */
|
|
393
|
+
type DecoratorsArgs<TRenderer extends Renderer, Decorators> = UnionToIntersection<Decorators extends DecoratorFunction<TRenderer, infer TArgs> ? TArgs : unknown>;
|
|
394
|
+
type InferArgs<TArgs, T, Decorators> = Simplify<TArgs & Simplify<RemoveIndexSignature<DecoratorsArgs<ReactTypes & T, Decorators>>>>;
|
|
395
|
+
type InferReactTypes<T, TArgs, Decorators> = ReactTypes & T & {
|
|
396
|
+
args: Simplify<InferArgs<TArgs, T, Decorators>>;
|
|
397
|
+
};
|
|
398
|
+
/**
|
|
399
|
+
* Creates a React-specific preview configuration with CSF factories support.
|
|
400
|
+
*
|
|
401
|
+
* This function wraps the base `definePreview` and adds React-specific annotations for rendering
|
|
402
|
+
* and documentation. It returns a `ReactPreview` that provides type-safe `meta()` and `story()`
|
|
403
|
+
* factory methods.
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
*
|
|
407
|
+
* ```ts
|
|
408
|
+
* // .storybook/preview.ts
|
|
409
|
+
* import { definePreview } from '@storybook/react';
|
|
410
|
+
*
|
|
411
|
+
* export const preview = definePreview({
|
|
412
|
+
* addons: [],
|
|
413
|
+
* parameters: { layout: 'centered' },
|
|
414
|
+
* });
|
|
415
|
+
* ```
|
|
416
|
+
*/
|
|
392
417
|
declare function __definePreview<Addons extends PreviewAddon<never>[]>(input: {
|
|
393
418
|
addons: Addons;
|
|
394
419
|
} & ProjectAnnotations<ReactTypes & InferTypes<Addons>>): ReactPreview<ReactTypes & InferTypes<Addons>>;
|
|
395
|
-
|
|
420
|
+
/**
|
|
421
|
+
* React-specific Preview interface that provides type-safe CSF factory methods.
|
|
422
|
+
*
|
|
423
|
+
* Use `preview.meta()` to create a meta configuration for a component, and then `meta.story()` to
|
|
424
|
+
* create individual stories. The type system will infer args from the component props, decorators,
|
|
425
|
+
* and any addon types.
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
*
|
|
429
|
+
* ```ts
|
|
430
|
+
* const meta = preview.meta({ component: Button });
|
|
431
|
+
* export const Primary = meta.story({ args: { label: 'Click me' } });
|
|
432
|
+
* ```
|
|
433
|
+
*/
|
|
396
434
|
/** @ts-expect-error We cannot implement the meta faithfully here, but that is okay. */
|
|
397
435
|
interface ReactPreview<T extends AddonTypes> extends Preview<ReactTypes & T> {
|
|
398
|
-
|
|
399
|
-
|
|
436
|
+
/**
|
|
437
|
+
* Narrows the type of the preview to include additional type information. This is useful when you
|
|
438
|
+
* need to add args that aren't inferred from the component.
|
|
439
|
+
*
|
|
440
|
+
* @example
|
|
441
|
+
*
|
|
442
|
+
* ```ts
|
|
443
|
+
* const meta = preview.type<{ args: { theme: 'light' | 'dark' } }>().meta({
|
|
444
|
+
* component: Button,
|
|
445
|
+
* });
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
type<R>(): ReactPreview<T & R>;
|
|
449
|
+
meta<TArgs extends Args, Decorators extends DecoratorFunction<ReactTypes & T, any>, TMetaArgs extends Partial<TArgs & T['args']>>(meta: {
|
|
450
|
+
render?: ArgsStoryFn<ReactTypes & T, TArgs & T['args']>;
|
|
400
451
|
component?: ComponentType<TArgs>;
|
|
401
452
|
decorators?: Decorators | Decorators[];
|
|
402
453
|
args?: TMetaArgs;
|
|
403
|
-
} & Omit<ComponentAnnotations<ReactTypes & T, TArgs>, 'decorators' | 'component' | 'args' | 'render'>): ReactMeta<
|
|
404
|
-
args: InferArgs<TArgs, T, Decorators>;
|
|
405
|
-
}, Omit<ComponentAnnotations<ReactTypes & T & {
|
|
406
|
-
args: InferArgs<TArgs, T, Decorators>;
|
|
407
|
-
}>, 'args'> & {
|
|
454
|
+
} & Omit<ComponentAnnotations<ReactTypes & T, TArgs>, 'decorators' | 'component' | 'args' | 'render'>): ReactMeta<InferReactTypes<T, TArgs, Decorators>, Omit<ComponentAnnotations<InferReactTypes<T, TArgs, Decorators>>, 'args'> & {
|
|
408
455
|
args: Partial<TArgs> extends TMetaArgs ? {} : TMetaArgs;
|
|
409
456
|
}>;
|
|
410
457
|
}
|
|
411
|
-
|
|
458
|
+
/**
|
|
459
|
+
* React-specific Meta interface returned by `preview.meta()`.
|
|
460
|
+
*
|
|
461
|
+
* Provides the `story()` method to create individual stories with proper type inference. Args
|
|
462
|
+
* provided in meta become optional in stories, while missing required args must be provided at the
|
|
463
|
+
* story level.
|
|
464
|
+
*/
|
|
412
465
|
interface ReactMeta<T extends ReactTypes, MetaInput extends ComponentAnnotations<T>>
|
|
413
|
-
/** @ts-expect-error
|
|
466
|
+
/** @ts-expect-error ReactMeta requires two type parameters, but Meta's constraints differ */
|
|
414
467
|
extends Meta<T, MetaInput> {
|
|
468
|
+
/**
|
|
469
|
+
* Creates a story with a custom render function that takes no args.
|
|
470
|
+
*
|
|
471
|
+
* This overload allows you to define a story using just a render function or an object with a
|
|
472
|
+
* render function that doesn't depend on args. Since the render function doesn't use args, no
|
|
473
|
+
* args need to be provided regardless of what's required by the component.
|
|
474
|
+
*
|
|
475
|
+
* @example
|
|
476
|
+
*
|
|
477
|
+
* ```ts
|
|
478
|
+
* // Using just a render function
|
|
479
|
+
* export const CustomRender = meta.story(() => <div>Custom content</div>);
|
|
480
|
+
*
|
|
481
|
+
* // Using an object with render
|
|
482
|
+
* export const WithRender = meta.story({
|
|
483
|
+
* render: () => <MyComponent prop="static" />,
|
|
484
|
+
* });
|
|
485
|
+
* ```
|
|
486
|
+
*/
|
|
415
487
|
story<TInput extends (() => ReactTypes['storyResult']) | (StoryAnnotations<T, T['args']> & {
|
|
416
488
|
render: () => ReactTypes['storyResult'];
|
|
417
489
|
})>(story: TInput): ReactStory<T, TInput extends () => ReactTypes['storyResult'] ? {
|
|
418
490
|
render: TInput;
|
|
419
491
|
} : TInput>;
|
|
492
|
+
/**
|
|
493
|
+
* Creates a story with custom configuration including args, decorators, or other annotations.
|
|
494
|
+
*
|
|
495
|
+
* This is the primary overload for defining stories. Args that were already provided in meta
|
|
496
|
+
* become optional, while any remaining required args must be specified here.
|
|
497
|
+
*
|
|
498
|
+
* @example
|
|
499
|
+
*
|
|
500
|
+
* ```ts
|
|
501
|
+
* // Provide required args not in meta
|
|
502
|
+
* export const Primary = meta.story({
|
|
503
|
+
* args: { label: 'Click me', disabled: false },
|
|
504
|
+
* });
|
|
505
|
+
*
|
|
506
|
+
* // Override meta args and add story-specific configuration
|
|
507
|
+
* export const Disabled = meta.story({
|
|
508
|
+
* args: { disabled: true },
|
|
509
|
+
* decorators: [withCustomWrapper],
|
|
510
|
+
* });
|
|
511
|
+
* ```
|
|
512
|
+
*/
|
|
420
513
|
story<TInput extends Simplify<StoryAnnotations<T, AddMocks<T['args'], MetaInput['args']>, SetOptional<T['args'], keyof T['args'] & keyof MetaInput['args']>>>>(story: TInput
|
|
421
514
|
/** @ts-expect-error hard */
|
|
422
515
|
): ReactStory<T, TInput>;
|
|
516
|
+
/**
|
|
517
|
+
* Creates a story with no additional configuration.
|
|
518
|
+
*
|
|
519
|
+
* This overload is only available when all required args have been provided in meta. The
|
|
520
|
+
* conditional type `Partial<T['args']> extends SetOptional<...>` checks if the remaining required
|
|
521
|
+
* args (after accounting for args provided in meta) are all optional. If so, the function accepts
|
|
522
|
+
* zero arguments `[]`. Otherwise, it requires `[never]` which makes this overload unmatchable,
|
|
523
|
+
* forcing the user to provide args.
|
|
524
|
+
*
|
|
525
|
+
* @example
|
|
526
|
+
*
|
|
527
|
+
* ```ts
|
|
528
|
+
* // When meta provides all required args, story() can be called with no arguments
|
|
529
|
+
* const meta = preview.meta({ component: Button, args: { label: 'Hi', disabled: false } });
|
|
530
|
+
* export const Default = meta.story(); // Valid - all args provided in meta
|
|
531
|
+
* ```
|
|
532
|
+
*/
|
|
423
533
|
story(..._args: Partial<T['args']> extends SetOptional<T['args'], keyof T['args'] & keyof MetaInput['args']> ? [] : [never]): ReactStory<T, {}>;
|
|
424
534
|
}
|
|
535
|
+
/**
|
|
536
|
+
* React-specific Story interface returned by `meta.story()`.
|
|
537
|
+
*
|
|
538
|
+
* Represents a single story with its configuration and provides access to the composed story for
|
|
539
|
+
* testing via `story.run()`.
|
|
540
|
+
*
|
|
541
|
+
* Also includes a `Component` property for portable story compatibility.
|
|
542
|
+
*/
|
|
425
543
|
interface ReactStory<T extends ReactTypes, TInput extends StoryAnnotations<T, T['args']>> extends Story<T, TInput> {
|
|
426
544
|
Component: ComponentType<Partial<T['args']>>;
|
|
427
545
|
}
|
package/dist/preview.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__definePreview
|
|
3
|
-
} from "./_browser-chunks/chunk-
|
|
4
|
-
import "./_browser-chunks/chunk-
|
|
3
|
+
} from "./_browser-chunks/chunk-HWOFIGZP.js";
|
|
4
|
+
import "./_browser-chunks/chunk-L3JF7GGZ.js";
|
|
5
5
|
import "./_browser-chunks/chunk-DX2KEMQY.js";
|
|
6
6
|
import "./_browser-chunks/chunk-CMP5DLKH.js";
|
|
7
7
|
import "./_browser-chunks/chunk-DDIRQRCA.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/react",
|
|
3
|
-
"version": "10.2.0-
|
|
3
|
+
"version": "10.2.0-beta.0",
|
|
4
4
|
"description": "Storybook React renderer",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook"
|
|
@@ -50,21 +50,21 @@
|
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@storybook/global": "^5.0.0",
|
|
53
|
-
"@storybook/react-dom-shim": "10.2.0-
|
|
53
|
+
"@storybook/react-dom-shim": "10.2.0-beta.0",
|
|
54
54
|
"react-docgen": "^8.0.2"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@types/babel-plugin-react-docgen": "^4.2.3",
|
|
58
58
|
"@types/escodegen": "^0.0.6",
|
|
59
59
|
"@types/estree": "^1.0.6",
|
|
60
|
-
"@types/node": "^22.
|
|
60
|
+
"@types/node": "^22.19.1",
|
|
61
61
|
"acorn": "^7.4.1",
|
|
62
62
|
"acorn-jsx": "^5.3.1",
|
|
63
63
|
"acorn-walk": "^7.2.0",
|
|
64
64
|
"babel-plugin-react-docgen": "^4.2.1",
|
|
65
65
|
"comment-parser": "^1.4.1",
|
|
66
66
|
"empathic": "^2.0.0",
|
|
67
|
-
"es-toolkit": "^1.
|
|
67
|
+
"es-toolkit": "^1.43.0",
|
|
68
68
|
"escodegen": "^2.1.0",
|
|
69
69
|
"expect-type": "^0.15.0",
|
|
70
70
|
"html-tags": "^3.1.0",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"peerDependencies": {
|
|
78
78
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
79
79
|
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
80
|
-
"storybook": "^10.2.0-
|
|
80
|
+
"storybook": "^10.2.0-beta.0",
|
|
81
81
|
"typescript": ">= 4.9.x"
|
|
82
82
|
},
|
|
83
83
|
"peerDependenciesMeta": {
|