Skip to content

The open alternative to Salesforce, designed for AI.

3.0 KB
Raw Blame

Theme

Import ThemeProvider, useTheme, useThemeColorScheme, useThemeContainer, themeCssVariables, and public theme types and constants from twenty-ui/theme. THEME_LIGHT and THEME_DARK remain available for styles, Stripe configuration, and other consumers that need static values. Load the existing twenty-ui/theme-light.css and twenty-ui/theme-dark.css stylesheets to supply CSS variables.

ThemeProvider applies the color-scheme class to the document root by default. Set applyToRoot={false} to scope the class to its children. overrides accepts CSS custom properties and creates a scope. Nested scopes resolve their own values, and useThemeContainer() identifies the nearest scope for portals. A popup's explicit container continues to take precedence over that scope. Root providers retain the scale preference; scoped providers ignore it.

Contexts initialize when a provider or hook is used, so importing static tokens also works under React’s server condition. The build can place the static tokens and the provider in the same chunk, so the theme runtime files import React as a default and call its APIs at render time; a lint rule on those files rejects named React value imports.

useTheme() without a provider returns CSS-variable references. Worker-rendered apps rely on these references resolving in the host document when its color scheme changes. Supplying static light values as a default would freeze those apps in light mode.

For consumers that need concrete JavaScript values in a worker, pass the theme explicitly:

import { THEME_DARK, THEME_LIGHT, ThemeProvider } from 'twenty-ui/theme';

<ThemeProvider
  colorScheme={colorScheme}
  applyToRoot={false}
  theme={colorScheme === 'dark' ? THEME_DARK : THEME_LIGHT}
>
  {children}
</ThemeProvider>;

The explicit theme supplies hook values and updates when the prop changes. Nested providers inherit it, and a provider with an explicit theme skips reading computed CSS values. Pass theme on a nested provider to replace the values for that subtree, for example when it switches color scheme. CSS classes, overrides, scaling, and portal scope retain their existing behavior. CSS overrides do not modify an explicitly supplied theme object. THEME_LIGHT and THEME_DARK keep their callable spacing helper; the provider resolves it into the same spacing entries that useTheme() returns from CSS variables, so theme.spacing[3] works with either source.

Raw contexts and their implementation types are private. Use the corresponding hook, including separate hook calls when reading both the theme and color scheme.

In Twenty apps, keep twenty-ui, twenty-sdk, and twenty-client-sdk on the same version. The front component renderer supplies the workspace styles and theme. See the front component guide for sandbox setup and the theming guide for standalone applications.