Skip to main content

createThemeColors

A utility function that generates a complete set of semantic color tokens for light and dark modes, following the shadcn/ui theming convention.

Import

import { createThemeColors } from '@react-native-styled-system/util';

Signature

const { light, dark } = createThemeColors({ base, theme });

Parameters

ParameterTypeDescription
baseBaseColorThe gray scale used for neutral UI surfaces. One of: 'slate', 'gray', 'zinc', 'neutral', 'stone'
themeThemeColorThe color used for primary/accent. Any of the 22 Tailwind color names or the 5 gray scales

ThemeColor includes all values of BaseColor plus: 'red', 'orange', 'amber', 'yellow', 'lime', 'green', 'emerald', 'teal', 'cyan', 'sky', 'blue', 'indigo', 'violet', 'purple', 'fuchsia', 'pink', 'rose'.

Return Value

Returns { light: Record<string, string>, dark: Record<string, string> }.

Each record contains the following semantic color tokens:

TokenLightDark
background#FFFFFFbase.950
foregroundbase.950base.50
card#FFFFFFbase.900
card-foregroundbase.950base.50
popover#FFFFFFbase.900
popover-foregroundbase.950base.50
primarytheme.900 (gray) / theme.600 (color)theme.200 (gray) / theme.500 (color)
primary-foregroundtheme.50 (gray) / #FFFFFF (color)theme.900 (gray) / #FFFFFF (color)
secondarybase.100base.800
secondary-foregroundbase.900base.50
mutedbase.100base.800
muted-foregroundbase.500base.400
accentbase.100base.800
accent-foregroundbase.900base.50
destructivered.600red.400
destructive-foregroundbase.50base.50
borderbase.200base.800
inputbase.200base.800
ringbase.400 (gray) / theme.400 (color)base.500 (gray) / theme.500 (color)
chart-1 ~ chart-5Fixed chart paletteFixed chart palette

When theme is a gray scale (same type as base), primary maps to darker/lighter shades of that gray. When theme is a saturated color, primary uses the vibrant shade directly.

Usage

Basic

const { light, dark } = createThemeColors({ base: 'neutral', theme: 'neutral' });

With colored primary

const { light, dark } = createThemeColors({ base: 'zinc', theme: 'blue' });

With defaultTheme

import { createThemeColors } from '@react-native-styled-system/util';
import { createTheme, defaultTheme } from '@react-native-styled-system/util';

const { light, dark } = createThemeColors({ base: 'slate', theme: 'violet' });

const theme = createTheme(defaultTheme, { colors: light });

Dark mode switching

const { light: lightColors, dark: darkColors } = createThemeColors({
base: 'neutral',
theme: 'blue',
});

const isDark = useColorScheme() === 'dark';

const theme = useMemo(
() => createTheme(defaultTheme, { colors: isDark ? darkColors : lightColors }),
[isDark],
);

<StyledSystemProvider theme={theme}>