Skip to main content

Theme Scope

Theme Scope is a wrapper that applies a different theme or color mode to part of the screen, such as a dark promo card.

Import

import { ThemeScope } from '@vortexlabs/vortex-native';
import type { ThemeScopeProps } from '@vortexlabs/vortex-native';

Other links

import { Stack, ThemeScope } from "@vortexlabs/vortex-native";

<Stack direction="row" gap={4}>
  <Panel title="Page" />
  <ThemeScope colorMode="inverted">
    <Panel title="Inverted section" />
  </ThemeScope>
</Stack>

Features

  • Supports fixed light and dark color modes.
  • Supports inverting the parent's color mode.
  • Supports nested scopes.
  • Supports themes and theme overrides.

Place ThemeScope inside a VortexProvider. It supplies context and doesn't render a view, so add your own themed Stack for backgrounds and layout. Panel in these examples is a Stack that shows its color mode.

Fixed Color Mode

Set colorMode to light or dark to keep a section in one mode whatever the app uses.

<ThemeScope colorMode="light">
  <Panel title="Light" />
</ThemeScope>
<ThemeScope colorMode="dark">
  <Panel title="Dark" />
</ThemeScope>

Nested Scopes

inverted uses the opposite of the parent mode. Nested inverted scopes alternate, so inverting twice returns to the original mode.

<Panel title="Page">
  <ThemeScope colorMode="inverted">
    <Panel title="Inverted section">
      <ThemeScope colorMode="inverted">
        <Panel title="Inverted twice" />
      </ThemeScope>
    </Panel>
  </ThemeScope>
</Panel>

Themes

Pass a generated native theme to theme to render a subtree with it.

import awenTheme from "@vortexlabs/vortex-themes/themes/awen/native";
import sleekTheme from "@vortexlabs/vortex-themes/themes/sleek/native";
import vortexTheme from "@vortexlabs/vortex-themes/themes/vortex/native";

<ThemeScope theme={vortexTheme}>
  <Panel title="Vortex" />
</ThemeScope>
<ThemeScope theme={awenTheme}>
  <Panel title="Awen" />
</ThemeScope>
<ThemeScope theme={sleekTheme}>
  <Panel title="Sleek" />
</ThemeScope>

Theme Overrides

An override, such as the bundled astra, is layered on the parent theme, so the subtree keeps every value the override doesn't change.

import astraTheme from "@vortexlabs/vortex-themes/themes/overrides/astra/native";

<Panel title="Page theme" />
<ThemeScope theme={astraTheme}>
  <Panel title="With Astra override" />
</ThemeScope>

Use useTheme to read the scope's theme and color mode.

Accessibility

Description
ThemeScope renders no view and adds no accessibility behavior.
Check text and control contrast in every color mode a scope can render.