--- description: Use this skill when the user asks to "generate dark mode", "create dark theme", "add dark mode support", "convert to dark mode colors", "generate dark color palette", or wants to automatically generate dark mode variants for their components with intelligent color inversion and accessibility preservation. --- # Dark Mode Generation Skill ## Overview Automatically generate dark mode color schemes from light mode designs with intelligent color inversion, contrast preservation, and accessibility compliance (WCAG 2.2). **Input:** Light mode component **Output:** Dark mode CSS variables, color mappings, theme toggle, updated stories ## How It Works ### 1. Analyze Light Mode Colors Extract all colors from component: ```tsx // Detected colors Background: #FFFFFF Text: #1F2937 (gray-800) Primary: #2196F3 (blue-500) Border: #E5E7EB (gray-200) Shadow: rgba(0, 0, 0, 0.1) ``` ### 2. Generate Dark Palette Apply intelligent transformations: ```css /* Light Mode */ --bg-primary: #FFFFFF; /* white */ --text-primary: #1F2937; /* dark gray */ --color-primary: #2196F3; /* blue */ --border: #E5E7EB; /* light gray */ /* Dark Mode (Generated) */ --bg-primary: #1F2937; /* dark gray (inverted) */ --text-primary: #F9FAFB; /* off-white (inverted) */ --color-primary: #60A5FA; /* lighter blue (adjusted for contrast) */ --border: #374151; /* medium gray (adjusted) */ ``` **Rules:** - Backgrounds: Darken significantly (#FFF → #1F2937) - Text: Lighten for readability (#000 → #F9FAFB) - Brand colors: Adjust for contrast (may lighten or darken) - Borders: Medium grays (#E5E7EB → #374151) - Shadows: Invert or remove (dark shadows on dark BG don't work) ### 3. Preserve Contrast Ratios Ensure WCAG compliance maintained: ``` Light Mode: #1F2937 on #FFFFFF = 16.1:1 (AAA) ✓ Dark Mode: #F9FAFB on #1F2937 = 15.8:1 (AAA) ✓ Light Mode: #2196F3 on #FFFFFF = 3.1:1 (AA Large) ✓ Dark Mode: #60A5FA on #1F2937 = 4.7:1 (AA Normal) ✓ (Improved!) ``` ### 4. Generate Theme System Create complete dark mode implementation: **CSS Variables:** ```css /* themes/colors.css */ :root { --bg-primary: #FFFFFF; --bg-secondary: #F9FAFB; --text-primary: #1F2937; --text-secondary: #6B7280; --color-primary: #2196F3; --border: #E5E7EB; --shadow: rgba(0, 0, 0, 0.1); } [data-theme="dark"] { --bg-primary: #1F2937; --bg-secondary: #111827; --text-primary: #F9FAFB; --text-secondary: #D1D5DB; --color-primary: #60A5FA; --border: #374151; --shadow: rgba(0, 0, 0, 0.3); } ``` **Theme Toggle Component:** ```tsx // components/ThemeToggle.tsx 'use client'; import { useEffect, useState } from 'react'; import { Moon, Sun } from 'lucide-react'; export function ThemeToggle() { const [theme, setTheme] = useState<'light' | 'dark'>('light'); useEffect(() => { const saved = localStorage.getItem('theme') || 'light'; setTheme(saved as 'light' | 'dark'); document.documentElement.setAttribute('data-theme', saved); }, []); const toggleTheme = () => { const newTheme = theme === 'light' ? 'dark' : 'light'; setTheme(newTheme); document.documentElement.setAttribute('data-theme', newTheme); localStorage.setItem('theme', newTheme); }; return ( ); } ``` ### 5. Update Storybook Stories Add dark mode variants: ```tsx // Button.stories.tsx export const LightMode: Story = { parameters: { backgrounds: { default: 'light' }, theme: 'light', }, }; export const DarkMode: Story = { parameters: { backgrounds: { default: 'dark' }, theme: 'dark', }, decorators: [ (Story) => (