Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
57c2c8c
WIP: Add support for parameters
kasperpeulen Feb 12, 2025
cf87f2a
Merge remote-tracking branch 'origin/next' into kasper/csf-parameters
kasperpeulen Feb 20, 2025
59b9d5d
Fix
kasperpeulen Feb 20, 2025
526ce10
Rollback preview changes
kasperpeulen Feb 20, 2025
07fbadc
Fix tests
kasperpeulen Feb 24, 2025
ec29949
Pass parameters to story and meta
kasperpeulen Feb 24, 2025
238df1b
Fix type tests
kasperpeulen Feb 24, 2025
dee1f12
Merge remote-tracking branch 'origin/next' into kasper/csf-parameters
kasperpeulen May 21, 2025
8050a06
Don't export in addon-outline
kasperpeulen May 21, 2025
f7a85a7
Don't export in addon-backgrounds
kasperpeulen May 21, 2025
793a49b
Get all addons in shape
kasperpeulen May 23, 2025
5af7f47
Fix next as well
kasperpeulen May 23, 2025
70c0641
Fix check
kasperpeulen May 25, 2025
9eb7abe
Just test the parameters
kasperpeulen May 26, 2025
9733393
Fix
kasperpeulen May 26, 2025
e77a51f
Merge remote-tracking branch 'origin/next' into kasper/csf-parameters
kasperpeulen May 26, 2025
1e25c44
Remove shared csf4 file
kasperpeulen May 26, 2025
e8fbce4
Restructure core annotations in csf export
kasperpeulen May 26, 2025
bfc9665
Fix check
kasperpeulen May 28, 2025
0a804a5
Add test of mrginglymus
kasperpeulen May 28, 2025
9cb16c1
Merge remote-tracking branch 'refs/remotes/origin/next' into kasper/c…
kasperpeulen May 28, 2025
a402c19
Fix
kasperpeulen May 28, 2025
1401cce
Merge branch 'next' into kasper/csf-parameters
kasperpeulen May 30, 2025
82e2e1b
Fix composed
kasperpeulen May 30, 2025
4f8d020
Fix input.args type
kasperpeulen Jun 2, 2025
d13935a
Fix core types
kasperpeulen Jun 2, 2025
4f06e56
Fix core parameter types
kasperpeulen Jun 2, 2025
f090c08
Add globals
kasperpeulen Jun 2, 2025
9f2b655
Fix
kasperpeulen Jun 2, 2025
fa988c0
Fix
kasperpeulen Jun 2, 2025
224683b
Fix type
kasperpeulen Jun 2, 2025
a667e87
Make grid optional
kasperpeulen Jun 2, 2025
dcb271d
Fix a11y type
kasperpeulen Jun 2, 2025
0cdccd7
Add portable stories support to factories
kasperpeulen Jun 3, 2025
4ba962a
Get local preview
kasperpeulen Jun 3, 2025
5736c48
Implement extends API
kasperpeulen Jun 3, 2025
b613883
Implement extends API
kasperpeulen Jun 3, 2025
84d090f
Add CSF1-like story
kasperpeulen Jun 3, 2025
7813e8c
Add CSF1-like story
kasperpeulen Jun 3, 2025
93ac519
Fix unit tests
kasperpeulen Jun 3, 2025
40d66b1
Fix extend
kasperpeulen Jun 3, 2025
825a252
Fix check
kasperpeulen Jun 3, 2025
e96aede
Add unit test for extend
kasperpeulen Jun 4, 2025
4e391ab
Fix viewport type
kasperpeulen Jun 4, 2025
69ee7af
Fix core options
kasperpeulen Jun 4, 2025
5fdc6ab
Change codemod for new CSF1 support
kasperpeulen Jun 4, 2025
3ecf70c
Fix nextjs router types
kasperpeulen Jun 4, 2025
9ecff97
Fix name
kasperpeulen Jun 5, 2025
2182afc
Improve types
kasperpeulen Jun 5, 2025
295e5ca
@ts-expect-error hard
kasperpeulen Jun 5, 2025
29e4d59
Fix portable stories
kasperpeulen Jun 5, 2025
b41ef60
Remove some type casts
kasperpeulen Jun 5, 2025
cc6bc62
Empty story objects have shortcut
kasperpeulen Jun 5, 2025
dda04ad
Resolve require.resolve to config dir
kasperpeulen Jun 5, 2025
276ddde
Fix react parameter types
kasperpeulen Jun 5, 2025
e20b842
Fix nextjs-vite types
kasperpeulen Jun 5, 2025
411c198
Always provide configDir
kasperpeulen Jun 5, 2025
4f24c5e
Fix tests
kasperpeulen Jun 5, 2025
be60407
Fix types
kasperpeulen Jun 5, 2025
66d8f42
Fix next types
kasperpeulen Jun 5, 2025
1bd4318
Remove old definePreview
kasperpeulen Jun 5, 2025
2b9a7be
Merge branch 'next' into kasper/csf-parameters
kasperpeulen Jun 5, 2025
111e2b4
Merge branch 'next' into kasper/csf-parameters
kasperpeulen Jun 5, 2025
d524e95
Implement composed for stories
kasperpeulen Jun 6, 2025
a1170d7
Merge remote-tracking branch 'origin/kasper/csf-parameters' into kasp…
kasperpeulen Jun 6, 2025
da74e17
Refactor and explain
kasperpeulen Jun 6, 2025
bdc40b3
Remove csf factory docs
kasperpeulen Jun 6, 2025
7dd5736
Fix react addon inference
kasperpeulen Jun 6, 2025
9c22424
Address feedback
kasperpeulen Jun 10, 2025
9ab9f8b
Merge remote-tracking branch 'origin/next' into kasper/csf-parameters
kasperpeulen Jun 10, 2025
d70f67e
Roll back docs changes
kasperpeulen Jun 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions code/addons/a11y/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { definePreview } from 'storybook/preview-api';
import { definePreviewAddon } from 'storybook/internal/csf';

