Theme Provider
emrocode/theme-providerFreeComponent
A theme provider using @emrocode/umbra
Install it
npx shadcn@latest add https://style.emroco.de/r/theme-provider.jsonSource
1"use client";23import Umbra, { type Options } from "@emrocode/umbra";4import { createContext, type ReactNode, useContext, useState } from "react";5import { KeyboardShortcut } from "./plugins";67const options: Partial<Options> = {8 autoMatchTheme: true,9 useColorScheme: ["#ffffff", "#000000"],10 useStorage: "local",11 usePlugins: [KeyboardShortcut],12};1314const umb = new Umbra(options);1516const ThemeContext = createContext<{17 theme: string;18 toggleTheme: () => void;19} | null>(null);2021export const ThemeProvider = ({ children }: { children: ReactNode }) => {22 const [theme, setTheme] = useState<string>(umb.getCurrentTheme());2324 const toggleTheme = () => {25 umb.toggleTheme();26 setTheme(umb.getCurrentTheme());27 };2829 return (30 <ThemeContext.Provider value={{ theme, toggleTheme }}>31 {children}32 </ThemeContext.Provider>33 );34};3536export const useTheme = () => {37 const context = useContext(ThemeContext);38 if (!context) {39 throw new Error("useTheme must be used within a ThemeProvider");40 }41 return context;42};
What it pulls in
npm packages
Files it writes
More from emrocode
All 6 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| GitHub Cornergithub-corner | emrocode | Components | Free | no deps | |
| Herohero | emrocode | Components | Free | no deps |
