Skip to content

Commit

Permalink
Docs: Add autodocs filter function parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
shilman committed Jan 2, 2024
1 parent e2c05c6 commit 685b825
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions code/addons/docs/src/preview.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import type { PreparedStory } from '@storybook/types';

export const parameters: any = {
docs: {
renderer: async () => {
const { DocsRenderer } = (await import('./DocsRenderer')) as any;
return new DocsRenderer();
},
autodocsFilter: (story: PreparedStory) => !story.parameters?.docs?.disable,
},
};
8 changes: 6 additions & 2 deletions code/ui/blocks/src/blocks/Stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ const StyledHeading: typeof Heading = styled(Heading)(({ theme }) => ({
}));

export const Stories: FC<StoriesProps> = ({ title = 'Stories', includePrimary = true }) => {
const { componentStories } = useContext(DocsContext);
const { componentStories, projectAnnotations, getStoryContext } = useContext(DocsContext);

let stories = componentStories().filter((story) => !story.parameters?.docs?.disable);
let stories = componentStories();
const { autodocsFilter } = projectAnnotations.parameters?.docs || {};
if (autodocsFilter) {
stories = stories.filter((story) => autodocsFilter(story, getStoryContext(story)));
}

if (!includePrimary) stories = stories.slice(1);

Expand Down

0 comments on commit 685b825

Please sign in to comment.