-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Source-loader: Handle template strings in CSF title #8995
Source-loader: Handle template strings in CSF title #8995
Conversation
This pull request is being automatically deployed with ZEIT Now (learn more). 🔍 Inspect: https://zeit.co/storybook/monorepo/hxwf1ve3e |
} | ||
// if a tagged template string. | ||
if (titleValue.type === 'TemplateLiteral' && titleValue.quasis.length > 0) { | ||
title = titleValue.quasis[0].value.raw; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose the support is actually quite limited?
import mdxNotes from '../notes/notes.mdx';
import { DocgenButton } from '../../components/DocgenButton';
const stories = () => 'Stories';
export default {
title: `Addons/Docs/${stories()}`,
component: DocgenButton,
};
wouldn't actually work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
works, I tried the following more real-life examples:
const docsTitle = title => `Docs/${title}`;
export default {
title: `Addons/${docsTitle('Stories')}`,
};
or
import { DocgenButton } from '../../components/DocgenButton';
export default {
title: `Addons/Docs/${DocgenButton.displayName}`,
};
and similar.
For other cases like expressions, dynamic functions etc - I assume there is some library that does ast node value evaluation, but I couldn't find one.
I checked in a better example and made the behavior backwards compatible for non-strings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about paths.macro
? Can it evaluate that correctly?
import * as React from 'react'
import base from 'paths.macro'
export default {
title: `${base}`
}
export const example = () => <div />
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The evaluation itself works fine. However there are some rules for titles - it can not finish in /
.
for example we have:
import base from 'paths.macro'
that evaluates to /stories/addon-docs/
In the case those will work:
title: `Docs${base}Story`,
title: `${base}Story`,
However currently this will not work directly (ends in /
):
title: `Docs${base}`
…ster/storybook into csf-title-template-string
@atanasster can you check the failing snapshot? |
@shilman - I reverted the snapshot and it works now. |
@atanasster @tmeasday Any idea why these are showing up as new stories in Chromatic? I tried modifying the capitalization to match the previous version, but it didn't seem to change anything. |
@shilman sorry, I don't know chromatic. can I run it locally on my machine and see the errors? |
@shilman it's because the previous build didn't have the stories with the old capitalisation. Try merging in the latest |
Issue: #7932
What I did
Handle case for template string while parsing CSF ast
Added template string example to story
How to test