theme-toggle
Skill1 starsChanged 5 months agoMITView on GitHub
Add a proper, persisted light/dark theme to a React + Tailwind/CSS-variables site — a ThemeProvider that toggles a `.dark` class on <html>, remembers the choice in localStorage, and a complete CSS token palette for both modes. Includes the trick for keeping intentionally-dark panels (terminals, code blocks) dark in BOTH themes. Use when the user wants a dark/light mode switch, theming that actually works (not half-broken), or to convert a dark-only site to switchable.
In this repository11 other files it gives its agents.
- ask-terminalSkill
- build-themeSkill
- command-paletteSkill
- deploy-doctorSkill
- github-activitySkill
- llm-endpointSkill
- numu-AOV-themesSkill
- numu-store-founderSkill
- og-imageSkill
- scroll-reveal-kitSkill
- seo-kitSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 24
Add a toggle button anywhere:
- Very specific: line 29
Make sure components use token classes (bg-background, text-foreground, text-muted-foreground, border-border, etc.) rather than hardcoded …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Theme Toggle (light / dark)
Switchable light/dark done right: CSS-variable token palettes for both modes, a .dark class on
<html>, persistence, and a useTheme() hook + toggle. Components that use the tokens
(bg-background, text-foreground, border-border, …) adapt automatically.
What it produces
ThemeProvider.tsx— context provider that toggles.darkondocumentElement, persists tolocalStorage, exposesuseTheme() → { theme, toggleTheme }. Defaults to dark (configurable),switchableflag.tokens.css—:root= light palette,.dark= dark palette, for the standard shadcn-style token set (background/foreground/card/primary/secondary/muted/accent/border + syntax colors).
How to use it
- Copy
references/ThemeProvider.tsxand import its CSS tokens (references/tokens.css). - Wrap the app:
<ThemeProvider defaultTheme="dark" switchable>…</ThemeProvider>. - Add a toggle button anywhere:
const { theme, toggleTheme } = useTheme(); <button onClick={toggleTheme}>{theme === "dark" ? "☀︎" : "☾"}</button> - Make sure components use token classes (
bg-background,text-foreground,text-muted-foreground,border-border, etc.) rather than hardcoded colors — those are what flip between modes.
The "keep terminals dark" trick
Terminals / code panels should stay dark even in light mode (a terminal is dark). Since the
tokens are defined on the .dark selector, just add className="dark" to that panel's wrapper —
its descendants inherit the dark token values regardless of the page theme:
<div className="dark bg-black text-foreground">…terminal stays dark & readable in both modes…</div>Gotchas
- Define tokens on
:root(light) and.dark— not the reverse. Apply.darkto<html>so it cascades everywhere (incl. portals/dialogs). - Hardcoded hex colors (
#1e1e1e,text-[#d4d4d4]) won't theme — convert them to tokens, or leave a page intentionally dark by scoping it with.dark. - Raise
--muted-foregroundlightness for light mode (low-contrast gray is the usual readability complaint). - Tailwind v4: tokens map via
@theme; v3: viatailwind.configtheme.extend.colors.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

