Create ThemeSwitcher btn
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import Button from "../button/button.jsx";
|
||||
import React from "react";
|
||||
|
||||
export default function ThemeSwitcher() {
|
||||
|
||||
const switchTheme = () => {
|
||||
|
||||
const currentTheme = localStorage.getItem("theme");
|
||||
let newTheme = currentTheme === "light" ? "dark" : "light";
|
||||
|
||||
if(currentTheme === null) newTheme = "dark";
|
||||
|
||||
localStorage.setItem("theme", newTheme);
|
||||
|
||||
window.dispatchEvent(new Event("theme-changed"));
|
||||
};
|
||||
|
||||
return <Button variant={"default"} onClick={switchTheme}> Changer de thème </Button>
|
||||
}
|
||||
Reference in New Issue
Block a user