diff --git a/components/navbar.tsx b/components/navbar.tsx index cea379e..b6fd5b2 100644 --- a/components/navbar.tsx +++ b/components/navbar.tsx @@ -1,10 +1,10 @@ import React, {Fragment, ReactNode, useState} from "react"; -import {useTheme} from "next-themes"; -import {Disclosure, Switch, Transition} from "@headlessui/react"; +import {Disclosure, Transition} from "@headlessui/react"; import {XIcon, MenuIcon} from "@heroicons/react/outline" import Head from "next/head"; import Link from "next/link"; import Image from "next/image"; +import { ThemeSwitch } from "./themeSwitch"; type Props = { @@ -13,50 +13,6 @@ type Props = { description?: string } -const ThemeSwitch = () => { - const {theme, setTheme} = useTheme(); - const [enabled, setEnabled] = useState(true) - - if(enabled) { - setTheme("dark") - } else { - setTheme("light") - } - - return ( -
- {/* Light -
- - -
- Dark */} - -
- Dark Mode - - - -
-
-
- ) -} - const NavBar = ({children, title = "nickbland.dev | Home", description = "A website made by Nick Bland."}: Props) => { const [isOpen, setIsOpen] = useState(false); return ( diff --git a/components/themeSwitch.tsx b/components/themeSwitch.tsx new file mode 100644 index 0000000..1ac7bb1 --- /dev/null +++ b/components/themeSwitch.tsx @@ -0,0 +1,33 @@ +import React, { useState } from "react"; +import { useTheme } from "next-themes"; +import { Switch } from "@headlessui/react"; + +export const ThemeSwitch = () => { + const { theme, setTheme } = useTheme(); + const [enabled, setEnabled] = useState(true); + + // Use theme requires its own hook which uses Strings. Using an enabled, disabled for a bool hook and following translates that to a string. + if (enabled) { + setTheme("dark"); + } else { + setTheme("light"); + } + + return ( +
+ +
+ Dark Mode + + + +
+
+
+ ); +}; diff --git a/pages/_app.tsx b/pages/_app.tsx index bc35a96..4c893a0 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -5,7 +5,7 @@ import {ThemeProvider} from 'next-themes' function MyApp({ Component, pageProps }: AppProps) { return ( <> - +