Merge pull request #11 from ling1726/fix/story-name

fix: use `originalStoryFn.name` instead of `story` for import
This commit is contained in:
ling1726 2021-11-05 16:11:39 +01:00 коммит произвёл GitHub
Родитель 279366a1fd c1e1b9d03d
Коммит f8175e32d0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 6 добавлений и 2 удалений

Просмотреть файл

@ -32,7 +32,7 @@ const getDependencies = (fileContent: string, requiredDependencies: PackageDepen
return dependencies; return dependencies;
}; };
const displayToolState = (selector: string, context: any) => { const displayToolState = (selector: string, context: StoryContext) => {
let exportLink = document.createElement('a'); let exportLink = document.createElement('a');
exportLink.style.setProperty('position', 'absolute'); exportLink.style.setProperty('position', 'absolute');
exportLink.style.setProperty('bottom', '0'); exportLink.style.setProperty('bottom', '0');
@ -85,6 +85,7 @@ const displayToolState = (selector: string, context: any) => {
); );
return false; return false;
} }
console.log(context);
const defaultFileToPreview = encodeURIComponent('/example.tsx'); const defaultFileToPreview = encodeURIComponent('/example.tsx');
const codeSandboxParameters = getParameters({ const codeSandboxParameters = getParameters({
@ -99,7 +100,10 @@ const displayToolState = (selector: string, context: any) => {
}, },
'index.tsx': { 'index.tsx': {
isBinary: false, isBinary: false,
content: indexTsx.replace('STORY_NAME', context.story.replaceAll(' ', '')), // use originalStoryFn because users can override the `storyName` property.
// We need the name of the exported function, not the actual story
// https://github.com/microsoft/fluentui-storybook-addons/issues/12
content: indexTsx.replace('STORY_NAME', context.originalStoryFn.name.replaceAll(' ', '')),
}, },
'package.json': { 'package.json': {
isBinary: false, isBinary: false,