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
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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
"@eslint/compat": "^1.2.7",
"@eslint/eslintrc": "^3.3.0",
"@eslint/js": "^9.22.0",
"@mdx-js/loader": "^3.1.0",
"@pmmmwh/react-refresh-webpack-plugin": "0.5.16",
"@sentry/jest-environment": "6.0.0",
"@sentry/profiling-node": "9.16.1",
Expand Down Expand Up @@ -255,6 +256,7 @@
"dev-ui-admin": "SENTRY_ADMIN_UI_DEV=1 yarn dev-ui",
"dev-ui-admin-rspack": "SENTRY_ADMIN_UI_DEV=1 yarn dev-ui-rspack",
"dev-ui-storybook": "STORYBOOK_TYPES=1 yarn dev-ui",
"dev-ui-storybook-rspack": "STORYBOOK_TYPES=1 yarn dev-ui-rspack",
"dev-acceptance": "NO_DEV_SERVER=1 NODE_ENV=development webpack --watch",
"dev-acceptance-rspack": "NO_DEV_SERVER=1 NODE_ENV=development rspack --watch",
"webpack-profile": "NO_TS_FORK=1 webpack --profile --json > stats.json",
Expand Down
69 changes: 42 additions & 27 deletions rspack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
DevServer,
OptimizationSplitChunksCacheGroup,
RspackPluginInstance,
RuleSetRule,
} from '@rspack/core';
import rspack from '@rspack/core';
import ReactRefreshRspackPlugin from '@rspack/plugin-react-refresh';
Expand Down Expand Up @@ -170,6 +171,35 @@ for (const locale of supportedLocales) {
};
}

const swcReactLoaderConfig: RuleSetRule['options'] = {
jsc: {
experimental: {
plugins: [
[
'@swc/plugin-emotion',
{
sourceMap: true,
// The "dev-only" option does not seem to apply correctly
autoLabel: DEV_MODE ? 'always' : 'never',
},
],
],
},
parser: {
syntax: 'typescript',
tsx: true,
},
transform: {
react: {
runtime: 'automatic',
development: DEV_MODE,
refresh: DEV_MODE,
importSource: '@emotion/react',
},
},
},
};

/**
* Main Webpack config for Sentry React SPA.
*/
Expand Down Expand Up @@ -217,34 +247,19 @@ const appConfig: Configuration = {
test: /\.(js|jsx|ts|tsx)$/,
exclude: /\/node_modules\//,
loader: 'builtin:swc-loader',
options: {
jsc: {
experimental: {
plugins: [
[
'@swc/plugin-emotion',
{
sourceMap: true,
// The "dev-only" option does not seem to apply correctly
autoLabel: DEV_MODE ? 'always' : 'never',
},
],
],
},
parser: {
syntax: 'typescript',
tsx: true,
},
transform: {
react: {
runtime: 'automatic',
development: DEV_MODE,
refresh: DEV_MODE,
importSource: '@emotion/react',
},
},
options: swcReactLoaderConfig,
},
{
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

options: swcReactLoaderConfig,
},
},
{
loader: '@mdx-js/loader',
},
],
},
{
test: /\.po$/,
Expand Down
285 changes: 285 additions & 0 deletions static/app/styles/colors.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
import {useTheme} from '@emotion/react';
import styled from '@emotion/styled';

import DoAccentColors from 'sentry-images/stories/color/do-accent-colors.svg';
import DoContrast from 'sentry-images/stories/color/do-contrast.svg';
import DoDifferentiation from 'sentry-images/stories/color/do-differentiation.svg';
import DontAccentColors from 'sentry-images/stories/color/dont-accent-colors.svg';
import DontContrast from 'sentry-images/stories/color/dont-contrast.svg';
import DontDifferentiation from 'sentry-images/stories/color/dont-differentiation.svg';

import ExternalLink from 'sentry/components/links/externalLink';
import Panel from 'sentry/components/panels/panel';
import PanelItem from 'sentry/components/panels/panelItem';
import ThemeToggle from 'sentry/components/stories/themeToggle';
import {IconCheckmark, IconClose} from 'sentry/icons';
import {space} from 'sentry/styles/space';

export const GRAY_PALETTES = [
[{color: 'gray500', text: 'lightModeWhite'}],
[{color: 'gray400', text: 'lightModeWhite'}],
[{color: 'gray300', text: 'lightModeWhite'}],
[{color: 'gray200', text: 'lightModeBlack'}],
[{color: 'gray100', text: 'lightModeBlack'}],
];

export const LEVELS_PALETTES = [
[
{color: 'purple400', text: 'lightModeWhite'},
{color: 'purple300', text: 'lightModeWhite'},
{color: 'purple200', text: 'lightModeBlack'},
{color: 'purple100', text: 'lightModeBlack'},
],
[
{color: 'blue400', text: 'lightModeWhite'},
{color: 'blue300', text: 'lightModeWhite'},
{color: 'blue200', text: 'lightModeBlack'},
{color: 'blue100', text: 'lightModeBlack'},
],
[
{color: 'green400', text: 'lightModeWhite'},
{color: 'green300', text: 'lightModeBlack'},
{color: 'green200', text: 'lightModeBlack'},
{color: 'green100', text: 'lightModeBlack'},
],
[
{color: 'yellow400', text: 'lightModeBlack'},
{color: 'yellow300', text: 'lightModeBlack'},
{color: 'yellow200', text: 'lightModeBlack'},
{color: 'yellow100', text: 'lightModeBlack'},
],
[
{color: 'red400', text: 'lightModeWhite'},
{color: 'red300', text: 'lightModeWhite'},
{color: 'red200', text: 'lightModeBlack'},
{color: 'red100', text: 'lightModeBlack'},
],
[
{color: 'pink400', text: 'lightModeWhite'},
{color: 'pink300', text: 'lightModeWhite'},
{color: 'pink200', text: 'lightModeBlack'},
{color: 'pink100', text: 'lightModeBlack'},
],
];

export const FixedWidth = styled('div')`
max-width: 800px;
`;

export const SideBySideList = styled('ul')`
list-style-type: none;
margin: 0;
padding: 0;
& > li {
margin: 0;
}
& > li > div {
margin-bottom: 0;
}

display: grid;
grid-template-columns: 1fr 1fr;
gap: ${space(2)};
`;

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>
);
}
Comment on lines +65 to +184
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.


