Skip to content

Add dark theme support with theme switcher using Zustand#75

Merged
LittleLittleCloud merged 5 commits intomainfrom
copilot/add-dark-theme-support
Oct 28, 2025
Merged

Add dark theme support with theme switcher using Zustand#75
LittleLittleCloud merged 5 commits intomainfrom
copilot/add-dark-theme-support

Conversation

Copy link
Contributor

Copilot AI commented Oct 28, 2025

Adds dark theme support to the website with a toggle in the app bar that cycles through System/Light/Dark modes, defaulting to system preference. Theme state is managed using Zustand for optimal performance and simplicity. All components and pages now have comprehensive dark mode support with proper Tailwind CSS classes.

Changes

  • Tailwind configuration: Added darkMode: 'class' to enable manual theme control
  • Zustand store: Lightweight state management for theme with localStorage persistence
  • ThemeToggle component: Cycling button (System → Light → Dark) with appropriate icons (Monitor/Sun/Moon)
  • Layout integration: Theme toggle positioned in app bar between navigation and GitHub link
  • FOUC prevention: Inline script in HTML head applies theme before React hydration
  • Component dark mode support: Added comprehensive dark mode Tailwind classes across all components and pages
  • Theme-aware syntax highlighting: Code blocks dynamically switch between light and dark color schemes

Implementation

Theme management uses Zustand instead of React Context for better performance and simpler API:

type Theme = "light" | "dark" | "system"

// Zustand store
export const useTheme = create<ThemeStore>((set) => ({
    theme: (localStorage.getItem("theme") as Theme) || "system",
    setTheme: (theme: Theme) => {
        localStorage.setItem("theme", theme)
        set({ theme })
    },
}))

// System mode respects OS preference
if (theme === "system") {
  const isDark = window.matchMedia("(prefers-color-scheme: dark)").matches
  root.classList.add(isDark ? "dark" : "light")
}

Benefits of Zustand:

  • No provider wrapper needed - cleaner component tree
  • Better performance through selective subscriptions
  • Less boilerplate code (~20 lines removed)
  • Smaller bundle size (~1KB)

Theme preference persists to localStorage and survives page reloads.

Dark Mode Enhancements

Components Updated:

  • Home.tsx: Feature icons and links with dark mode color variants (dark:text-blue-400, dark:text-violet-400, dark:text-green-400)
  • Markdown.tsx: Dynamic syntax highlighting that switches between atomOneDark (dark) and docco (light) themes
  • Components.tsx: Code blocks with theme-aware backgrounds and borders
  • All existing components: Already included dark mode classes (Card, Button, Tabs, etc.)

All pages (Home, Components, Docs) now provide a cohesive dark mode experience with proper contrast and accessibility.

Screenshots

Light theme:

Dark theme (Home):

Dark theme (Components):

Dark theme (Docs):

Original prompt

This section details on the original issue you should resolve

<issue_title>Website: support dark theme</issue_title>
<issue_description>- Add a theme switch in layout app bar

  • default to system theme, support light / dark theme</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits October 28, 2025 04:43
Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Copilot AI changed the title [WIP] Add theme switch for dark and light modes Add dark theme support with theme switcher Oct 28, 2025
undefined
)

export function ThemeProvider({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot
Don't use useContext; use zustand to manage theme store

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored to use Zustand for theme management in commit 74c7f86. The implementation now uses a Zustand store instead of React Context, eliminating the need for the provider wrapper and simplifying the state management API.

Changes:

  • useTheme is now a Zustand hook that directly accesses the store
  • Added useThemeEffect hook to apply theme changes to the DOM
  • Removed ThemeProvider component wrapper from main.tsx
  • Components use Zustand selectors for better performance

Screenshots:

Light theme:
Light theme

Dark theme:
Dark theme

Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Copilot AI changed the title Add dark theme support with theme switcher Add dark theme support with theme switcher using Zustand Oct 28, 2025
@LittleLittleCloud
Copy link
Member

@copilot
Update components and pages to support light and dark theme via tailwind css

Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 28, 2025

@copilot
Update components and pages to support light and dark theme via tailwind css

Updated all components and pages with comprehensive dark mode Tailwind CSS classes in commit efd811b.

Changes made:

  • Home.tsx: Added dark mode variants for feature icons (dark:text-blue-400, dark:text-violet-400, dark:text-green-400) and link hover states
  • Markdown.tsx: Integrated theme-aware syntax highlighting that switches between atomOneDark (dark) and docco (light) based on current theme
  • Components.tsx: Updated code blocks with theme-aware backgrounds and borders (dark:bg-slate-900, dark:border-slate-700)

All pages (Home, Components, Docs) now fully support both light and dark themes with proper color contrasts and styling.

Screenshots:

Light theme:
Light theme

Dark theme (Home):
Dark theme home

Dark theme (Components):
Dark theme components

Dark theme (Docs):
Dark theme docs

@LittleLittleCloud LittleLittleCloud marked this pull request as ready for review October 28, 2025 07:02
@LittleLittleCloud LittleLittleCloud enabled auto-merge (squash) October 28, 2025 07:03
@LittleLittleCloud LittleLittleCloud merged commit 477186d into main Oct 28, 2025
5 checks passed
@LittleLittleCloud LittleLittleCloud deleted the copilot/add-dark-theme-support branch October 28, 2025 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Website: support dark theme

2 participants