Skip to content
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
6 changes: 4 additions & 2 deletions code/addons/docs/src/blocks/blocks/Stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { FC, ReactElement } from 'react';
import React, { useContext } from 'react';

import { Tag } from 'storybook/internal/preview-api';

import { styled } from 'storybook/theming';

import { DocsContext } from './DocsContext';
Expand Down Expand Up @@ -43,11 +45,11 @@ export const Stories: FC<StoriesProps> = ({ title = 'Stories', includePrimary =
// The new behavior here is that if NONE of the stories in the autodocs page are tagged
// with 'autodocs', we show all stories. If ANY of the stories have autodocs then we use
// the new behavior.
const hasAutodocsTaggedStory = stories.some((story) => story.tags?.includes('autodocs'));
const hasAutodocsTaggedStory = stories.some((story) => story.tags?.includes(Tag.AUTODOCS));
if (hasAutodocsTaggedStory) {
// Don't show stories where mount is used in docs.
// As the play function is not running in docs, and when mount is used, the mounting is happening in play itself.
stories = stories.filter((story) => story.tags?.includes('autodocs') && !story.usesMount);
stories = stories.filter((story) => story.tags?.includes(Tag.AUTODOCS) && !story.usesMount);
}

if (!includePrimary) {
Expand Down
7 changes: 4 additions & 3 deletions code/addons/docs/src/blocks/blocks/usePrimaryStory.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import { describe, expect, it, vi } from 'vitest';
import React from 'react';
import type { FC, PropsWithChildren } from 'react';

import { Tag } from 'storybook/internal/core-server';
import type { PreparedStory } from 'storybook/internal/types';

import type { DocsContextProps } from './DocsContext';
import { DocsContext } from './DocsContext';
import { usePrimaryStory } from './usePrimaryStory';

const stories: Record<string, Partial<PreparedStory>> = {
story1: { name: 'Story One', tags: ['!autodocs'] },
story2: { name: 'Story Two', tags: ['autodocs'] },
story3: { name: 'Story Three', tags: ['autodocs'] },
story1: { name: 'Story One', tags: [`!${Tag.AUTODOCS}`] },
story2: { name: 'Story Two', tags: [Tag.AUTODOCS] },
story3: { name: 'Story Three', tags: [Tag.AUTODOCS] },
story4: { name: 'Story Four', tags: [] },
};

Expand Down
3 changes: 2 additions & 1 deletion code/addons/docs/src/blocks/blocks/usePrimaryStory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useContext } from 'react';

import { Tag } from 'storybook/internal/preview-api';
import type { PreparedStory } from 'storybook/internal/types';

import { DocsContext } from './DocsContext';
Expand All @@ -11,5 +12,5 @@ import { DocsContext } from './DocsContext';
export const usePrimaryStory = (): PreparedStory | undefined => {
const context = useContext(DocsContext);
const stories = context.componentStories();
return stories.find((story) => story.tags.includes('autodocs'));
return stories.find((story) => story.tags.includes(Tag.AUTODOCS));
};
Loading