-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
App-html: align types with addon, angular and react
- Loading branch information
1 parent
948f507
commit c70c1a9
Showing
6 changed files
with
64 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,37 @@ | ||
/* eslint-disable prefer-destructuring */ | ||
import { start } from '@storybook/core/client'; | ||
import { ClientStoryApi } from '@storybook/addons'; | ||
|
||
import './globals'; | ||
import render from './render'; | ||
import { StoryFnHtmlReturnType, IStorybookSection } from './types'; | ||
|
||
export type StoriesOfArgs = [string, typeof module]; | ||
|
||
export type LoadFnArgs = [RequireContext, typeof module, string]; | ||
const framework = 'html'; | ||
|
||
export interface RequireContext { | ||
keys(): string[]; | ||
(id: string): any; | ||
<T>(id: string): T; | ||
resolve(id: string): string; | ||
interface ClientApi extends ClientStoryApi<StoryFnHtmlReturnType> { | ||
setAddon(addon: any): void; | ||
configure(loaders: () => void, module: NodeModule): void; | ||
getStorybook(): IStorybookSection[]; | ||
clearDecorators(): void; | ||
forceReRender(): void; | ||
raw: () => any; // todo add type | ||
load: (req: any, m: NodeModule, framework: string) => void; | ||
} | ||
|
||
const { load: coreLoad, clientApi, configApi, forceReRender } = start(render); | ||
|
||
export const { | ||
setAddon, | ||
addDecorator, | ||
addParameters, | ||
clearDecorators, | ||
getStorybook, | ||
raw, | ||
} = clientApi; | ||
|
||
const framework = 'html'; | ||
export const storiesOf = (...args: StoriesOfArgs) => | ||
clientApi.storiesOf(...args).addParameters({ framework }); | ||
export const load = (...args: LoadFnArgs) => coreLoad(...args, framework); | ||
|
||
export const { configure } = configApi; | ||
export { forceReRender }; | ||
const api = start(render); | ||
|
||
export const storiesOf: ClientApi['storiesOf'] = (kind, m) => { | ||
return (api.clientApi.storiesOf(kind, m) as ReturnType<ClientApi['storiesOf']>).addParameters({ | ||
framework, | ||
}); | ||
}; | ||
|
||
export const load: ClientApi['load'] = (...args) => api.load(...args, framework); | ||
export const addDecorator: ClientApi['addDecorator'] = api.clientApi.addDecorator; | ||
export const addParameters: ClientApi['addParameters'] = api.clientApi.addParameters; | ||
export const clearDecorators: ClientApi['clearDecorators'] = api.clientApi.clearDecorators; | ||
export const setAddon: ClientApi['setAddon'] = api.clientApi.setAddon; | ||
export const configure: ClientApi['configure'] = api.configApi.configure; | ||
export const forceReRender: ClientApi['forceReRender'] = api.forceReRender; | ||
export const getStorybook: ClientApi['getStorybook'] = api.clientApi.getStorybook; | ||
export const raw: ClientApi['raw'] = api.clientApi.raw; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { StoryFn } from '@storybook/addons'; | ||
|
||
export type StoryFnHtmlReturnType = string | Node; | ||
|
||
export interface IStorybookStory { | ||
name: string; | ||
render: () => any; | ||
} | ||
|
||
export interface IStorybookSection { | ||
kind: string; | ||
stories: IStorybookStory[]; | ||
} | ||
|
||
export interface ShowErrorArgs { | ||
title: string; | ||
description: string; | ||
} | ||
|
||
export interface RenderMainArgs { | ||
storyFn: () => StoryFn<StoryFnHtmlReturnType>; | ||
selectedKind: string; | ||
selectedStory: string; | ||
showMain: () => void; | ||
showError: (args: ShowErrorArgs) => void; | ||
forceRender: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
declare module '@storybook/core/*'; | ||
declare module 'global'; | ||
declare module '*.json'; | ||
declare module '@storybook/core/client'; | ||
declare module '@storybook/core/server'; | ||
|
||
// will be provided by the webpack define plugin | ||
declare var NODE_ENV: string | undefined; |