Theme
Configure themes and dark mode in Lunar Kit
Theme Configuration
Lunar Kit uses CSS variables for theming, making it easy to customize colors and support dark mode.
Color System
The theme is based on semantic color tokens that adapt to light and dark modes:
| Token | Description |
|---|---|
background | Main background color |
foreground | Main text color |
card | Card/surface background |
card-foreground | Card text color |
primary | Primary brand color |
primary-foreground | Text on primary color |
secondary | Secondary color |
secondary-foreground | Text on secondary color |
muted | Muted/subtle background |
muted-foreground | Muted text color |
accent | Accent/highlight color |
accent-foreground | Text on accent color |
destructive | Error/danger color |
destructive-foreground | Text on destructive color |
border | Border color |
input | Input border color |
ring | Focus ring color |
CSS Variables
Colors are defined in global.css using HSL values:
Tailwind Configuration
Colors are mapped in tailwind.config.js:
Dark Mode
Using NativeWind
Lunar Kit supports dark mode through NativeWind's dark: prefix:
Theme Provider
Set up a theme provider to manage theme state:
Using the Theme Hook
Use Theme Colors
Lunar Kit provides a type-safe way to access your theme colors through the useThemeColors hook. This approach ensures you always get the correct color value based on the current theme (light/dark).
Setup
To ensure your colors are consistent across both Tailwind classes and runtime JavaScript (e.g., in useThemeColors), we recommend using a "Single Source of Truth" approach.
Instead of manually keeping global.css and your JS constants in sync, define your colors in lib/theme.ts and export them as CSS variables using NativeWind's vars.
Create lib/theme.ts:
Then create the hook that consumes these exported colors:
Global Configuration
Update your _layout.tsx to handle theme changes globally:
Usage in Components
Custom Themes
Creating a Custom Theme
You can create custom themes by modifying the CSS variables:
Theme Presets
Here are some popular theme presets you can use:
Slate (Default)
Zinc
Stone
Rose
Blue
Using Colors in Components
With NativeWind Classes
With Style Props
When you need to use colors with style props (for libraries like react-native-svg):
Best Practices
- Use semantic tokens — Use
primary,secondary, etc. instead of specific color values - Test both modes — Always check your UI in both light and dark modes
- Contrast ratios — Ensure text is readable against backgrounds
- Consistent usage — Use the same tokens consistently across your app
- Avoid hardcoded colors — Use theme colors instead of hex values
Next, learn about the CLI to add components to your project!