Provides token overrides for content rendered on inverted surfaces: media overlays, scrims, toasts, and tooltips. The base behavior flips color-scheme so all light-dark() tokens resolve to the correct side. Only a small set of tokens need explicit overrides beyond that. Themes can further customize component appearance on media surfaces via onDark/onLight in defineTheme(), with both token overrides (e.g. "--color-accent": "#90CAF9") and component overrides (e.g. ghost buttons get a border on dark surfaces).
Preview loads on approachPreview loads on approach
Exact source · media-theme-showcase
// Copyright (c) Meta Platforms, Inc. and affiliates.
'use client';
import {MediaTheme} from '@astryxdesign/core/theme';
import {Section} from '@astryxdesign/core/Section';
import {Stack} from '@astryxdesign/core/Layout';
import {Text} from '@astryxdesign/core/Text';
import {Button} from '@astryxdesign/core/Button';
import {Badge} from '@astryxdesign/core/Badge';
import {Icon} from '@astryxdesign/core/Icon';
const SHOWCASE_IMAGE_URL =
'/template-assets/light-scene-horizontal-1.png';
export default function MediaThemeShowcase() {
return (
<Section
variant="transparent"
padding={4}
style={{
width: 360,
maxWidth: '100%',
minHeight: 230,
display: 'flex',
alignItems: 'flex-end',
backgroundImage: `linear-gradient(180deg, rgba(10,19,23,0.05) 0%, rgba(10,19,23,0.82) 100%), url(${SHOWCASE_IMAGE_URL})`,
backgroundSize: 'cover',
backgroundPosition: 'center',
borderRadius: 'var(--radius-container)',
boxShadow: 'var(--shadow-med)',
}}>
<MediaTheme mode="dark">
<Stack direction="vertical" gap={3}>
<Stack direction="horizontal" gap={2} vAlign="center">
<Icon icon="info" size="md" />
<Text type="body" weight="bold">
Media overlay
</Text>
<Badge label="Live" />
</Stack>
<Text type="supporting" color="secondary">
Text, icons, badges, and button variants inherit legible colors on
top of the dark image treatment.
</Text>
<Stack direction="horizontal" gap={2} wrap="wrap">
<Button label="Primary" variant="primary" size="sm" />
<Button label="Secondary" variant="secondary" size="sm" />
<Button label="Ghost" variant="ghost" size="sm" />
</Stack>
</Stack>
</MediaTheme>
</Section>
);
}
Usage
Provides token overrides for content rendered on inverted surfaces: media overlays, scrims, toasts, and tooltips. The base behavior flips color-scheme so all light-dark() tokens resolve to the correct side. Only a small set of tokens need explicit overrides beyond that. Themes can further customize component appearance on media surfaces via onDark/onLight in defineTheme(), with both token overrides (e.g. "--color-accent": "#90CAF9") and component overrides (e.g. ghost buttons get a border on dark surfaces).
Use for any content placed over a dark background (image overlays, video scrims, dark cards) or other inverted surfaces like toasts and tooltips.
Prefer mode="auto" when the surface color comes from a theme token. A token named "inverted" is not guaranteed to be inverted, and auto measures what was actually painted instead of trusting the name. It can even decide that a surface needs no media context at all.
Pair with a background color: MediaTheme flips the token context but does not add a background. Set backgroundColor on the parent element.
Themes can customize components on media surfaces via onDark.components and onLight.components in defineTheme(). For example, add a border to ghost buttons on dark surfaces.
Use MediaTheme for app-level dark mode: use Theme with mode="dark" or mode="system" instead. MediaTheme is for local surface inversions, not page-wide color scheme.
Typed props
Prop
Type and behavior
mode
'dark' | 'light' | 'auto' | 'off' · required
Surface luminance context: dark for content over dark backgrounds (light text, white-tinted interactions), light for content over light backgrounds (dark text, black-tinted interactions), auto to decide from the painted surface (no media context when the ambient text already reads on the surface at 3:1, otherwise the side that reads better), and off to turn it off explicitly. The element renders either way, so a surface can switch contexts without remounting children.
fallback
'dark' | 'light' · default 'dark'
Which side auto uses when the surface cannot be measured: during SSR, on the first client frame, and whenever the backdrop is not knowable from CSS, most often a background-image, whose pixels need sampling (useImageMode) rather than a computed style. Ignored unless mode is auto.
children
ReactNode · required
Content to render with inverted token context. Components inherit the correct colors automatically.