react-themes-provider
v0.1.2
Published
React theme contexts is a package for and and switch theme of a React.js website or React.js app
Downloads
3
Maintainers
Readme
React Theme Contexts Provider
Themes for your React.js App.
Demo click here 😊.
Install
npm install react-theme-contexts
# yarn
yarn add react-theme-contexts
# pnpm
pnpm install react-theme-contexts
uses
in app.js
// >> app.jsx
import ThemeContextProvider from "react-theme-contexts"
// components
import ThemeSwitcher from "@/theme-switcher"
const App = ({ children }) => {
return (
<ThemeContextProvider>
{children}
<ThemeSwitcher />
</ThemeContextProvider>
);
}
export default App;
Add theme-switcher.js
// >> theme-switcher.jsx
import { useThemeContext } from "react-theme-contexts";
const ThemeSwitcher = () => {
const { switchTheme } = useThemeContext();
return (
<div className="theme-switcher">
<button onClick={() => switchTheme("system")}>System</button>
<button onClick={() => switchTheme("light")}>light</button>
<button onClick={() => switchTheme("dark")}>dark</button>
</div>
);
}
export default ThemeSwitcher;
Add More Themes
There is no limit to add more themes
// >> theme-switcher.jsx
import { useThemeContext } from "react-theme-contexts";
const ThemeSwitcher = () => {
const { addThemes, switchTheme } = useThemeContext();
useEffect(() => {
addThemes(["pink", "yellow", "coral"])
},[])
return (
<div className="theme-switcher">
<button onClick={() => switchTheme("system")}>System</button>
<button onClick={() => switchTheme("light")}>light</button>
<button onClick={() => switchTheme("dark")}>dark</button>
// More themes button
<button onClick={() => switchTheme("pink")}>pink</button>
<button onClick={() => switchTheme("yellow")}>yellow</button>
<button onClick={() => switchTheme("coral")}>coral</button>
</div>
);
}
export default ThemeSwitcher;