-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting