-
-
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.
refactor(store): move csf related logic to its own folder
- Loading branch information
Showing
16 changed files
with
89 additions
and
69 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
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,9 @@ | ||
import { ArgTypes } from '@storybook/csf'; | ||
|
||
export const getValuesFromArgTypes = (argTypes: ArgTypes = {}) => | ||
Object.entries(argTypes).reduce((acc, [arg, { defaultValue }]) => { | ||
if (typeof defaultValue !== 'undefined') { | ||
acc[arg] = defaultValue; | ||
} | ||
return acc; | ||
}, {} as ArgTypes); |
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,7 @@ | ||
export * from './normalizeInputTypes'; | ||
export * from './normalizeStory'; | ||
export * from './processCSFFile'; | ||
export * from './prepareStory'; | ||
export * from './normalizeComponentAnnotations'; | ||
export * from './normalizeProjectAnnotations'; | ||
export * from './getValuesFromArgTypes'; |
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,22 @@ | ||
import { sanitize, AnyFramework } from '@storybook/csf'; | ||
|
||
import { ModuleExports, NormalizedComponentAnnotations } from '../types'; | ||
import { normalizeInputTypes } from './normalizeInputTypes'; | ||
|
||
export function normalizeComponentAnnotations<TFramework extends AnyFramework>( | ||
defaultExport: ModuleExports['default'], | ||
title: string = defaultExport.title, | ||
importPath?: string | ||
): NormalizedComponentAnnotations<TFramework> { | ||
const { id, argTypes } = defaultExport; | ||
return { | ||
id: sanitize(id || title), | ||
...defaultExport, | ||
title, | ||
...(argTypes && { argTypes: normalizeInputTypes(argTypes) }), | ||
parameters: { | ||
fileName: importPath, | ||
...defaultExport.parameters, | ||
}, | ||
}; | ||
} |
File renamed without changes.
File renamed without changes.
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,25 @@ | ||
import { AnyFramework, ProjectAnnotations } from '@storybook/csf'; | ||
import { inferControls, NormalizedProjectAnnotations, normalizeInputTypes } from '..'; | ||
import { inferArgTypes } from '../inferArgTypes'; | ||
|
||
export function normalizeProjectAnnotations<TFramework extends AnyFramework>({ | ||
argTypes, | ||
globalTypes, | ||
argTypesEnhancers, | ||
...annotations | ||
}: ProjectAnnotations<TFramework>): NormalizedProjectAnnotations<TFramework> { | ||
return { | ||
...(argTypes && { argTypes: normalizeInputTypes(argTypes) }), | ||
...(globalTypes && { globalTypes: normalizeInputTypes(globalTypes) }), | ||
argTypesEnhancers: [ | ||
...(argTypesEnhancers || []), | ||
inferArgTypes, | ||
// inferControls technically should only run if the user is using the controls addon, | ||
// and so should be added by a preset there. However, as it seems some code relies on controls | ||
// annotations (in particular the angular implementation's `cleanArgsDecorator`), for backwards | ||
// compatibility reasons, we will leave this in the store until 7.0 | ||
inferControls, | ||
], | ||
...annotations, | ||
}; | ||
} |
File renamed without changes.
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
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
File renamed without changes.
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