How It Works
The theme system is enabled insrc/app/layout.tsx, where the <ThemeProvider> component wraps your entire application.
src/app/layout.tsx
attribute="class": This tellsnext-themesto toggle dark mode by adding or removing thedarkclass on the<html>element.defaultTheme="system": The default theme is set to match the user’s operating system preference.enableSystem: Allows the theme to sync with the system setting.
Applying Dark Mode Styles
Sabo offers two ways to apply dark mode styles. The recommended approach is to use the semantic color system, which handles theme changes automatically.- Option 1: Semantic System (Recommended)
- Option 2: Direct Styling with `dark:`
Sabo’s components are built with a semantic color system based on CSS variables. This means you use classes that describe a component’s purpose, not its color, and the theme system handles the color switching automatically.For example, instead of specifying This works because variables like
bg-white dark:bg-black, you should use bg-card:CardComponent.tsx
--card are defined with different values for light and dark themes in src/app/globals.css.This semantic approach is used for all themed components in Sabo. To learn more, see the Styling guide.
Theme Toggle Component
Sabo includes a theme toggle component that allows users to switch between light, dark, and system themes.- Location:
src/components/shared/theme-toggle.tsx - Usage: You can place the
<ThemeToggle />component anywhere in your application. In this boilerplate, it is located in theFootercomponent.
Header component:
src/components/shared/header.tsx