HTML: Introduce setProjectAnnotations API

This commit is contained in:
Yann Braga 2024-08-16 12:45:59 +02:00
parent 18df216270
commit 0809eb5e2a
2 changed files with 42 additions and 0 deletions

View File

@ -2,6 +2,7 @@
import './globals';
export * from './public-types';
export * from './portable-stories';
// optimization: stop HMR propagation in webpack

View File

@ -0,0 +1,41 @@
import {
setProjectAnnotations as originalSetProjectAnnotations,
setDefaultProjectAnnotations,
} from 'storybook/internal/preview-api';
import type {
NamedOrDefaultProjectAnnotations,
NormalizedProjectAnnotations,
} from 'storybook/internal/types';
import * as INTERNAL_DEFAULT_PROJECT_ANNOTATIONS from './entry-preview';
import type { HtmlRenderer } from './types';
/**
* Function that sets the globalConfig of your storybook. The global config is the preview module of
* your .storybook folder.
*
* It should be run a single time, so that your global config (e.g. decorators) is applied to your
* stories when using `composeStories` or `composeStory`.
*
* Example:
*
* ```jsx
* // setup-file.js
* import { setProjectAnnotations } from '@storybook/preact';
* import projectAnnotations from './.storybook/preview';
*
* setProjectAnnotations(projectAnnotations);
* ```
*
* @param projectAnnotations - E.g. (import projectAnnotations from '../.storybook/preview')
*/
export function setProjectAnnotations(
projectAnnotations:
| NamedOrDefaultProjectAnnotations<any>
| NamedOrDefaultProjectAnnotations<any>[]
): NormalizedProjectAnnotations<HtmlRenderer> {
setDefaultProjectAnnotations(INTERNAL_DEFAULT_PROJECT_ANNOTATIONS);
return originalSetProjectAnnotations(
projectAnnotations
) as NormalizedProjectAnnotations<HtmlRenderer>;
}