Skip to Content
Documentation
Getting startedComponentsChartsTheming
Get Pro
Overview
Concepts

Theme

Used to force a part of the tree to light or dark mode, and to override appearance tokens like radius and scale.

Anatomy

import { Theme } from '#components/ui/theme'
<Theme appearance="dark">
  <div />
</Theme>

Usage

Theme renders a div that scopes appearance to its subtree. It sets the chakra-theme class together with the appearance class, and applies the native color-scheme style so browser UI (scrollbars, form controls) follows along.

The key things to note:

  • appearance forces light or dark for everything inside. Leave it off to inherit the current color mode.
  • hasBackground (default true) paints the bg and fg tokens. Set it to false when the theme wraps an element that already has a background, like a popover or dialog.
  • colorPalette sets the default palette for all components in the subtree.
  • The radius and scale props write CSS variables that the Saas UI semantic tokens read, so they cascade to every component below.

Examples

Nested

Themes can be nested to apply different appearances to different parts of the tree. This is useful for applying a global appearance and then overriding some parts of it.

Good to know: this uses native CSS selectors, so there is no extra React context involved.

Hello Normal
Hello Dark
Hello Light

Portalled

Portalled content, such as a popover or dialog, is rendered outside the tree and therefore does not inherit a parent Theme. Wrap the portalled content itself and set hasBackground={false} so it keeps the panel styles.

Radius

Use controlRadius, panelRadius and indicatorRadius to change the border radius of controls, panels and indicators in a subtree. scaleFactor scales all three at once.

controlRadius: 0

controlRadius: 2

Page specific color mode

To lock an entire page to a specific color mode, wrap the page with Theme. Combine it with ColorModeProvider when you also use the useColorMode hook.

import { ColorModeProvider } from '#components/setup/color-mode/color-mode'
import { Theme } from '#components/ui/theme'

export const ForcedColorMode = ({ children }) => {
  return (
    <ColorModeProvider forcedTheme="dark">
      <Theme appearance="dark">{children}</Theme>
    </ColorModeProvider>
  )
}

Props

PropDefaultType
hasBackground true
boolean

Whether to apply the theme background and foreground colors. Set to false when wrapping content that already has a background, such as portalled panels.

scaleFactor '1'
number

Scale factor consumed by the Saas UI semantic radius tokens. Scales control, panel and indicator radii at once.

controlRadius '1'
number

Radius factor for controls such as Button, Input and Select.

panelRadius '1'
number

Radius factor for panels such as Dialog, Drawer and Popover.

indicatorRadius '1'
number

Radius factor for indicators such as Badge and Tag.

overlayEffect 'blur(10px)'
string

Backdrop effect consumed by the Saas UI overlay layer styles.

appearance
'light' | 'dark'

The light or dark appearance applied to this subtree. Leave undefined to inherit the current color mode.

colorPalette
ColorPalette

The default color palette for components in this subtree.