# Colors

Sentry has a flexible, tiered color system that adapts to both light and dark mode. Our color palette consists of neutral grays and 6 accent colors.

## Grays

There are 5 shades of gray, ranging from Gray 500 (darkest) to Gray 100 (lightest).

**Gray 300 and above** are accessible foreground colors that conform to [WCAG standards](https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html). Use them as text and icon colors.

Here are the recommended use cases:

- **Gray 500:** headings, button labels, tags/badges, and alerts.
- **Gray 400:** body text, input values & labels.
- **Gray 300:** input placeholders, inactive/disabled inputs and buttons, chart labels, supplemental and non-essential text
- **Gray 200:** borders around large elements (cards, panels, dialogs, tables).
- **Gray 100:** dividers and borders around small elements (buttons, form inputs). */}

<ThemeToggle>
<ColorPalette name="grays" palette={GRAY_PALETTES} />
</ThemeToggle>

## Accent Colors

Accent colors help shift the user's focus to certain interactive and high-priority elements, like links, buttons, and warning banners.

### Hues

There are 6 hues to choose from. Each has specific connotations:

- **Purple:** brand, current/active/focus state, or new information.
- **Blue:** hyperlink.
- **Green:** success, resolution, approval, availability, or creation.
- **Yellow:** warning, missing, or impeded progress.
- **Red:** fatal error, deletion, or removal.
- **Pink:** new feature or promotion.

### Levels

Each hue comes in 4 levels: 400 (dark), 300 (full opacity), 200 (medium opacity), and 100 (low opacity).

- **The 400 level** is a darkened version of 300. It is useful for hover/active states in already accentuated elements. For example, a button could have a background of Purple 300 in normal state and Purple 400 on hover.
- **The 300 level** has full opacity and serves well as text and icon colors (with the exception of Yellow 300, which does not meet [WCAG's contrast standards](https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html)).
- **The 200 level** has medium opacity, useful for borders and dividers.
- **The 100 level** has very low opacity, useful as background fills.

<ThemeToggle>
<ColorPalette name="levels" palette={LEVELS_PALETTES} />
</ThemeToggle>

## Accessibility

When it comes to using color, there are two main accessibility concerns: readability and separation.

### Readability

[WCAG](https://www.w3.org/TR/WCAG21/) requires that normal text elements have a contrast ratio of at least 4.5:1 against the background. For large text (at least 16px in size AND in medium/bold weight), the required ratio is lower, at 3:1. This is to ensure a comfortable reading experience in different lighting conditions. [Use this tool](https://webaim.org/resources/contrastchecker/) to confirm text contrast ratios.

In Sentry's color palette, only Gray 300 and above satisfy the contrast requirement for normal text. This applies to both light and dark mode.

Accent colors in the 300 series, except for Yellow 300, satisfy the contrast requirement for large text.

<SideBySideList>
<ExampleCard
imgSrc={DoContrast}
text="Use Gray 300 and above for normal text"
isPositive
/>
<ExampleCard
imgSrc={DontContrast}
text="Use Gray 100 or 200 for normal text, as they don't have the required the contrast levels"
/>
<ExampleCard
imgSrc={DoAccentColors}
text="Use accent colors in the 300 series (except for Yellow 300) for large text, if needed"
isPositive
/>
<ExampleCard
imgSrc={DontAccentColors}
text="Use accent colors in the 100 or 200 series for any text"
/>
</SideBySideList>

### Separation

Color can be an effective way to visually separate elements in the user interface. However, not all users see color in the same way. Some are color-blind and cannot reliably differentiate one color from another. Some have color filters on their screens, like Night Shift in MacOS. Others are in bright environments with high levels of glare, reducing their ability to see color clearly.

As such, color is an unreliable way to separate elements. Whenever possible, provide additional visual cues like icons, text labels, line type (solid, dashed, dotted),… to further reinforce the separation.

<SideBySideList>
<ExampleCard
imgSrc={DoDifferentiation}
text="Provide additional visual encoding (e.g. line type) besides color to differentiate elements"
isPositive
/>
<ExampleCard
imgSrc={DontDifferentiation}
text="Use color as the only way to differentiate elements"
/>
</SideBySideList>
Loading
Loading