Skip to content

stories: fix api reference table #95396

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

Merged
merged 3 commits into from
Jul 14, 2025
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 static/app/components/core/alert/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import {Button} from 'sentry/components/core/button';
import {IconAdd, IconDelete, IconEdit} from 'sentry/icons';
import * as Storybook from 'sentry/stories';

import types from '!!type-loader!sentry/components/core/alert/index';
import APIReference from '!!type-loader!sentry/components/core/alert/index';

export {types};
export const types = {Alert: APIReference.Alert};

To create a basic alert, wrap your message in an `<Alert>` component and specify the appropriate type.

Expand Down
4 changes: 2 additions & 2 deletions static/app/components/core/button/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ import {
} from 'sentry/icons';
import * as Storybook from 'sentry/stories';

import types from '!!type-loader!sentry/components/core/button/index';
import APIReference from '!!type-loader!sentry/components/core/button/index';

export {types};
export const types = {Button: APIReference.Button};

To create a basic button, wrap text in a `<Button>` and pass an `onClick` callback.

Expand Down
34 changes: 28 additions & 6 deletions static/app/stories/view/storyExports.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {space} from 'sentry/styles/space';

import {StoryResources} from './storyResources';
import {StorySourceLinks} from './storySourceLinks';
import type {StoryDescriptor} from './useStoriesLoader';
import {isMDXStory, type StoryDescriptor} from './useStoriesLoader';
import type {StoryExports as StoryExportValues} from './useStory';
import {StoryContextProvider, useStory} from './useStory';

Expand Down Expand Up @@ -47,11 +47,11 @@ function StoryLayout() {
function StoryTitlebar() {
const {story} = useStory();

if (!isMDXStory(story)) return null;

const title = story.exports.frontmatter?.title;
const description = story.exports.frontmatter?.description;

if (!story.filename.endsWith('.mdx')) return null;

return (
<StoryHeader>
<StoryGrid>
Expand All @@ -74,7 +74,8 @@ function StoryTabList() {
<TabList>
<TabList.Item key="usage">{t('Usage')}</TabList.Item>
{story.exports.types ? <TabList.Item key="api">{t('API')}</TabList.Item> : null}
{story.exports.frontmatter?.resources ? (

{isMDXStory(story) && story.exports.frontmatter?.resources ? (
<TabList.Item key="resources">{t('Resources')}</TabList.Item>
) : null}
</TabList>
Expand Down Expand Up @@ -109,6 +110,7 @@ function StoryUsage() {
filename,
},
} = useStory();

return (
<Fragment>
{Story && (
Expand All @@ -129,9 +131,10 @@ function StoryUsage() {
return null;
}
if (typeof MaybeComponent === 'function') {
const Component = MaybeComponent as React.ComponentType;
return (
<Storybook.Section key={name}>
<MaybeComponent />
<Component />
</Storybook.Section>
);
}
Expand All @@ -148,7 +151,26 @@ function StoryUsage() {
function StoryAPI() {
const {story} = useStory();
if (!story.exports.types) return null;
return <Storybook.APIReference types={story.exports.types} />;

if (
typeof story.exports.types === 'object' &&
story.exports.types !== null &&
'filename' in story.exports.types
) {
return (
<Storybook.APIReference
types={story.exports.types as TypeLoader.ComponentDocWithFilename}
/>
);
}

return (
<Fragment>
{Object.entries(story.exports.types).map(([key, value]) => {
return <Storybook.APIReference key={key} types={value} />;
})}
</Fragment>
);
}

const StoryHeader = styled('header')`
Expand Down
8 changes: 5 additions & 3 deletions static/app/stories/view/storyFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@ import styled from '@emotion/styled';
import {LinkButton} from 'sentry/components/core/button/linkButton';
import {Flex} from 'sentry/components/core/layout';
import {IconArrow} from 'sentry/icons';
import {isMDXStory} from 'sentry/stories/view/useStoriesLoader';
import {useStory} from 'sentry/stories/view/useStory';
import {space} from 'sentry/styles/space';

export function StoryFooter() {
const {story} = useStory();
if (!story.filename.endsWith('.mdx')) return null;
if (!isMDXStory(story)) return null;
const {prev, next} = story.exports.frontmatter ?? {};

return (
<Flex align="center" justify="space-between" gap={space(2)}>
{prev && (
{typeof prev === 'object' && 'link' in prev && (
<Card to={prev.link} icon={<IconArrow direction="left" />}>
<CardLabel>Previous</CardLabel>
<CardTitle>{prev.label}</CardTitle>
</Card>
)}
{next && (
{typeof next === 'object' && 'link' in next && (
<Card data-flip to={next.link} icon={<IconArrow direction="right" />}>
<CardLabel>Next</CardLabel>
<CardTitle>{next.label}</CardTitle>
Expand Down
11 changes: 8 additions & 3 deletions static/app/stories/view/storyResources.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import {Badge} from 'sentry/components/core/badge';
import {LinkButton} from 'sentry/components/core/button/linkButton';
import {IconGithub} from 'sentry/icons';
import type {StoryResources as Resources} from 'sentry/stories/view/useStoriesLoader';
import {
isMDXStory,
type StoryResources as Resources,
} from 'sentry/stories/view/useStoriesLoader';
import {useStory} from 'sentry/stories/view/useStory';
import {space} from 'sentry/styles/space';

export function StoryResources() {
const {story} = useStory();
if (!story.exports.frontmatter?.resources) {

if (!isMDXStory(story)) {
return null;
}
const resources: Resources = story.exports.frontmatter.resources;

const resources: Resources = story.exports.frontmatter?.resources ?? {};

return (
<table style={{marginTop: space(4)}}>
Expand Down
10 changes: 8 additions & 2 deletions static/app/stories/view/useStoriesLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,24 @@ interface MDXStoryDescriptor {
source?: string;
types?: string;
};
types?: TypeLoader.ComponentDocWithFilename;
types?:
| TypeLoader.ComponentDocWithFilename
| Record<string, TypeLoader.ComponentDocWithFilename>;
};
filename: string;
}

interface TSStoryDescriptor {
exports: Record<string, React.ComponentType | any>;
exports: Record<string, React.ComponentType | unknown>;
filename: string;
}

export type StoryDescriptor = MDXStoryDescriptor | TSStoryDescriptor;

export function isMDXStory(story: StoryDescriptor): story is MDXStoryDescriptor {
return story.filename.endsWith('.mdx');
}

export function useStoryBookFiles() {
return useMemo(
() =>
Expand Down
Loading