Skip to content

Global CSS Design Tokens & Light/Dark Mode Toggle#33

Open
YusufsDesigns wants to merge 1 commit intoGroup1-OSS:mainfrom
YusufsDesigns:feature/add-dark-mode
Open

Global CSS Design Tokens & Light/Dark Mode Toggle#33
YusufsDesigns wants to merge 1 commit intoGroup1-OSS:mainfrom
YusufsDesigns:feature/add-dark-mode

Conversation

@YusufsDesigns
Copy link

✨ Global CSS Design Tokens & Light/Dark Mode Toggle

Overview

This PR lays the foundational styling infrastructure for the app. It introduces a full set of global CSS custom properties (design tokens) and implements a light/dark mode toggle that persists the user's preference across sessions.

All tokens are defined on :root and automatically apply to every component teammates build — no extra work needed to support theming.


Changes

style.css

  • Defined a complete set of CSS custom properties on :root covering:
    • Brand & semantic colors (--color-primary, --color-bg, --color-surface, --color-border, --color-text-*, etc.)
    • Typography scale (--font-sans, --font-mono, --text-xs--text-2xl, --font-weight-*)
    • Spacing scale (--space-1--space-12)
    • Shape & depth (--radius-*, --shadow-sm, --shadow-md)
    • Transitions (--transition-fast, --transition-normal)
  • Added [data-theme="dark"] overrides on <html> that swap all surface, background, border, and text color tokens
  • Converted existing base styles (body, #app) to consume the new tokens
  • Added styles for #main-header and the #theme-toggle button, including hover, focus-visible, and transition states

index.html

  • Populated #main-header with an app title and the theme toggle <button>
  • Button includes an icon (<span class="toggle-icon">), a text label (<span class="toggle-label">), and a descriptive aria-label for accessibility

script.js

  • getInitialTheme() — reads from localStorage first, falls back to the OS prefers-color-scheme media query
  • applyTheme(theme) — sets/removes data-theme on <html> and syncs the button icon and label
  • toggleTheme() — switches the active theme and persists the choice to localStorage
  • Listens to prefers-color-scheme changes to stay in sync with OS theme switches, but only when the user hasn't manually overridden it
  • All logic runs in DOMContentLoaded to prevent a flash of the wrong theme on load

Why data-theme on <html>?

Placing the attribute on the root element (rather than a class on <body>) means any component at any nesting depth can scope dark mode overrides with [data-theme="dark"] .my-component without specificity issues. Teammates don't need to think about theming — just use the token variables and it works in both modes automatically.

Why semantic token names?

Tokens like --color-surface and --color-text-secondary are intentionally named by role, not by value. This means a contributor writing a new component just picks the right semantic token and it resolves to the correct color in both light and dark mode — no hex codes, no conditionals.


How to Test

  1. Open the app in a browser
  2. Click the Dark Mode button in the header — the theme should switch instantly with a smooth transition
  3. Refresh the page — your chosen theme should persist
  4. Change your OS appearance setting (System Preferences / Settings) — the app should follow it, but only if you haven't manually toggled it
  5. Tab to the button and press Enter — focus ring should be visible (accessibility check)

Notes for Teammates

  • Always use the CSS variables — never hardcode hex values in component styles
  • Dark mode is handled automatically as long as you use the token variables; no extra CSS is needed
  • The #main-header now has content — if you're working on Issue Design Navigation Bar #3 (header component), please build on top of the existing structure rather than replacing it

Related Issues

Closes #14 — Global Theme & Dark Mode Toggle

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.

Global Theme & Dark Mode Toggle

3 participants