Skip to content
This repository was archived by the owner on Jan 31, 2024. It is now read-only.

Commit 562ae08

Browse files
committed
update types and imports for storybook 7.0
1 parent dce8409 commit 562ae08

File tree

5 files changed

+433
-248
lines changed

5 files changed

+433
-248
lines changed

package.json

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,18 @@
5656
"limit": "10 KB"
5757
}
5858
],
59+
"dependencies": {
60+
"@storybook/csf": "next"
61+
},
5962
"devDependencies": {
6063
"@auto-it/conventional-commits": "^10.31.0",
6164
"@auto-it/first-time-contributor": "^10.31.0",
6265
"@auto-it/released": "^10.31.0",
6366
"@size-limit/preset-small-lib": "^4.10.1",
64-
"@storybook/addons": "^7.0.0-alpha.49",
65-
"@storybook/react": "^7.0.0-alpha.49",
66-
"@storybook/store": "^7.0.0-alpha.49",
67-
"@storybook/types": "^7.0.0-alpha.49",
67+
"@storybook/addons": "next",
68+
"@storybook/react": "next",
69+
"@storybook/store": "next",
70+
"@storybook/types": "next",
6871
"@types/react": "17",
6972
"auto": "^10.31.0",
7073
"concurrently": "^6.0.0",
@@ -73,18 +76,14 @@
7376
"size-limit": "^4.10.1",
7477
"tsdx": "^0.14.1",
7578
"tslib": "^2.3.1",
76-
"typescript": "^4.2.3"
79+
"typescript": "^4.9.3"
7780
},
7881
"peerDependencies": {
79-
"@storybook/addons": ">=6.4.0",
80-
"@storybook/preview-web": ">=6.4.0",
81-
"@storybook/react": ">=6.4.0",
82-
"@storybook/store": ">=6.4.0",
82+
"@storybook/preview-web": "next",
83+
"@storybook/preview-api": "next",
84+
"@storybook/react": "next",
8385
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
8486
},
85-
"resolutions": {
86-
"**/typescript": "^4.2.3"
87-
},
8887
"publishConfig": {
8988
"access": "public"
9089
},
@@ -99,8 +98,5 @@
9998
"first-time-contributor",
10099
"released"
101100
]
102-
},
103-
"dependencies": {
104-
"@storybook/csf": "next"
105101
}
106102
}

src/index.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { defaultDecorateStory, combineParameters } from '@storybook/store';
2-
import { addons, applyHooks, HooksContext, mockChannel } from '@storybook/addons';
3-
import type { Meta, ReactFramework } from '@storybook/react';
1+
import { defaultDecorateStory, combineParameters, addons, applyHooks, HooksContext, mockChannel } from '@storybook/preview-api';
2+
import type { Meta, ReactRenderer, Args } from '@storybook/react';
43
import type { StoryContext } from '@storybook/types';
54
import { isExportStory } from '@storybook/csf';
65

