Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSF: Allow default export without title or component attributes #26516

Merged
merged 1 commit into from Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions code/lib/csf-tools/src/CsfFile.test.ts
Expand Up @@ -619,15 +619,23 @@ describe('CsfFile', () => {
});

it('no metadata', () => {
expect(() =>
expect(
parse(
dedent`
export default { foo: '5' };
export const A = () => {};
export const B = () => {};
`
)
).toThrow('CSF: missing title/component');
).toMatchInlineSnapshot(`
meta:
title: Default Title
stories:
- id: default-title--a
name: A
- id: default-title--b
name: B
`);
});

it('dynamic titles', () => {
Expand Down
8 changes: 0 additions & 8 deletions code/lib/csf-tools/src/CsfFile.ts
Expand Up @@ -478,14 +478,6 @@ export class CsfFile {
throw new NoMetaError('missing default export', self._ast, self._fileName);
}

if (!self._meta.title && !self._meta.component) {
throw new Error(dedent`
CSF: missing title/component ${formatLocation(self._ast, self._fileName)}

More info: https://storybook.js.org/docs/react/writing-stories#default-export
`);
}

// default export can come at any point in the file, so we do this post processing last
const entries = Object.entries(self._stories);
self._meta.title = this._makeTitle(self._meta?.title as string);
Expand Down