import * as addonAnnotations from './preview';
import type { A11yTypes } from './types';

export { PARAM_KEY } from './constants';
export * from './params';
export type { A11yParameters } from './types';
export type { A11yTypes } from './types';

export default () => definePreview(addonAnnotations);
export default () => definePreviewAddon<A11yTypes>(addonAnnotations);
7 changes: 6 additions & 1 deletion code/addons/a11y/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface A11yGlobals {
*
* @see https://storybook.js.org/docs/writing-tests/accessibility-testing
*/
a11y: {
a11y?: {
/**
* Prevent the addon from executing automated accessibility checks upon visiting a story. You
* can still trigger the checks from the addon panel.
Expand Down Expand Up @@ -51,3 +51,8 @@ export type EnhancedResults = Omit<AxeResults, 'incomplete' | 'passes' | 'violat
passes: EnhancedResult[];
violations: EnhancedResult[];
};

export interface A11yTypes {
parameters: A11yParameters;
globals: A11yGlobals;
}
7 changes: 4 additions & 3 deletions code/addons/docs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { definePreview } from 'storybook/preview-api';
import { definePreviewAddon } from 'storybook/internal/csf';

import * as addonAnnotations from './preview';
import type { DocsTypes } from './types';

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore (these types only work once the package is compiled)
export * from '@storybook/addon-docs/blocks';
export { DocsRenderer } from './DocsRenderer';
export type { DocsParameters } from './types';
export type { DocsTypes };

export default () => definePreview(addonAnnotations);
export default () => definePreviewAddon<DocsTypes>(addonAnnotations);
10 changes: 7 additions & 3 deletions code/addons/docs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export interface DocsParameters {
*
* @see https://storybook.js.org/docs/api/doc-blocks/doc-block-canvas
*/
canvas?: CanvasBlockParameters;
canvas?: Partial<CanvasBlockParameters>;

/**
* Controls block configuration
Expand Down Expand Up @@ -195,14 +195,14 @@ export interface DocsParameters {
*
* @see https://storybook.js.org/docs/api/doc-blocks/doc-block-source
*/
source?: SourceBlockParameters;
source?: Partial<SourceBlockParameters>;

/**
* Story configuration
*
* @see https://storybook.js.org/docs/api/doc-blocks/doc-block-story
*/
story?: StoryBlockParameters;
story?: Partial<StoryBlockParameters>;

/**
* The subtitle displayed when shown in docs page
Expand All @@ -219,3 +219,7 @@ export interface DocsParameters {
title?: string;
};
}

export interface DocsTypes {
parameters: DocsParameters;
}
4 changes: 2 additions & 2 deletions code/addons/links/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { definePreview } from 'storybook/preview-api';
import { definePreviewAddon } from 'storybook/internal/csf';

import * as addonAnnotations from './preview';

export { linkTo, hrefTo, withLinks, navigate } from './utils';

export default () => definePreview(addonAnnotations);
export default () => definePreviewAddon(addonAnnotations);
4 changes: 2 additions & 2 deletions code/addons/pseudo-states/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { definePreview } from 'storybook/preview-api';
import { definePreviewAddon } from 'storybook/internal/csf';

import * as addonAnnotations from './preview';

export { PARAM_KEY } from './constants';

export default () => definePreview(addonAnnotations);
export default () => definePreviewAddon(addonAnnotations);
7 changes: 4 additions & 3 deletions code/addons/themes/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { definePreview } from 'storybook/preview-api';
import { definePreviewAddon } from 'storybook/internal/csf';

import * as addonAnnotations from './preview';
import type { ThemesTypes } from './types';

export type { ThemesGlobals, ThemesParameters } from './types';
export type { ThemesTypes } from './types';

export default () => definePreview(addonAnnotations);
export default () => definePreviewAddon<ThemesTypes>(addonAnnotations);

export * from './decorators';
2 changes: 1 addition & 1 deletion code/addons/themes/src/theme-switcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from './constants';
import type { ThemesParameters as Parameters, ThemeAddonState } from './types';

type ThemesParameters = Parameters['themes'];
type ThemesParameters = NonNullable<Parameters['themes']>;

const IconButtonLabel = styled.div(({ theme }) => ({
fontSize: theme.typography.size.s2 - 1,
Expand Down
7 changes: 6 additions & 1 deletion code/addons/themes/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface ThemesParameters {
*
* @see https://github.com/storybookjs/storybook/blob/next/code/addons/themes/README.md
*/
themes: {
themes?: {
/** Remove the addon panel and disable the addon's behavior */
disable?: boolean;
/** Which theme to override for the story */
Expand All @@ -21,3 +21,8 @@ export interface ThemesGlobals {
/** Which theme to override for the story */
theme?: string;
}

export interface ThemesTypes {
parameters: ThemesParameters;
globals: ThemesGlobals;
}
6 changes: 2 additions & 4 deletions code/addons/vitest/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { definePreview } from 'storybook/preview-api';
import { definePreviewAddon } from 'storybook/internal/csf';

export default () => definePreview({});

export type { TestParameters } from './types';
export default () => definePreviewAddon({});
15 changes: 0 additions & 15 deletions code/addons/vitest/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@ import type { experimental_UniversalStore } from 'storybook/internal/core-server
import type { PreviewAnnotation, StoryId } from 'storybook/internal/types';
import type { API_HashEntry } from 'storybook/internal/types';

export interface TestParameters {
/**
* Test addon configuration
*
* @see https://storybook.js.org/docs/next/writing-tests/integrations/vitest-addon
*/
test: {
/** Ignore unhandled errors during test execution */
dangerouslyIgnoreUnhandledErrors?: boolean;

/** Whether to throw exceptions coming from the play function */
throwPlayFunctionExceptions?: boolean;
};
}

export interface VitestError extends Error {
VITEST_TEST_PATH?: string;
VITEST_TEST_NAME?: string;
Expand Down
2 changes: 0 additions & 2 deletions code/core/src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export * from './constants';
export * from './models';
export * from './runtime';

export type { ActionsParameters } from './types';
7 changes: 5 additions & 2 deletions code/core/src/actions/preview.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { definePreview } from 'storybook/preview-api';
import { definePreviewAddon } from 'storybook/internal/csf';

import * as addArgs from './addArgs';
import * as loaders from './loaders';
import type { ActionsTypes } from './types';

export { ActionsTypes };

export default () =>
definePreview({
definePreviewAddon<ActionsTypes>({
...addArgs,
...loaders,
});
6 changes: 5 additions & 1 deletion code/core/src/actions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface ActionsParameters {
*
* @see https://storybook.js.org/docs/essentials/actions#parameters
*/
actions: {
actions?: {
/**
* Create actions for each arg that matches the regex. (**NOT recommended, see below**)
*
Expand Down Expand Up @@ -36,3 +36,7 @@ export interface ActionsParameters {
handles?: string[];
};
}

export interface ActionsTypes {
parameters: ActionsParameters;
}
2 changes: 1 addition & 1 deletion code/core/src/backgrounds/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const withBackgroundAndGrid: DecoratorFunction = (StoryFn, context) => {
options = DEFAULT_BACKGROUNDS,
disable,
grid = defaultGrid,
} = (parameters[PARAM_KEY] || {}) as BackgroundsParameters['backgrounds'];
} = (parameters[PARAM_KEY] || {}) as NonNullable<BackgroundsParameters['backgrounds']>;
const data = globals[PARAM_KEY] || {};
const backgroundName: string | undefined = typeof data === 'string' ? data : data?.value;

Expand Down
6 changes: 1 addition & 5 deletions code/core/src/backgrounds/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import addonAnnotations from './preview';

export default addonAnnotations;

export type { BackgroundsParameters, BackgroundsGlobals } from './types';
export {};
8 changes: 5 additions & 3 deletions code/core/src/backgrounds/preview.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { definePreview } from 'storybook/preview-api';
import { definePreviewAddon } from 'storybook/internal/csf';

import { PARAM_KEY } from './constants';
import { withBackgroundAndGrid } from './decorator';
import type { BackgroundsParameters, GlobalState } from './types';
import type { BackgroundTypes, BackgroundsParameters, GlobalState } from './types';

const decorators = globalThis.FEATURES?.backgrounds ? [withBackgroundAndGrid] : [];

Expand All @@ -21,8 +21,10 @@ const initialGlobals: Record<string, GlobalState> = {
[PARAM_KEY]: { value: undefined, grid: false },
};

export type { BackgroundTypes };

export default () =>
definePreview({
definePreviewAddon<BackgroundTypes>({
decorators,
parameters,
initialGlobals,
Expand Down
19 changes: 16 additions & 3 deletions code/core/src/backgrounds/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@ export interface GridConfig {
offsetY?: number;
}

export type GlobalState = { value: string | undefined; grid: boolean };
export type GlobalState = { value: string | undefined; grid?: boolean };
export type GlobalStateUpdate = Partial<GlobalState>;

export interface BackgroundsParameters {
[PARAM_KEY]: {
/**
* Backgrounds configuration
*
* @see https://storybook.js.org/docs/essentials/backgrounds#parameters
*/
backgrounds?: {
/** Default background color */
default?: string;

/** Remove the addon panel and disable the addon's behavior */
disable?: boolean;

Expand All @@ -37,5 +45,10 @@ export interface BackgroundsGlobals {
*
* @see https://storybook.js.org/docs/essentials/backgrounds#globals
*/
[PARAM_KEY]: GlobalState | GlobalState['value'];
[PARAM_KEY]?: GlobalState | GlobalState['value'];
}

export interface BackgroundTypes {
parameters: BackgroundsParameters;
globals: BackgroundsGlobals;
}
40 changes: 19 additions & 21 deletions code/core/src/common/utils/get-addon-annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,24 @@ export function getAnnotationsName(addonName: string): string {
return cleanedUpName;
}

export async function getAddonAnnotations(addon: string) {
export async function getAddonAnnotations(addon: string, configDir: string) {
const data = {
// core addons will have a function as default export in index entrypoint
importPath: addon,
importName: getAnnotationsName(addon),
isCoreAddon: isCorePackage(addon),
};

if (!data.isCoreAddon) {
// for backwards compatibility, if it's not a core addon we use /preview entrypoint
data.importPath = `${addon}/preview`;
}

// If the preview endpoint doesn't exist, we don't need to add the addon to definePreview
try {
const data = {
// core addons will have a function as default export in index entrypoint
importPath: addon,
importName: getAnnotationsName(addon),
isCoreAddon: isCorePackage(addon),
};

if (addon === '@storybook/addon-essentials') {
return data;
} else if (!data.isCoreAddon) {
// for backwards compatibility, if it's not a core addon we use /preview entrypoint
data.importPath = `${addon}/preview`;
}

require.resolve(path.join(addon, 'preview'));

return data;
} catch (err) {}

return null;
require.resolve(path.join(addon, 'preview'), { paths: [configDir] });
} catch (err) {
return null;
}
return data;
}
12 changes: 7 additions & 5 deletions code/core/src/common/utils/sync-main-preview-addons.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ describe('getSyncedStorybookAddons', () => {
addons: ['custom-addon', '@storybook/addon-a11y'],
};

const configDir = '/user/storybook/.storybook';

it('should sync addons between main and preview', async () => {
const preview = loadConfig(`
import * as myAddonAnnotations from "custom-addon/preview";
Expand All @@ -36,7 +38,7 @@ describe('getSyncedStorybookAddons', () => {
return { importName: 'addonA11yAnnotations', importPath: '@storybook/addon-a11y/preview' };
});

const result = await getSyncedStorybookAddons(mainConfig, preview);
const result = await getSyncedStorybookAddons(mainConfig, preview, configDir);
expect(printConfig(result).code).toMatchInlineSnapshot(`
import * as addonA11yAnnotations from "@storybook/addon-a11y/preview";
import * as myAddonAnnotations from "custom-addon/preview";
Expand Down Expand Up @@ -66,7 +68,7 @@ describe('getSyncedStorybookAddons', () => {
};
});

const result = await getSyncedStorybookAddons(mainConfig, preview);
const result = await getSyncedStorybookAddons(mainConfig, preview, configDir);
expect(printConfig(result).code).toMatchInlineSnapshot(`
import addonA11yAnnotations from "@storybook/addon-a11y";
import * as myAddonAnnotations from "custom-addon/preview";
Expand All @@ -92,7 +94,7 @@ describe('getSyncedStorybookAddons', () => {
return { importName: 'addonA11yAnnotations', importPath: '@storybook/addon-a11y/preview' };
});

const result = await getSyncedStorybookAddons(mainConfig, preview);
const result = await getSyncedStorybookAddons(mainConfig, preview, configDir);
expect(printConfig(result).code).toMatchInlineSnapshot(`
import * as addonA11yAnnotations from "@storybook/addon-a11y/preview";
import { definePreview } from "@storybook/react/preview";
Expand Down Expand Up @@ -122,7 +124,7 @@ describe('getSyncedStorybookAddons', () => {
return { importName: 'addonA11yAnnotations', importPath: '@storybook/addon-a11y/preview' };
});

const result = await getSyncedStorybookAddons(mainConfig, preview);
const result = await getSyncedStorybookAddons(mainConfig, preview, configDir);
const transformedCode = normalizeLineBreaks(printConfig(result).code);

expect(transformedCode).toMatch(originalCode);
Expand All @@ -144,7 +146,7 @@ describe('getSyncedStorybookAddons', () => {
return { importName: 'addonA11yAnnotations', importPath: '@storybook/addon-a11y/preview' };
});

const result = await getSyncedStorybookAddons(mainConfig, preview);
const result = await getSyncedStorybookAddons(mainConfig, preview, configDir);
const transformedCode = normalizeLineBreaks(printConfig(result).code);

expect(transformedCode).toMatch(originalCode);
Expand Down
Loading