@@ -62,7 +61,7 @@ export function setGlobalConfig(config: GlobalConfig) {
6261
* @param meta - e.g. (import Meta from './Button.stories')
6362
* @param [globalConfig] - e.g. (import * as globalConfig from '../.storybook/preview') this can be applied automatically if you use `setGlobalConfig` in your setup files.
6463
*/
65-
export function composeStory<GenericArgs>(
64+
export function composeStory<GenericArgs extends Args>(
6665
story: TestingStory<GenericArgs>,
6766
meta: Meta<GenericArgs | any>,
6867
globalConfig: GlobalConfig = globalStorybookConfig
@@ -82,15 +81,14 @@ export function composeStory<GenericArgs>(
8281
}
8382

8483
const renderFn = typeof story === 'function' ? story : story.render ?? meta.render ?? globalRender;
85-
const finalStoryFn = (context: StoryContext<ReactFramework, GenericArgs>) => {
84+
const finalStoryFn = (context: StoryContext<ReactRenderer, GenericArgs>) => {
8685
const { passArgsFirst = true } = context.parameters;
8786
if (!passArgsFirst) {
8887
throw new Error(
8988
'composeStory does not support legacy style stories (with passArgsFirst = false).'
9089
);
9190
}
9291

93-
// @ts-expect-error (just trying to get this to build)
9492
return renderFn(context.args, context);
9593
};
9694

@@ -100,7 +98,7 @@ export function composeStory<GenericArgs>(
10098
...(globalConfig.decorators || []),
10199
];
102100

103-
const decorated = decorateStory<ReactFramework>(
101+
const decorated = decorateStory<ReactRenderer>(
104102
finalStoryFn as any,
105103
combinedDecorators as any
106104
);
@@ -141,7 +139,7 @@ export function composeStory<GenericArgs>(
141139
viewMode: 'story',
142140
originalStoryFn: renderFn,
143141
hooks: new HooksContext(),
144-
} as StoryContext<ReactFramework, GenericArgs>;
142+
} as StoryContext<ReactRenderer, GenericArgs>;
145143

146144
const composedStory = (extraArgs: Partial<GenericArgs>) => {
147145
return decorated({

src/types.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
import type { BaseStoryFn as OriginalBaseStoryFn } from '@storybook/addons';
2-
import type { BaseAnnotations, Store_WebProjectAnnotations, StoryContext, Args } from '@storybook/types';
3-
import type { StoryFn as OriginalStoryFn, StoryObj, Meta, ReactFramework } from '@storybook/react';
1+
import type { Addon_BaseStoryFn as OriginalBaseStoryFn, BaseAnnotations, ProjectAnnotations, StoryContext, Args } from '@storybook/types';
2+
import type { StoryFn as OriginalStoryFn, StoryObj, Meta, ReactRenderer } from '@storybook/react';
43
import type { ReactElement } from 'react';
54

65
type StoryFnReactReturnType = ReactElement<unknown>;
76

8-
export type BaseStoryFn<Args> = OriginalBaseStoryFn<Args, StoryFnReactReturnType> & BaseAnnotations<Args, StoryFnReactReturnType>;
7+
export type BaseStoryFn<Args> = OriginalBaseStoryFn<Args, StoryFnReactReturnType> & BaseAnnotations<ReactRenderer, Args>;
98
/**
109
* Object representing the preview.ts module
1110
*
1211
* Used in storybook testing utilities.
1312
* @see [Unit testing with Storybook](https://storybook.js.org/docs/react/workflows/unit-testing)
1413
*/
15-
export type GlobalConfig = Store_WebProjectAnnotations<ReactFramework>;
14+
export type GlobalConfig = ProjectAnnotations<ReactRenderer>;
1615

1716
export type TestingStory<T = Args> = StoryFn<T> | StoryObj<T>;
1817

1918
export type StoryFile = { default: Meta<any>, __esModule?: boolean }
2019

21-
export type TestingStoryPlayContext<T = Args> = Partial<StoryContext<ReactFramework, T>> & Pick<StoryContext, 'canvasElement'>
20+
export type TestingStoryPlayContext<T = Args> = Partial<StoryContext<ReactRenderer, T>> & Pick<StoryContext, 'canvasElement'>
2221

2322
export type TestingStoryPlayFn<TArgs = Args> = (context: TestingStoryPlayContext<TArgs>) => Promise<void> | void;
2423

src/utils.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react';
22

33
import type { FunctionComponent } from 'react';
4-
import type { Story } from '@storybook/react';
4+
import type { StoryFn } from '@storybook/react';
55
import type { TestingStory } from './types';
66

7-
export const globalRender: Story = (args, { parameters }) => {
7+
export const globalRender: StoryFn = (args, { parameters }) => {
88
if (!parameters.component) {
99
throw new Error(`
1010
Could not render story due to missing 'component' property in Meta.

0 commit comments

Comments
 (0)