Skip to content

storybook: add markdown support #91817

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 4 commits into from
May 19, 2025
Merged

storybook: add markdown support #91817

merged 4 commits into from
May 19, 2025

Conversation

JonasBa
Copy link
Member

@JonasBa JonasBa commented May 16, 2025

Add mdx support for stories. This allows us to write mdx compliant markup which is commonly supported by documentation framework and friendlier to write than jsx.

The mdx loader also conveniently exports a default export which means that we can omit the concept of storybook entirely

@JonasBa JonasBa requested review from a team as code owners May 16, 2025 19:22
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label May 16, 2025
Copy link

codecov bot commented May 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #91817      +/-   ##
==========================================
- Coverage   87.64%   85.26%   -2.39%     
==========================================
  Files       10350    10344       -6     
  Lines      586527   585977     -550     
  Branches    22574    22531      -43     
==========================================
- Hits       514068   499605   -14463     
- Misses      72013    85926   +13913     
  Partials      446      446              

Comment on lines +65 to +184
export const PalettePanel = styled(Panel)`
margin-bottom: 0;
`;

export const PalettePanelItem = styled(PanelItem)`
flex-direction: column;
gap: ${space(0.5)};

&:first-child {
border-radius: ${p => p.theme.borderRadius} ${p => p.theme.borderRadius} 0 0;
}
&:last-child {
border-radius: 0 0 ${p => p.theme.borderRadius} ${p => p.theme.borderRadius};
}
&:first-child:last-child {
border-radius: ${p => p.theme.borderRadius};
}

background: ${p => p.theme[p.color]};
color: ${p => p.theme[p.text]};
`;

export const ExampleImg = styled('img')`
border: 1px solid ${p => p.theme.border};
border-radius: ${p => p.theme.borderRadius};
max-width: 400px;
`;

export const PositiveLabel = styled(({className}) => (
<div className={className}>
<IconCheckmark />
DO
</div>
))`
color: ${p => p.theme.green400};
align-items: center;
display: flex;
font-weight: ${p => p.theme.fontWeightBold};
gap: ${space(0.5)};
`;

export const NegativeLabel = styled(({className}) => (
<div className={className}>
<IconClose color="red400" />
DON'T
</div>
))`
color: ${p => p.theme.red400};
align-items: center;
display: flex;
font-weight: ${p => p.theme.fontWeightBold};
gap: ${space(0.5)};
`;

export const ExampleCardGrid = styled('figcaption')`
display: grid;
grid-template-columns: 1fr 2fr;
align-items: flex-start;
color: ${p => p.theme.subText};
padding: ${space(1)} ${space(1)} 0;
`;

export const ExampleCard = ({imgSrc, text, isPositive}) => (
<figure>
<ExampleImg src={imgSrc} />
<ExampleCardGrid>
{isPositive ? <PositiveLabel /> : <NegativeLabel />}
<span>{text}</span>
</ExampleCardGrid>
</figure>
);

export const ColorPalette = ({name, palette}) => {
const theme = useTheme();

return (
<SideBySideList>
{palette.map((section, i) => {
return (
<li key={`${name}-${i}`}>
<PalettePanel typeof="ul">
{section.map((color, index) => {
return (
<PalettePanelItem
key={`${name}-${color.color}-${index}`}
color={color.color}
text={color.text}
>
<strong>{color.color}</strong>
{theme[color.color]}
</PalettePanelItem>
);
})}
</PalettePanel>
</li>
);
})}
</SideBySideList>
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to move these local components out of this file... would these make more sense in the stories file where other helpers are?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will open a PR and just move all of these story components to a single file or directory I think. They are all kinda spread around the codebase, and I never actually know where to find anything.

test: /\.mdx?$/,
use: [
{
loader: 'builtin:swc-loader',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting

Copy link
Member

@scttcper scttcper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nightmare of subdependencies but looks good

@JonasBa
Copy link
Member Author

JonasBa commented May 16, 2025

nightmare of subdependencies but looks good

Long term, the plan is very likely to move this out of the codebase entirely. Unfortunately, before we are able to do that, we need to untangle the module graph, and that is quite the undertaking 😅

By adding this loader, we can essentially focus on writing the docs, which is the bulk of the value, before we ultimately lift it out

@JonasBa JonasBa merged commit 20b05fc into master May 19, 2025
41 checks passed
@JonasBa JonasBa deleted the jb/storybook/mdx branch May 19, 2025 14:47
andrewshie-sentry pushed a commit that referenced this pull request May 20, 2025
Add mdx support for stories. This allows us to write mdx compliant
markup which is commonly supported by documentation framework and
friendlier to write than jsx.

The mdx loader also conveniently exports a default export which means
that we can omit the concept of storybook entirely
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants