When adding or customizing theme colors in this Next.js dashboard:
- •
Locate the theme definitions in
src/app/globals.css:- •Light theme:
:rootselector - •Dark theme:
.darkselector - •Chart colors are defined in both themes
- •Light theme:
- •
Color format: Use HSL values without the
hsl()wrapper:css--color-name: 220 10% 50%;
This allows using
hsl(var(--color-name))in components. - •
Available color categories:
- •Layout: background, foreground, card, popover, border
- •Elements: primary, secondary, muted, accent, destructive
- •Text: foreground, muted-foreground, popover-foreground
- •Charts: chart-1 through chart-5
- •
Adding a new theme color:
css:root { --new-color: 210 100% 50%; /* Light mode */ } .dark { --new-color: 210 50% 40%; /* Dark mode */ } - •
Using the color in components:
tsx// In Tailwind classes (if configured) className="text-new-color" // In inline styles or charts color: "hsl(var(--new-color))" backgroundColor: "hsl(var(--new-color))"
- •
Chart colors (predefined: chart-1 through chart-5):
- •Used automatically by the
useChartColorshook - •Ensure both light and dark modes have distinct, accessible colors
- •Test visibility in both themes
- •Used automatically by the
- •
Best practices:
- •Maintain color harmony across themes
- •Ensure sufficient contrast for accessibility (WCAG AA)
- •Test colors in both light and dark modes
- •Document custom colors if they serve specific purposes
- •
Color palette consistency:
- •Light theme: Use higher lightness values (50-90%)
- •Dark theme: Use lower lightness values (10-40%)
- •Keep saturation similar for color harmony
Examples
Add a success color
tsx
/* In src/app/globals.css */
:root {
--success: 142 76% 36%; /* Green for light mode */
--success-foreground: 0 0% 100%;
}
.dark {
--success: 142 69% 58%; /* Lighter green for dark mode */
--success-foreground: 0 0% 0%;
}
/* Usage in component */
<div className="bg-success text-success-foreground">
Success message
</div>
Add a new chart color
tsx
/* In src/app/globals.css */
:root {
--chart-6: 280 80% 60%; /* Purple for light mode */
}
.dark {
--chart-6: 280 70% 50%; /* Adjusted purple for dark mode */
}
/* The useChartColors hook can be extended to use it */
const colors = {
...useChartColors(),
chart6: "hsl(var(--chart-6))"
};
Tips
- •Use an HSL color picker for easy value adjustment
- •Test accessibility with tools like WebAIM Contrast Checker
- •Keep the HSL format consistent (no hsl() wrapper in CSS)
- •Chart colors should be visually distinct from each other
- •Theme colors automatically apply to shadcn/ui components
Related Files
- •
src/app/globals.css - •
src/components/DashboardCharts.tsx
Related Skills
- •
add-chart - •
add-shadcn-component