start adding a theme toggle
This commit is contained in:
parent
bb63d6b671
commit
d22f7e4ab2
3 changed files with 38 additions and 0 deletions
|
@ -1,11 +1,13 @@
|
|||
import Title from "./Title";
|
||||
import styles from "../styles/Navbar.module.sass";
|
||||
import ThemeToggle from "./toggle/theme";
|
||||
|
||||
const Navbar = () => {
|
||||
return (
|
||||
<>
|
||||
<div className={styles.center}>
|
||||
<Title />
|
||||
<ThemeToggle/>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
|
26
components/toggle/theme.tsx
Normal file
26
components/toggle/theme.tsx
Normal file
|
@ -0,0 +1,26 @@
|
|||
import styles from "styles/ThemeToggle.module.sass";
|
||||
import { useTheme } from "next-themes";
|
||||
import Icon from "components/Icon";
|
||||
|
||||
function the(t) {
|
||||
switch (t) {
|
||||
case "light":
|
||||
return "dark";
|
||||
case "dark":
|
||||
return "light";
|
||||
}
|
||||
}
|
||||
|
||||
const ThemeToggle = () => {
|
||||
const { resolvedTheme: theme, setTheme } = useTheme();
|
||||
|
||||
return (
|
||||
<>
|
||||
<button data-theme={theme} onClick={() => setTheme(the(theme))} className={styles.button}>
|
||||
<Icon icon="asterisk" />
|
||||
</button>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default ThemeToggle;
|
10
styles/ThemeToggle.module.sass
Normal file
10
styles/ThemeToggle.module.sass
Normal file
|
@ -0,0 +1,10 @@
|
|||
@import "./_variables"
|
||||
|
||||
|
||||
.button
|
||||
color: $text-dark-buttons
|
||||
background: $background-dark-buttons
|
||||
border: none
|
||||
&[data-theme="light"]
|
||||
background: $background-light-buttons
|
||||
color: $text-light-buttons
|
Loading…
Add table
Reference in a new issue