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

Addon-docs: Apply transformSource to any SourceType #12375

Merged
merged 4 commits into from
Sep 10, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions addons/docs/src/blocks/Source.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ const getSnippet = (snippet: string, storyContext?: StoryContext): string => {

// if user has explicitly set this as dynamic, use snippet
if (type === SourceType.DYNAMIC) {
return snippet;
return parameters.docs?.transformSource?.(snippet, storyContext) || snippet;
}

// if this is an args story and there's a snippet
if (type === SourceType.AUTO && snippet && isArgsStory) {
return snippet;
return parameters.docs?.transformSource?.(snippet, storyContext) || snippet;
}

// otherwise, use the source code logic
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export default {
title: 'Addons/Docs/transformSource',
parameters: {
docs: {
transformSource(src, ctx) {
return `// We transformed this!\n const example = ${src};`;
},
},
},
};

export const code = () => 'StoryType "CODE" story which has source transformed';
code.parameters = {
docs: { source: { type: 'code' } },
};

export const dynamic = () => 'StoryType "DYNAMIC" story which has source transformed';
dynamic.parameters = {
docs: { source: { type: 'dynamic' } },
};

export const auto = () => 'StoryType "AUTO" story which has source transformed';
dynamic.parameters = {
docs: { source: { type: 'auto' } },
};