Skip to content

Navigation Menu

Sign in
Sign up
Emilio Romero edited this page Jun 3, 2026 · 29 revisions

React

import { createContext, useContext, useState, type ReactNode } from 'react';
import Umbra, { type Options } from '@emrocode/umbra';
const options: Partial<Options> = {
 autoMatchTheme: true,
 // useColorScheme: ['#ffffff', '#000000'],
 // useStorage: 'local',
 // usePlugins: []
}
let u = new Umbra('', options);
const ThemeContext = createContext<{
 theme: string;
 toggleTheme: () => void;
} | null>(null);
export const ThemeProvider = ({ children }: { children: ReactNode }) => {
 const [theme, setTheme] = useState<string>(() => u.getCurrentTheme());
 const toggleTheme = () => {
 u.toggleTheme();
 setTheme(u.getCurrentTheme());
 };
 return (
 <ThemeContext.Provider value={{ theme, toggleTheme }}>
 {children}
 </ThemeContext.Provider>
 );
};
export const useTheme = () => {
 const context = useContext(ThemeContext);
 if (!context) {
 throw new Error('useTheme must be used within a ThemeProvider');
 }
 return context;
};

TailwindCSS

v3.x

// tailwind.config.js
darkMode: ['selector', '[data-theme="dark"]']

v4.x

@import "tailwindcss";
@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));
@theme {
 --color-background: #fff;
 --color-foreground: #000;
}
@variant dark {
 --color-background: #000;
 --color-foreground: #fff;
}
@layer base {
 html,
 body {
 @apply bg-background text-foreground;
 }
}

Clone this wiki locally

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /