design-system
使用Sentry布局和文本原语的指南。在实现UI组件、布局或排版时使用。强制使用核心组件而非样式化…
npx skills add https://github.com/getsentry/sentry --skill design-systemLayout and Text Primitives at Sentry
Core Principle
ALWAYS use core components from @sentry/scraps instead of creating styled components with Emotion.
Core components provide consistent styling, responsive design, and better maintainability across the codebase.
Component Implementation Reference
For the complete list of supported props and their types, refer to the implementation files:
- Layout Components:
/static/app/components/core/layout/container.tsx- Base container with all layout propsflex.tsx- Flex layout primitivegrid.tsx- Grid layout primitivestack.tsx- Stack layout primitive (Flex with column direction by default)
- Typography Components:
/static/app/components/core/text/text.tsx- Text primitiveheading.tsx- Heading primitive
Layout Primitives
Important:
Flex,Grid, andStackall extendContainer. This means every prop available on Container is also available on Flex, Grid, and Stack. When you use<Flex>, you get all Container props (position, padding, border, overflow, etc.) PLUS the flex-specific props. The same applies to Grid and Stack.
Container
Base layout component that supports all common layout properties. Flex, Grid, and Stack extend Container, inheriting all of its props.
Key Props (see container.tsx for complete list):
position: "static" | "relative" | "absolute" | "fixed" | "sticky"padding,paddingTop,paddingBottom,paddingLeft,paddingRight: SpaceSize tokensmargin,marginTop, etc.: SpaceSize tokens (deprecated, prefer gap)width,height,minWidth,maxWidth,minHeight,maxHeightborderColor(all sides),borderTopColor,borderBottomColor,borderLeftColor,borderRightColor(one side): BorderVariant tokens. Draws a solid border, 1px unlessborderWidthis setborderWidth: BorderWidthToken (a key oftheme.border). On its own it draws all sides inprimaryradius: RadiusSize tokensoverflow,overflowX,overflowY: "visible" | "hidden" | "scroll" | "auto"background: BackgroundToken (a path intotokens.background)display: Various display types- Flex item props:
flex,flexGrow,flexShrink,flexBasis,alignSelf,order - Grid item props:
area,row,column
import {Container} from '@sentry/scraps/layout';
// ❌ Don't create styled components
const Component = styled('div')`
padding: ${p => p.theme.space.md};
border: 1px solid ${p => p.theme.tokens.border.primary};
`;
// ✅ Use Container primitive
<Container padding="md" borderColor="primary">
Content
</Container>;
Flex
Use <Flex> for flex layouts. Extends Container, inheriting all Container props plus flex-specific props.
Flex-Specific Props (see flex.tsx for complete list):
direction: "row" | "row-reverse" | "column" | "column-reverse"align: "start" | "end" | "center" | "baseline" | "stretch"justify: "start" | "end" | "center" | "between" | "around" | "evenly" | "left" | "right"gap: SpaceSize or"${SpaceSize} ${SpaceSize}"for row/column gapwrap: "nowrap" | "wrap" | "wrap-reverse"display: "flex" | "inline-flex" | "none"
Plus ALL Container props: position, padding, margin, width, height, borderColor, borderWidth, radius, overflow, background, flex/grid item props, and more (see Container section above).
import {Flex} from '@sentry/scraps/layout';
// ❌ Don't create styled components
const Component = styled('div')`
display: flex;
flex-direction: column;
position: relative;
`;
// ✅ Use Flex primitive with props
<Flex direction="column" position="relative" gap="md">
<Child1 />
<Child2 />
</Flex>;
Grid
Use <Grid> for grid layouts. Extends Container, inheriting all Container props plus grid-specific props.
Grid-Specific Props (see grid.tsx for complete list):
columns: Grid template columns (number or CSS value)rows: Grid template rowsareas: Named grid areasgap: SpaceSize or"${SpaceSize} ${SpaceSize}"for row/column gapalign: "start" | "end" | "center" | "baseline" | "stretch" (align-items)alignContent: "start" | "end" | "center" | "between" | "around" | "evenly" | "stretch"justify: "start" | "end" | "center" | "between" | "around" | "evenly" | "stretch" (justify-content)justifyItems: "start" | "end" | "center" | "stretch"flow: "row" | "column" | "row dense" | "column dense"autoColumns,autoRows: Size of auto-generated tracks
Plus ALL Container props: position, padding, margin, width, height, borderColor, borderWidth, radius, overflow, background, flex/grid item props, and more (see Container section above).
import {Grid} from '@sentry/scraps/layout';
// ❌ Don't create styled components
const Component = styled('div')`
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: ${p => p.theme.space.md};
`;
// ✅ Use Grid primitive
<Grid columns="repeat(3, 1fr)" gap="md">
<Item1 />
<Item2 />
<Item3 />
</Grid>;
Stack
Use <Stack> for vertical layouts. Stack is essentially Flex with direction="column" by default. It also provides Stack.Separator for adding separators between items.
Props (see stack.tsx for complete list):
- Same as Flex props (inherits all Flex and Container props)
directiondefaults to "column" (but can be overridden)Stack.Separatorcomponent for adding dividers between stack items
import {Stack} from '@sentry/scraps/layout';
// ❌ Don't create styled components for vertical layouts
const Component = styled('div')`
display: flex;
flex-direction: column;
gap: ${p => p.theme.space.md};
`;
// ✅ Use Stack primitive (automatically column direction)
<Stack gap="md">
<Item1 />
<Item2 />
<Item3 />
</Stack>;
// ✅ With separators between items
<Stack gap="md">
<Item1 />
<Stack.Separator />
<Item2 />
<Stack.Separator />
<Item3 />
</Stack>;
// ✅ Stack supports all Flex and Container props
<Stack gap="md" padding="lg" position="relative" borderColor="primary">
<Item1 />
<Item2 />
</Stack>;
Typography Primitives
Text
Use <Text> for all text content. Never use raw <p>, <span>, or <div> elements with text styling.
Key Props (see text.tsx for complete list):
as: "span" | "p" | "label" | "div" (semantic HTML element)size: TextSize ("xs" | "sm" | "md" | "lg" | "xl" | "2xl")variant: ContentVariant | "muted" (see Content Variant Tokens below)align: "left" | "center" | "right" | "justify"bold: booleanitalic: booleanuppercase: booleanmonospace: booleantabular: boolean (fixed-width numbers)ellipsis: boolean (truncate with ellipsis)wrap: "nowrap" | "normal" | "pre" | "pre-line" | "pre-wrap"textWrap: "wrap" | "nowrap" | "balance" | "pretty" | "stable"wordBreak: "normal" | "break-all" | "keep-all" | "break-word"density: "compressed" | "comfortable" (line-height)underline: boolean | "dotted"strikethrough: boolean
import {Text} from '@sentry/scraps/text';
// ❌ Don't create styled text components
const Label = styled('span')`
color: ${p => p.theme.tokens.content.secondary};
font-size: ${p => p.theme.font.size.sm};
`;
// ❌ Don't use raw elements
<p>This is a paragraph</p>
<span>Status: Active</span>
// ✅ Use Text primitive with semantic 'as' prop
<Text as="p" variant="muted" density="comfortable">
This is a paragraph
</Text>
<Text as="span" bold uppercase>
Status: Active
</Text>
Heading
Use <Heading> for all headings. Never use raw <h1>, <h2>, etc. elements.
Key Props (see heading.tsx for complete list):
as: "h1" | "h2" | "h3" | "h4" | "h5" | "h6" (REQUIRED)size: HeadingSize ("xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "4xl")variant: Same as Textalign: Same as Textitalic,monospace,tabular: Same as Textellipsis,wrap,textWrap,wordBreak: Same as Textdensity: Same as Textunderline,strikethrough: Same as Text
Note: bold and uppercase are NOT available on Heading (headings are always bold).
import {Heading} from '@sentry/scraps/text';
// ❌ Don't style heading elements
const Title = styled('h2')`
font-size: ${p => p.theme.font.size.md};
font-weight: bold;
`;
// ❌ Don't use raw heading elements
<h2>My Title</h2>
// ✅ Use Heading primitive with semantic 'as' prop
<Heading as="h2">My Title</Heading>
// ✅ With custom size
<Heading as="h3" size="xl">Large H3</Heading>
Info Components
Important: Always prefer
InfoTipandInfoTextover using raw<Tooltip>components. These provide consistent, accessible patterns for contextual help.
InfoTip
Use <InfoTip> to add an info icon with tooltip next to labels or headings. It's keyboard accessible and provides a consistent pattern for supplementary help.
import {InfoTip} from '@sentry/scraps/info';
import {Flex} from '@sentry/scraps/layout';
import {Text} from '@sentry/scraps/text';
// ❌ Don't use Tooltip with arbitrary icons
<Flex gap="xs" align="center">
<Text>Retention Period</Text>
<Tooltip title="The number of days...">
<IconInfo size="xs" />
</Tooltip>
</Flex>
// ✅ Use InfoTip for contextual help icons
<Flex gap="xs" align="center">
<Text>Retention Period</Text>
<InfoTip title="The number of days event data is stored before being automatically deleted." />
</Flex>
Key Props:
title: Tooltip content (required)size: "xs" | "sm" (default) | "md"
When to Use:
- Add context to headings or section titles
- Show supplementary information without inline text
- Explain settings or configuration options
InfoText
Use <InfoText> for inline text with a tooltip. It renders text with a dotted underline that reveals a tooltip on hover/focus.
import {InfoText} from '@sentry/scraps/info';
// ❌ Don't wrap text with raw Tooltip
<Tooltip title="Time to First Byte measures the time...">
<span style={{textDecoration: 'underline dotted'}}>TTFB</span>
</Tooltip>
// ✅ Use InfoText for inline explanations
<InfoText title="Time to First Byte measures the time from the request start until the first byte of the response is received.">
TTFB
</InfoText>
Key Props:
title: Tooltip content (required)- Extends
Text, so supports all Text props:size,variant,bold, etc.
// With Text styling props
<InfoText title="Small muted text" size="sm" variant="muted">
Hint text
</InfoText>
<InfoText title="Bold text" bold>
Important term
</InfoText>
When to Use:
- Define technical terms or acronyms inline
- Provide additional context without adding visual clutter
- Create consistent, accessible inline help patterns
Creating Thin Abstractions
Ask the user before creating an abstraction over layout primitives (
Container,Flex,Grid,Stack,Text,Heading) whose purpose is to DRY up repeated props.
You can create thin abstractions over primitives with the purpose of improving the semantic structure by using meaningful names (e.g., TableCell vs generic Flex) and with the purpose of providing some default props. It is very important that you do this sparingly, and only when it is a net gain for readability. For example, if there are only two instances of the duplicated props, and they are placed next to each other, the price of the abstraction outweights the terseness.
Before creating an abstraction, you MUST:
- Ask the user for confirmation
- Explain what abstraction you plan to create
- Justify why the abstraction is worth the added complexity
- Wait for explicit approval before proceeding
import {Flex, type FlexProps} from '@sentry/scraps/layout';
// ❌ Don't repeat the same props everywhere
<Flex align="center" gap="xs" flex="1" padding="sm">Content 1</Flex>
<Flex align="center" gap="xs" flex="1" padding="sm">Content 2</Flex>
<Flex align="center" gap="xs" flex="1" padding="sm">Content 3</Flex>
<Flex align="center" gap="xs" flex="1" padding="sm">Content 4</Flex>
// ✅ Create a thin wrapper with default props (AFTER USER CONFIRMATION)
function TableCell(props: FlexProps) {
return <Flex align="center" gap="md" {...props} />;
}
<TableCell>Content 1</TableCell>
<TableCell>Content 2</TableCell>
<TableCell align="start">Content 3</TableCell>{/* Can override defaults */}
Key points:
- ALWAYS prompt for user confirmation BEFORE creating the abstraction
- Extend the primitive's props type (
extends FlexProps) - Set defaults on JSX component and spread
{...props}to allow overrides - Don't use styled components - compose primitives instead
General Guidelines
1. Use Responsive Props
Most props support responsive syntax using breakpoint keys.
// ❌ Don't use styled media queries
const Component = styled('div')`
display: flex;
flex-direction: column;
@media screen and (min-width: ${p => p.theme.breakpoints.md}) {
flex-direction: row;
}
`;
// ✅ Use responsive props with bare (container) keys
<Flex direction={{zero: 'column', md: 'row'}}>
Bare keys ({md: …}) resolve against the nearest ancestor query container,
not the viewport. The organization layout already makes page content a query
container. To react to a component's own available space, declare a parent as
one with containerType="inline-size" (an element can never query its own size,
so the container must be an ancestor):
// ✅ Reflow based on the parent's width, not the viewport's
<Container containerType="inline-size">
<Flex direction={{'2xs': 'column', md: 'row'}}>{/* ... */}</Flex>
</Container>
Container breakpoints are named zero, 3xs, 2xs, xs, sm, md, lg,
xl, then 2xl to 5xl. A container is often narrower than the viewport, so
when replacing a media query, choose the breakpoint by checking the layout in its
real container rather than reusing the media query's breakpoint name.
When you need the resolved breakpoint in JS, use useContainerBreakpoint() from
@sentry/scraps/layout. It takes no arguments and reads the nearest query
container. It replaces width-based useMedia.
@sentry/scraps/prefer-container-responsive-props fails lint on layout
@media/@container queries in Emotion styles, width-based useMedia, and
viewport (screen:) keys in app code. Don't add new ones.
Existing viewport behavior. Responsive props also accept screen:-prefixed
keys ({'screen:md': …}), which resolve against the viewport. App code uses them
only where a container query would change behavior that has to follow the
viewport, with a suppression that says why:
// Hide by viewport width; a container query would change where first seen appears.
// oxlint-disable-next-line @sentry/scraps/prefer-container-responsive-props
display={{zero: 'none', 'screen:md': 'flex'}}
Leave existing suppressed screen: keys as they are. Don't copy them as a
pattern for new code, and don't add a suppression just to avoid choosing a
container breakpoint.
2. Prefer Gap/Padding Over Margin
Container supports margin props but they are deprecated. Use gap on parent containers instead.
// ❌ Don't use margin between children
const Child = styled('div')`
margin-right: ${p => p.theme.space.lg};
`;
// ✅ Use gap on parent container
<Flex gap="lg">
<Child1 />
<Child2 />
</Flex>;
3. Split Layout from Typography
Don't couple layout and typography in a single styled component. Use separate primitives.
// ❌ Don't couple layout and typography
const Component = styled('div')`
display: flex;
flex-direction: column;
color: ${p => p.theme.tokens.content.secondary};
font-size: ${p => p.theme.font.size.lg};
`;
// ✅ Split into layout and typography primitives
<Flex direction="column">
<Text variant="muted" size="lg">
Content
</Text>
</Flex>;
4. Check Implementation Files for All Props
The implementation files contain the complete, up-to-date list of supported props with TypeScript types. When in doubt:
- Read
/static/app/components/core/layout/container.tsxfor base layout props - Read
/static/app/components/core/layout/flex.tsxfor Flex-specific props - Read
/static/app/components/core/layout/grid.tsxfor Grid-specific props - Read
/static/app/components/core/layout/stack.tsxfor Stack-specific props - Read
/static/app/components/core/text/text.tsxfor Text props - Read
/static/app/components/core/text/heading.tsxfor Heading props
Token Reference
Spacing Tokens (SpaceSize)
Use these for gap, padding:
"0","2xs","xs","sm","md","lg","xl","2xl","3xl"- Multiple values:
"md lg"(vertical horizontal) - Responsive:
{{xs: "sm", md: "lg"}}
Border Tokens (BorderVariant)
Use these for borderColor and the side color props (borderTopColor, etc.). A value is a path into tokens.border, matching the theme's token names:
"primary","secondary""<color>.muted","<color>.moderate","<color>.vibrant", where<color>isneutral,accent,promotion,danger,warningorsuccess(e.g."accent.moderate")"transparent.<color>.<step>"with the same colors and steps (e.g."transparent.neutral.muted")"onVibrant.light","onVibrant.dark""none"removes a border, e.g. at a breakpoint or on one side
Border Width Tokens (BorderWidthToken)
Use these for the borderWidth prop. A value is a key of theme.border. Without a color prop, the border is primary:
"0"(0px),"md"(1px),"lg"(1.5px),"xl"(2px),"2xl"(4px)
Radius Tokens (RadiusSize)
Use these for radius prop:
"0","2xs","xs","sm","md","lg","xl","2xl","full"
Text Size Tokens
- TextSize: "xs" | "sm" | "md" | "lg" | "xl" | "2xl"
- HeadingSize: "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "4xl"
Background Tokens (BackgroundToken)
Use these for the background prop on layout components. A value is a path into tokens.background, matching the theme's token names:
"primary","secondary","tertiary","overlay""<color>.vibrant", where<color>isaccent,promotion,danger,warningorsuccess(e.g."accent.vibrant")"transparent.<color>.muted", where<color>isneutral,accent,promotion,danger,warningorsuccess(e.g."transparent.neutral.muted")
Content Variant Tokens (ContentVariant)
Use these for variant prop on Text and Heading:
- ContentVariant: "primary" | "secondary" | "accent" | "danger" | "promotion" | "success" | "warning"
- Plus "muted": Text and Heading also accept "muted" in addition to ContentVariant values
Quick Reference Checklist
Before creating a styled component, ask:
- ✅ Can I use
<Flex>,<Grid>, or<Stack>for layout? - ✅ Can I use
<Stack>for vertical layouts with default column direction? - ✅ Can I use
<Container>for borders/padding/positioning? - ✅ Can I use
<Text>or<Heading>for typography? - ✅ Can I use
<InfoTip>or<InfoText>instead of<Tooltip>? - ✅ Can I use responsive props instead of media queries?
- ✅ Can I use
gapinstead of margins? - ✅ Does the primitive support the prop I need? (Check implementation files)
If you answered yes to any of these, use the primitive instead.
Other Core Components
Menus and Selects
Use DropdownMenu for action menus and CompactSelect for choices. In forms, use the form system's field.Select or field.CompactSelect. Menu from @sentry/scraps/menu is an internal presentation primitive; use it directly only when implementing shared controls such as DropdownMenu and CompactSelect.
Avatars
Use the core avatar components (<UserAvatar/>, <TeamAvatar/>, <ProjectAvatar/>, <OrganizationAvatar/>, <SentryAppAvatar/>, <DocIntegrationAvatar/>) from static/app/components/core/avatar. For lists of avatars, use <AvatarList>.
// ✅ Use Avatar component and useUser
import {UserAvatar} from '@sentry/scraps/avatar';
import {useUser} from 'sentry/utils/useUser';
<UserAvatar user={user}>
// ❌ Do not use raw intrinsic elements or static paths
function Component() {
return (
<img
src="/path/to/image.jpg"
style={{
border,
width: 20,
height: 20,
borderRadius: '50%',
objectFit: 'cover',
display: 'inline-block',
}}
/>
);
}
Disclosure
Use the core disclosure component instead of building your own.
// ✅ Use Disclosure component
<Disclosure>
<Disclosure.Title>Title</Disclosure.Title>
<Disclosure.Content>Content that is toggled based on expanded state</Disclosure.Content>
</Disclosure>;
// ❌ Do not reimplement disclosure pattern manually
function Component() {
const [isExpanded, setIsExpanded] = useState(false);
return (
<div>
<Button
onClick={() => setIsExpanded(!isExpanded)}
icon={<IconChevron direction={isExpanded ? 'down' : 'right'} />}
>
Title
</Button>
{isExpanded && (
<Container>Content that is toggled based on expanded state</Container>
)}
</div>
);
}
Images and Icons
Place SvgIcon-based icons in static/packages/icons/src and import them from explicit @sentry/icons subpaths. Keep app asset wrappers in static/app/icons. The icons package must not depend on scraps or app code. Never inline SVGs. Optimize SVGs using svgo or svgomg.
// ❌ Never inline SVGs
function Component(){
return (
<Button icon={
<svg viewbox="0 0 16 16>"}>
// ❌ paths have excessive precision, optimize them with SVGO
<circle cx="8.00134" cy="8.4314" r="5.751412" />
<circle cx="8.00134" cy="8.4314" r="12.751412" />
<line x1="8.41334" y1="5.255361" x2="8" y2="8.255421" />
</svg>
</Button>
)
}
// ❌ Never place SVGs outside of icons folder.
import {CustomIcon} from "./customIcon"
// ✅ Import icon from our icon set
import {IconExclamation} from "@sentry/icons/exclamation"
All images belong inside static/images and must be imported via the sentry-images alias (defined in rsbuild.config.ts), never referenced by static path.
// ✅ Images are imported from sentry-images alias
import image from 'sentry-images/example.png';
function Component() {
return <Image src={image} />;
}
// ❌ All images need to be imported using the sentry-images alias!
function Component() {
return <Image src="/path/to/image.png" />;
}