Layout has a vocabulary
Use Stack for vertical rhythm, Inline for wrapping groups, and Grid when alignment needs multiple columns. Bleed offsets a surrounding inset, and Divider separates content. Text and Heading carry type scale and document semantics.
Use gap tokens for gaps and margins. Use inset tokens for padding, squish tokens for asymmetric padding, and inline spacing tokens inside inline elements. Keep the layout visible in the JSX so readers can see how parts fit.
A theme is a selection of parts
A theme pairs a light color palette with a dark color palette, then selects spacing, shape, and typography. colorMode: 'auto' follows the system preference. An explicit mode activates its corresponding slot. Choosing a different palette leaves the other slots available for independent selection.
import { Suspense } from 'react';
import { ThemeProvider } from '@precursor/theme';
export function DesignScope({ children }: { children: React.ReactNode }) {
return (
<Suspense fallback={null}>
<ThemeProvider
selection={{
color: { light: 'light', dark: 'dark' },
colorMode: 'auto',
spacing: 'compact',
shape: 'sharp',
typography: 'monospace',
}}
>
{children}
</ThemeProvider>
</Suspense>
);
}
Theme CSS is generated by Style Dictionary. The provider loads the assets for its selection, applies them together, and keeps loaded styles available. For server rendering, ThemeProvider also accepts a preloaded theme from loadTheme. See Next.js for the App Router setup.
Nest themes to change one part of a page
A child provider inherits each theme setting it does not specify. In this example, the Build console selects the workspace’s dark palette and changes typography. Recent checks changes only spacing. The text after the console still uses the workspace’s light theme. Each panel pairs its scoped text with a background from the same theme.
Workspace
The outer theme sets both color palettes, type, and spacing.
Build console
Uses the outer dark palette with monospace typography.
Recent checks
Inherits dark colors and monospace type with tighter spacing.
Outside the console, the workspace theme is still in effect.
import { Suspense, type ReactNode } from 'react';
import Heading from '@precursor/heading';
import Lozenge from '@precursor/lozenge';
import Panel from '@precursor/panel';
import Stack from '@precursor/stack';
import Text from '@precursor/text';
import { ThemeProvider } from '@precursor/theme';
function ThemeSurface({ children }: { children: ReactNode }) {
return (
<div
style={{
backgroundColor: 'var(--color-surface)',
color: 'var(--color-text)',
borderRadius: 'var(--shape-radius-m)',
}}
>
<Panel>{children}</Panel>
</div>
);
}
export default function NestedThemes() {
return (
<Suspense fallback={<p>Loading themes…</p>}>
<ThemeProvider
selection={{
color: { light: 'light', dark: 'dark' },
colorMode: 'light',
typography: 'sans-serif',
spacing: 'comfortable',
}}
>
<ThemeSurface>
<Stack gap="m">
<Heading as="h3" size="h4">
Workspace
</Heading>
<Text>
The outer theme sets both color palettes, type, and
spacing.
</Text>
<ThemeProvider
selection={{
colorMode: 'dark',
typography: 'monospace',
}}
>
<ThemeSurface>
<Stack gap="s">
<Heading as="h4" size="h4">
Build console
</Heading>
<Text>
Uses the outer dark palette with
monospace typography.
</Text>
<ThemeProvider
selection={{ spacing: 'compact' }}
>
<ThemeSurface>
<Stack gap="s">
<Heading as="h5" size="h5">
Recent checks
</Heading>
<Text>
Inherits dark colors and
monospace type with tighter
spacing.
</Text>
<div>
<Lozenge status="success">
Passed
</Lozenge>
</div>
</Stack>
</ThemeSurface>
</ThemeProvider>
</Stack>
</ThemeSurface>
</ThemeProvider>
<Text>
Outside the console, the workspace theme is still in
effect.
</Text>
</Stack>
</ThemeSurface>
</ThemeProvider>
</Suspense>
);
}
Composition is the first choice
Build from named parts around a shared root. Let the root manage behavior that belongs to the whole component. Give callers room to supply content and actions as children.
Reuse a layout with different content
Both review cards share the same heading and spacing. The first caller supplies an action. The second supplies a status. Either caller can omit the footer, and the card can support new footer content through the same slot.
Design review
Share a draft with your team.
Release review
All checks passed.
import type { ReactNode } from 'react';
import Button from '@precursor/button';
import Heading from '@precursor/heading';
import Lozenge from '@precursor/lozenge';
import Panel from '@precursor/panel';
import Stack from '@precursor/stack';
import Text from '@precursor/text';
function ReviewCard({
title,
children,
footer,
}: {
title: string;
children: ReactNode;
footer?: ReactNode;
}) {
return (
<Panel>
<Stack gap="s">
<Heading as="h3" size="h4">
{title}
</Heading>
{children}
{footer && <div>{footer}</div>}
</Stack>
</Panel>
);
}
export default function CompositionExample() {
return (
<Stack gap="s">
<ReviewCard
title="Design review"
footer={<Button primary>Request review</Button>}
>
<Text>Share a draft with your team.</Text>
</ReviewCard>
<ReviewCard
title="Release review"
footer={<Lozenge status="success">Approved</Lozenge>}
>
<Text>All checks passed.</Text>
</ReviewCard>
</Stack>
);
}
Keep shared behavior at the root
Tabs owns selection and coordinates the triggers and panels by ID. Put the triggers inside TabList and give each panel a matching ID. You can add a third tab by adding two children, and it gets the same keyboard and selection behavior. The tab panel can contain any React content.
Explore copyable blocks to see the same primitives in everyday patterns.
Feedback retains its meaning
Feedback colors adapt to the current palette while keeping blue for information, green for success, amber for warning, and red for errors. Pair color with a visible label or message that names the state.