Skip to content

Commit

Permalink
Expose more types in the renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperpeulen committed Nov 14, 2022
1 parent b0c013a commit 4d637a5
Show file tree
Hide file tree
Showing 30 changed files with 157 additions and 76 deletions.
2 changes: 1 addition & 1 deletion code/addons/links/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"@storybook/addons": "7.0.0-alpha.49",
"@storybook/client-logger": "7.0.0-alpha.49",
"@storybook/core-events": "7.0.0-alpha.49",
"@storybook/csf": "0.0.2-next.5",
"@storybook/csf": "0.0.2-next.7",
"@storybook/router": "7.0.0-alpha.49",
"@storybook/types": "7.0.0-alpha.49",
"global": "^4.4.0",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/storyshots/storyshots-puppeteer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"dependencies": {
"@axe-core/puppeteer": "^4.2.0",
"@storybook/csf": "0.0.2-next.5",
"@storybook/csf": "0.0.2-next.7",
"@storybook/node-logger": "7.0.0-alpha.49",
"@storybook/types": "7.0.0-alpha.49",
"@types/jest-image-snapshot": "^4.1.3",
Expand Down
19 changes: 17 additions & 2 deletions code/frameworks/angular/src/client/public-types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { AnnotatedStoryFn, Args, ComponentAnnotations, StoryAnnotations } from '@storybook/types';
import {
AnnotatedStoryFn,
Args,
ComponentAnnotations,
DecoratorFunction,
LoaderFunction,
StoryAnnotations,
StoryContext as GenericStoryContext,
StrictArgs,
} from '@storybook/types';
import { AngularRenderer } from './types';

export type { Args, ArgTypes } from '@storybook/types';
export type { Args, ArgTypes, Parameters, StrictArgs } from '@storybook/types';
export type { Parameters as AngularParameters } from './types';
export type { AngularRenderer };

/**
* Metadata to configure the stories for a component.
Expand Down Expand Up @@ -34,3 +45,7 @@ export type StoryObj<TArgs = Args> = StoryAnnotations<AngularRenderer, TArgs>;
* @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
*/
export type Story<TArgs = Args> = StoryFn<TArgs>;

export type Decorator<TArgs = StrictArgs> = DecoratorFunction<AngularRenderer, TArgs>;
export type Loader<TArgs = StrictArgs> = LoaderFunction<AngularRenderer, TArgs>;
export type StoryContext<TArgs = StrictArgs> = GenericStoryContext<AngularRenderer, TArgs>;
2 changes: 1 addition & 1 deletion code/lib/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@storybook/channels": "7.0.0-alpha.49",
"@storybook/client-logger": "7.0.0-alpha.49",
"@storybook/core-events": "7.0.0-alpha.49",
"@storybook/csf": "0.0.2-next.5",
"@storybook/csf": "0.0.2-next.7",
"@storybook/router": "7.0.0-alpha.49",
"@storybook/theming": "7.0.0-alpha.49",
"@storybook/types": "7.0.0-alpha.49",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/client-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"dependencies": {
"@storybook/addons": "7.0.0-alpha.49",
"@storybook/client-logger": "7.0.0-alpha.49",
"@storybook/csf": "0.0.2-next.5",
"@storybook/csf": "0.0.2-next.7",
"@storybook/store": "7.0.0-alpha.49",
"@storybook/types": "7.0.0-alpha.49",
"@types/qs": "^6.9.5",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/codemod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"dependencies": {
"@babel/types": "^7.12.11",
"@storybook/csf": "0.0.2-next.5",
"@storybook/csf": "0.0.2-next.7",
"@storybook/csf-tools": "7.0.0-alpha.49",
"@storybook/node-logger": "7.0.0-alpha.49",
"@storybook/types": "7.0.0-alpha.49",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/core-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@storybook/client-api": "7.0.0-alpha.49",
"@storybook/client-logger": "7.0.0-alpha.49",
"@storybook/core-events": "7.0.0-alpha.49",
"@storybook/csf": "0.0.2-next.5",
"@storybook/csf": "0.0.2-next.7",
"@storybook/preview-web": "7.0.0-alpha.49",
"@storybook/store": "7.0.0-alpha.49",
"@storybook/types": "7.0.0-alpha.49",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/core-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@storybook/core-client": "7.0.0-alpha.49",
"@storybook/core-common": "7.0.0-alpha.49",
"@storybook/core-events": "7.0.0-alpha.49",
"@storybook/csf": "0.0.2-next.5",
"@storybook/csf": "0.0.2-next.7",
"@storybook/csf-tools": "7.0.0-alpha.49",
"@storybook/docs-mdx": "0.0.1-canary.12433cf.0",
"@storybook/node-logger": "7.0.0-alpha.49",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/csf-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"dependencies": {
"@babel/types": "^7.12.11",
"@storybook/csf": "0.0.2-next.5",
"@storybook/csf": "0.0.2-next.7",
"@storybook/types": "7.0.0-alpha.49",
"fs-extra": "^9.0.1",
"ts-dedent": "^2.0.0"
Expand Down
2 changes: 1 addition & 1 deletion code/lib/source-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {
"@storybook/csf": "0.0.2-next.5",
"@storybook/csf": "0.0.2-next.7",
"@storybook/types": "7.0.0-alpha.49",
"estraverse": "^5.2.0",
"lodash": "^4.17.21",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@storybook/addons": "7.0.0-alpha.49",
"@storybook/client-logger": "7.0.0-alpha.49",
"@storybook/core-events": "7.0.0-alpha.49",
"@storybook/csf": "0.0.2-next.5",
"@storybook/csf": "0.0.2-next.7",
"@storybook/types": "7.0.0-alpha.49",
"dequal": "^2.0.2",
"global": "^4.4.0",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"file-system-cache": "^2.0.0"
},
"devDependencies": {
"@storybook/csf": "0.0.2-next.5",
"@storybook/csf": "0.0.2-next.7",
"@types/node": "^16.0.0",
"synchronous-promise": "^2.0.15",
"typescript": "~4.6.3"
Expand Down
15 changes: 10 additions & 5 deletions code/lib/types/src/modules/csf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type {
LegacyStoryAnnotationsOrFn,
LegacyStoryFn,
LoaderFunction,
Parameters as ParametersBase,
Parameters,
PartialStoryFn,
PlayFunction,
PlayFunctionContext,
Expand Down Expand Up @@ -51,6 +51,7 @@ import type {
StoryIdentifier,
StoryKind,
StoryName,
StrictArgs,
StrictArgTypes,
StrictGlobalTypes,
StrictInputType,
Expand Down Expand Up @@ -83,6 +84,7 @@ export type {
LegacyStoryAnnotationsOrFn,
LegacyStoryFn,
LoaderFunction,
Parameters,
PartialStoryFn,
PlayFunction,
PlayFunctionContext,
Expand All @@ -109,6 +111,7 @@ export type {
StoryIdentifier,
StoryKind,
StoryName,
StrictArgs,
StrictArgTypes,
StrictGlobalTypes,
StrictInputType,
Expand All @@ -135,13 +138,15 @@ export type ViewMode = ViewModeBase | 'story' | 'info' | 'settings' | string | u

type Layout = 'centered' | 'fullscreen' | 'padded' | 'none';

export interface Parameters extends ParametersBase {
fileName?: string;
export interface StorybookParameters {
options?: Addon_OptionsParameter;
/** The layout property defines basic styles added to the preview body where the story is rendered. If you pass 'none', no styles are applied. */
layout?: Layout;
docsOnly?: boolean;
[key: string]: any;
}

export interface StorybookInternalParameters extends StorybookParameters {
fileName?: string;
docsOnly?: true;
}

export type Path = string;
2 changes: 1 addition & 1 deletion code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
"@storybook/core-events": "workspace:*",
"@storybook/core-server": "workspace:*",
"@storybook/core-webpack": "workspace:*",
"@storybook/csf": "0.0.2-next.5",
"@storybook/csf": "0.0.2-next.7",
"@storybook/csf-plugin": "workspace:*",
"@storybook/csf-tools": "workspace:*",
"@storybook/docs-tools": "workspace:*",
Expand Down
12 changes: 10 additions & 2 deletions code/renderers/html/src/public-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import type {
AnnotatedStoryFn,
Args,
ComponentAnnotations,
DecoratorFunction,
LoaderFunction,
StoryAnnotations,
StoryContext as GenericStoryContext,
StrictArgs,
} from '@storybook/types';

import type { HtmlRenderer } from './types';

export type { Args, ArgTypes, Parameters } from '@storybook/types';
export type { Args, ArgTypes, Parameters, StrictArgs } from '@storybook/types';
export type { HtmlRenderer };

/**
* Metadata to configure the stories for a component.
Expand Down Expand Up @@ -40,3 +44,7 @@ export type StoryObj<TArgs = Args> = StoryAnnotations<HtmlRenderer, TArgs>;
* @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
*/
export type Story<TArgs = Args> = StoryFn<TArgs>;

export type Decorator<TArgs = StrictArgs> = DecoratorFunction<HtmlRenderer, TArgs>;
export type Loader<TArgs = StrictArgs> = LoaderFunction<HtmlRenderer, TArgs>;
export type StoryContext<TArgs = StrictArgs> = GenericStoryContext<HtmlRenderer, TArgs>;
11 changes: 10 additions & 1 deletion code/renderers/preact/src/public-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ import type {
Args,
ComponentAnnotations,
StoryAnnotations,
DecoratorFunction,
LoaderFunction,
StoryContext as GenericStoryContext,
StrictArgs,
} from '@storybook/types';
import type { PreactRenderer } from './types';

export type { Args, ArgTypes, Parameters, StoryContext } from '@storybook/types';
export type { Args, ArgTypes, Parameters, StrictArgs } from '@storybook/types';
export type { PreactRenderer };

/**
* Metadata to configure the stories for a component.
Expand Down Expand Up @@ -39,3 +44,7 @@ export type StoryObj<TArgs = Args> = StoryAnnotations<PreactRenderer, TArgs>;
* @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
*/
export type Story<TArgs = Args> = StoryFn<TArgs>;

export type Decorator<TArgs = StrictArgs> = DecoratorFunction<PreactRenderer, TArgs>;
export type Loader<TArgs = StrictArgs> = LoaderFunction<PreactRenderer, TArgs>;
export type StoryContext<TArgs = StrictArgs> = GenericStoryContext<PreactRenderer, TArgs>;
11 changes: 2 additions & 9 deletions code/renderers/react/src/public-api.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
/* eslint-disable prefer-destructuring */
import type {
Addon_ClientStoryApi,
Addon_Loadable,
Args,
DecoratorFunction,
} from '@storybook/types';
import { start } from '@storybook/core-client';
import type { Addon_ClientStoryApi, Addon_Loadable } from '@storybook/types';

import { renderToCanvas, render } from './render';
import { render, renderToCanvas } from './render';
import type { ReactRenderer } from './types';

interface ClientApi extends Addon_ClientStoryApi<ReactRenderer['storyResult']> {
Expand All @@ -28,5 +23,3 @@ export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
export const configure: ClientApi['configure'] = (...args) => api.configure(FRAMEWORK, ...args);
export const forceReRender: ClientApi['forceReRender'] = api.forceReRender;
export const raw: ClientApi['raw'] = api.clientApi.raw;

export type DecoratorFn<TArgs = Args> = DecoratorFunction<ReactRenderer, TArgs>;
9 changes: 4 additions & 5 deletions code/renderers/react/src/public-types.test.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { describe, test } from '@jest/globals';
import type { StoryAnnotations } from '@storybook/types';

import { satisfies } from '@storybook/core-common';
import type { StoryAnnotations } from '@storybook/types';
import { expectTypeOf } from 'expect-type';
import type { KeyboardEventHandler, ReactNode } from 'react';
import React from 'react';

import type { SetOptional } from 'type-fest';

import type { DecoratorFn } from './public-api';
import type { Meta, StoryObj } from './public-types';
import type { Decorator, Meta, StoryObj } from './public-types';
import type { ReactRenderer } from './types';

type ReactStory<Args, RequiredArgs> = StoryAnnotations<ReactRenderer, Args, RequiredArgs>;
Expand Down Expand Up @@ -141,7 +140,7 @@ describe('Story args can be inferred', () => {
expectTypeOf(Basic).toEqualTypeOf<Expected>();
});

const withDecorator: DecoratorFn<{ decoratorArg: number }> = (Story, { args }) => (
const withDecorator: Decorator<{ decoratorArg: number }> = (Story, { args }) => (
<>
Decorator: {args.decoratorArg}
<Story args={{ decoratorArg: 0 }} />
Expand All @@ -166,7 +165,7 @@ describe('Story args can be inferred', () => {
test('Correct args are inferred when type is widened for multiple decorators', () => {
type Props = ButtonProps & { decoratorArg: number; decoratorArg2: string };

const secondDecorator: DecoratorFn<{ decoratorArg2: string }> = (Story, { args }) => (
const secondDecorator: Decorator<{ decoratorArg2: string }> = (Story, { args }) => (
<>
Decorator: {args.decoratorArg2}
<Story />
Expand Down
17 changes: 14 additions & 3 deletions code/renderers/react/src/public-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import type {
ArgsFromMeta,
ArgsStoryFn,
ComponentAnnotations,
DecoratorFunction,
LoaderFunction,
StoryAnnotations,
StoryContext as GenericStoryContext,
StrictArgs,
} from '@storybook/types';

import type { ComponentProps, ComponentType, JSXElementConstructor } from 'react';
import type { SetOptional, Simplify } from 'type-fest';

import type { ReactRenderer } from './types';

export { ReactRenderer };
export type { Args, ArgTypes, Parameters, StrictArgs } from '@storybook/types';
export type { ReactRenderer };

type JSXElement = keyof JSX.IntrinsicElements | JSXElementConstructor<any>;

Expand Down Expand Up @@ -124,3 +127,11 @@ export type Story<TArgs = Args> = StoryFn<TArgs>;
* ```
*/
export type ComponentStory<T extends JSXElement> = ComponentStoryFn<T>;

/**
* @deprecated Use Decorator instead.
*/
export type DecoratorFn<TArgs = Args> = DecoratorFunction<ReactRenderer, TArgs>;
export type Decorator<TArgs = StrictArgs> = DecoratorFunction<ReactRenderer, TArgs>;
export type Loader<TArgs = StrictArgs> = LoaderFunction<ReactRenderer, TArgs>;
export type StoryContext<TArgs = StrictArgs> = GenericStoryContext<ReactRenderer, TArgs>;
11 changes: 10 additions & 1 deletion code/renderers/server/src/public-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import type {
Args,
ComponentAnnotations,
StoryAnnotations,
StoryContext as GenericStoryContext,
DecoratorFunction,
LoaderFunction,
StrictArgs,
} from '@storybook/types';
import type { ServerRenderer } from './types';

export type { Args, ArgTypes, Parameters, StoryContext } from '@storybook/types';
export type { Args, ArgTypes, Parameters, StrictArgs } from '@storybook/types';

/**
* Metadata to configure the stories for a component.
Expand Down Expand Up @@ -39,3 +43,8 @@ export type StoryObj<TArgs = Args> = StoryAnnotations<ServerRenderer, TArgs>;
* @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
*/
export type Story<TArgs = Args> = StoryFn<TArgs>;

export type { ServerRenderer };
export type Decorator<TArgs = StrictArgs> = DecoratorFunction<ServerRenderer, TArgs>;
export type Loader<TArgs = StrictArgs> = LoaderFunction<ServerRenderer, TArgs>;
export type StoryContext<TArgs = StrictArgs> = GenericStoryContext<ServerRenderer, TArgs>;
10 changes: 5 additions & 5 deletions code/renderers/svelte/src/public-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import type { ComponentAnnotations, StoryAnnotations } from '@storybook/types';
import { expectTypeOf } from 'expect-type';
import type { ComponentProps, SvelteComponentTyped } from 'svelte';
import Button from './__test__/Button.svelte';
import Decorator from './__test__/Decorator.svelte';
import Decorator1 from './__test__/Decorator.svelte';
import Decorator2 from './__test__/Decorator2.svelte';

import type { DecoratorFn, Meta, StoryObj } from './public-types';
import type { Decorator, Meta, StoryObj } from './public-types';
import type { SvelteRenderer } from './types';

type SvelteStory<Component extends SvelteComponentTyped, Args, RequiredArgs> = StoryAnnotations<
Expand Down Expand Up @@ -172,11 +172,11 @@ describe('Story args can be inferred', () => {
expectTypeOf(Basic).toEqualTypeOf<Expected>();
});

const withDecorator: DecoratorFn<{ decoratorArg: string }> = (
const withDecorator: Decorator<{ decoratorArg: string }> = (
storyFn,
{ args: { decoratorArg } }
) => ({
Component: Decorator,
Component: Decorator1,
props: { decoratorArg },
});

Expand All @@ -202,7 +202,7 @@ describe('Story args can be inferred', () => {
test('Correct args are inferred when type is widened for multiple decorators', () => {
type Props = ComponentProps<Button> & { decoratorArg: string; decoratorArg2: string };

const secondDecorator: DecoratorFn<{ decoratorArg2: string }> = (
const secondDecorator: Decorator<{ decoratorArg2: string }> = (
storyFn,
{ args: { decoratorArg2 } }
) => ({
Expand Down
Loading

0 comments on commit 4d637a5

Please sign in to comment.