joshbolduc / vscode-story-explorer

Browse and preview Storybook stories inside VS Code
MIT License
29 stars 1 forks source link

feat: add support for CSF3 custom story names #1010

Closed joshbolduc closed 1 year ago

joshbolduc commented 1 year ago

The CSF parser did not previously require that stories be functions, so story detection already worked. However, overriding the story's name via the name property was not supported, nor was parsing CSF3-style objects for properties (like name):

StoryObject.storyName = 'Custom name';
const StoryObject = { storyName: 'Custom name' };

This commit recognizes name as a relevant property for CSF3 stories and adds basic logic to parse story objects, subject to Babel's evaluation limitations. (Notably, story objects that use object spread will not have story names detected, even if they are not part of the spread itself.)

This commit also attempts to handle differences in semantics between Storybook 6 and 7 as they relate to CSF2 and CSF3 custom display names. In particular, Storybook 7 enforces stricter rules around when to use name vs. storyName to override a story's display name.