Skip to content

Commit e929de9

Browse files
committed
storybook: rewrite colors to mdx
1 parent 8184bd9 commit e929de9

File tree

6 files changed

+305
-401
lines changed

6 files changed

+305
-401
lines changed

static/app/components/core/colors.mdx

Lines changed: 0 additions & 5 deletions
This file was deleted.

static/app/styles/colors.mdx

Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
import {Meta} from '@storybook/addon-docs';
2+
import {useTheme} from '@emotion/react';
3+
import styled from '@emotion/styled';
4+
5+
import DoAccentColors from 'sentry-images/stories/color/do-accent-colors.svg';
6+
import DoContrast from 'sentry-images/stories/color/do-contrast.svg';
7+
import DoDifferentiation from 'sentry-images/stories/color/do-differentiation.svg';
8+
import DontAccentColors from 'sentry-images/stories/color/dont-accent-colors.svg';
9+
import DontContrast from 'sentry-images/stories/color/dont-contrast.svg';
10+
import DontDifferentiation from 'sentry-images/stories/color/dont-differentiation.svg';
11+
12+
import ExternalLink from 'sentry/components/links/externalLink';
13+
import Panel from 'sentry/components/panels/panel';
14+
import PanelItem from 'sentry/components/panels/panelItem';
15+
import ThemeToggle from 'sentry/components/stories/themeToggle';
16+
import {IconCheckmark, IconClose} from 'sentry/icons';
17+
import {space} from 'sentry/styles/space';
18+
19+
export const GRAY_PALETTES = [
20+
[{color: 'gray500', text: 'lightModeWhite'}],
21+
[{color: 'gray400', text: 'lightModeWhite'}],
22+
[{color: 'gray300', text: 'lightModeWhite'}],
23+
[{color: 'gray200', text: 'lightModeBlack'}],
24+
[{color: 'gray100', text: 'lightModeBlack'}],
25+
];
26+
27+
export const LEVELS_PALETTES = [
28+
[
29+
{color: 'purple400', text: 'lightModeWhite'},
30+
{color: 'purple300', text: 'lightModeWhite'},
31+
{color: 'purple200', text: 'lightModeBlack'},
32+
{color: 'purple100', text: 'lightModeBlack'},
33+
],
34+
[
35+
{color: 'blue400', text: 'lightModeWhite'},
36+
{color: 'blue300', text: 'lightModeWhite'},
37+
{color: 'blue200', text: 'lightModeBlack'},
38+
{color: 'blue100', text: 'lightModeBlack'},
39+
],
40+
[
41+
{color: 'green400', text: 'lightModeWhite'},
42+
{color: 'green300', text: 'lightModeBlack'},
43+
{color: 'green200', text: 'lightModeBlack'},
44+
{color: 'green100', text: 'lightModeBlack'},
45+
],
46+
[
47+
{color: 'yellow400', text: 'lightModeBlack'},
48+
{color: 'yellow300', text: 'lightModeBlack'},
49+
{color: 'yellow200', text: 'lightModeBlack'},
50+
{color: 'yellow100', text: 'lightModeBlack'},
51+
],
52+
[
53+
{color: 'red400', text: 'lightModeWhite'},
54+
{color: 'red300', text: 'lightModeWhite'},
55+
{color: 'red200', text: 'lightModeBlack'},
56+
{color: 'red100', text: 'lightModeBlack'},
57+
],
58+
[
59+
{color: 'pink400', text: 'lightModeWhite'},
60+
{color: 'pink300', text: 'lightModeWhite'},
61+
{color: 'pink200', text: 'lightModeBlack'},
62+
{color: 'pink100', text: 'lightModeBlack'},
63+
],
64+
];
65+
66+
export const FixedWidth = styled('div')`
67+
max-width: 800px;
68+
`;
69+
70+
export const SideBySideList = styled('ul')`
71+
list-style-type: none;
72+
margin: 0;
73+
padding: 0;
74+
& > li {
75+
margin: 0;
76+
}
77+
& > li > div {
78+
margin-bottom: 0;
79+
}
80+
81+
display: grid;
82+
grid-template-columns: 1fr 1fr;
83+
gap: ${space(2)};
84+
`;
85+
86+
export const PalettePanel = styled(Panel)`
87+
margin-bottom: 0;
88+
`;
89+
90+
export const PalettePanelItem = styled(PanelItem)`
91+
flex-direction: column;
92+
gap: ${space(0.5)};
93+
94+
&:first-child {
95+
border-radius: ${p => p.theme.borderRadius} ${p => p.theme.borderRadius} 0 0;
96+
}
97+
&:last-child {
98+
border-radius: 0 0 ${p => p.theme.borderRadius} ${p => p.theme.borderRadius};
99+
}
100+
&:first-child:last-child {
101+
border-radius: ${p => p.theme.borderRadius};
102+
}
103+
104+
background: ${p => p.theme[p.color]};
105+
color: ${p => p.theme[p.text]};
106+
`;
107+
108+
export const ExampleImg = styled('img')`
109+
border: 1px solid ${p => p.theme.border};
110+
border-radius: ${p => p.theme.borderRadius};
111+
max-width: 400px;
112+
`;
113+
114+
export const PositiveLabel = styled(({className}) => (
115+
<div className={className}>
116+
<IconCheckmark />
117+
DO
118+
</div>
119+
))`
120+
color: ${p => p.theme.green400};
121+
align-items: center;
122+
display: flex;
123+
font-weight: ${p => p.theme.fontWeightBold};
124+
gap: ${space(0.5)};
125+
`;
126+
127+
export const NegativeLabel = styled(({className}) => (
128+
<div className={className}>
129+
<IconClose color="red400" />
130+
DON'T
131+
</div>
132+
))`
133+
color: ${p => p.theme.red400};
134+
align-items: center;
135+
display: flex;
136+
font-weight: ${p => p.theme.fontWeightBold};
137+
gap: ${space(0.5)};
138+
`;
139+
140+
export const ExampleCardGrid = styled('figcaption')`
141+
display: grid;
142+
grid-template-columns: 1fr 2fr;
143+
align-items: flex-start;
144+
color: ${p => p.theme.subText};
145+
padding: ${space(1)} ${space(1)} 0;
146+
`;
147+
148+
export const ExampleCard = ({imgSrc, text, isPositive}) => (
149+
<figure>
150+
<ExampleImg src={imgSrc} />
151+
<ExampleCardGrid>
152+
{isPositive ? <PositiveLabel /> : <NegativeLabel />}
153+
<span>{text}</span>
154+
</ExampleCardGrid>
155+
</figure>
156+
);
157+
158+
export const ColorPalette = ({name, palette}) => {
159+
const theme = useTheme();
160+
161+
return (
162+
<SideBySideList>
163+
{palette.map((section, i) => {
164+
return (
165+
<li key={`${name}-${i}`}>
166+
<PalettePanel typeof="ul">
167+
{section.map((color, index) => {
168+
return (
169+
<PalettePanelItem
170+
key={`${name}-${color.color}-${index}`}
171+
color={color.color}
172+
text={color.text}
173+
>
174+
<strong>{color.color}</strong>
175+
{theme[color.color]}
176+
</PalettePanelItem>
177+
);
178+
})}
179+
</PalettePanel>
180+
</li>
181+
);
182+
})}
183+
</SideBySideList>
184+
);
185+
}
186+
187+
# Colors
188+
189+
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.
190+
191+
## Grays
192+
193+
There are 5 shades of gray, ranging from Gray 500 (darkest) to Gray 100 (lightest).
194+
195+
**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.
196+
197+
Here are the recommended use cases:
198+
199+
- **Gray 500:** headings, button labels, tags/badges, and alerts.
200+
- **Gray 400:** body text, input values & labels.
201+
- **Gray 300:** input placeholders, inactive/disabled inputs and buttons, chart labels, supplemental and non-essential text
202+
- **Gray 200:** borders around large elements (cards, panels, dialogs, tables).
203+
- **Gray 100:** dividers and borders around small elements (buttons, form inputs). */}
204+
205+
<ThemeToggle>
206+
<ColorPalette name="grays" palette={GRAY_PALETTES} />
207+
</ThemeToggle>
208+
209+
## Accent Colors
210+
211+
Accent colors help shift the user's focus to certain interactive and high-priority elements, like links, buttons, and warning banners.
212+
213+
### Hues
214+
215+
There are 6 hues to choose from. Each has specific connotations:
216+
217+
- **Purple:** brand, current/active/focus state, or new information.
218+
- **Blue:** hyperlink.
219+
- **Green:** success, resolution, approval, availability, or creation.
220+
- **Yellow:** warning, missing, or impeded progress.
221+
- **Red:** fatal error, deletion, or removal.
222+
- **Pink:** new feature or promotion.
223+
224+
### Levels
225+
226+
Each hue comes in 4 levels: 400 (dark), 300 (full opacity), 200 (medium opacity), and 100 (low opacity).
227+
228+
- **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.
229+
- **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)).
230+
- **The 200 level** has medium opacity, useful for borders and dividers.
231+
- **The 100 level** has very low opacity, useful as background fills.
232+
233+
<ThemeToggle>
234+
<ColorPalette name="levels" palette={LEVELS_PALETTES} />
235+
</ThemeToggle>
236+
237+
## Accessibility
238+
239+
When it comes to using color, there are two main accessibility concerns: readability and separation.
240+
241+
### Readability
242+
243+
[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.
244+
245+
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.
246+
247+
Accent colors in the 300 series, except for Yellow 300, satisfy the contrast requirement for large text.
248+
249+
<SideBySideList>
250+
<ExampleCard
251+
imgSrc={DoContrast}
252+
text="Use Gray 300 and above for normal text"
253+
isPositive
254+
/>
255+
<ExampleCard
256+
imgSrc={DontContrast}
257+
text="Use Gray 100 or 200 for normal text, as they don't have the required the contrast levels"
258+
/>
259+
<ExampleCard
260+
imgSrc={DoAccentColors}
261+
text="Use accent colors in the 300 series (except for Yellow 300) for large text, if needed"
262+
isPositive
263+
/>
264+
<ExampleCard
265+
imgSrc={DontAccentColors}
266+
text="Use accent colors in the 100 or 200 series for any text"
267+
/>
268+
</SideBySideList>
269+
270+
### Separation
271+
272+
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.
273+
274+
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.
275+
276+
<SideBySideList>
277+
<ExampleCard
278+
imgSrc={DoDifferentiation}
279+
text="Provide additional visual encoding (e.g. line type) besides color to differentiate elements"
280+
isPositive
281+
/>
282+
<ExampleCard
283+
imgSrc={DontDifferentiation}
284+
text="Use color as the only way to differentiate elements"
285+
/>
286+
</SideBySideList>

0 commit comments

Comments
 (0)