diff --git a/src/components/Card.tsx b/src/components/Card.tsx index 384cd40..d03e89f 100644 --- a/src/components/Card.tsx +++ b/src/components/Card.tsx @@ -14,7 +14,7 @@ const Card = ({ directory }: CardProps) => { return (
@@ -27,7 +27,7 @@ const Card = ({ directory }: CardProps) => { className="absolute -top-4 left-8 self-end rounded-2xl" />
-

+

{directory.name}{" "} {directory.verified ? ( sample icon @@ -55,12 +55,12 @@ export function SkeletonCard() { return (

-
+

-
-
-
+
+
+
    -
    -
    -
    {" "} -
    +
    +
    +
    {" "} +
); diff --git a/src/components/DarkModeSwitch.tsx b/src/components/DarkModeSwitch.tsx new file mode 100644 index 0000000..41f1dc6 --- /dev/null +++ b/src/components/DarkModeSwitch.tsx @@ -0,0 +1,57 @@ +import { useEffect, useState } from "react"; +import { TbSun, TbMoon } from "react-icons/tb"; + +const iconDiv = + "absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 transform cursor-pointer transition-opacity duration-200"; + +function DarkModeSwitch() { + //Set light theme by default + const [theme, setTheme] = useState("theme"); + + useEffect(() => { + //Set theme on device + if (typeof window !== "undefined") { + const _theme = + localStorage.theme === "dark" || + (!("theme" in localStorage) && + window.matchMedia("(prefers-color-scheme: dark)").matches) + ? "dark" + : "light"; + changeTheme(_theme); + } + }, [theme]); + + function changeTheme(_theme: string) { + //Set theme on the html tag. + if (_theme === "dark") { + document.documentElement.classList.add("dark"); + } else { + document.documentElement.classList.remove("dark"); + } + setTheme(_theme); + localStorage.setItem("theme", _theme); + } + + return ( +
+
changeTheme("light")} + > + +
+
changeTheme("dark")} + > + +
+
+ ); +} + +export default DarkModeSwitch; diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 502f7d4..82b6ddb 100755 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,6 +1,7 @@ import type { NextPage } from "next"; import { useState } from "react"; import Card, { SkeletonCard } from "@/components/Card"; +import DarkModeSwitch from "@/components/DarkModeSwitch"; import Pagination from "@/components/Pagination"; import Seo from "@/components/Seo"; import { Directory } from "@/interface"; @@ -22,21 +23,24 @@ const Home: NextPage = () => { } return ( -
+
-

+

Web3 Philippines Directory

- - Submit project - +
diff --git a/tailwind.config.js b/tailwind.config.js index c890999..42e799f 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -65,8 +65,12 @@ module.exports = { "neutral-dark": "#19202D", "neutral-light": "#6E8098", "neutral-lightest": "#B0BDCF", + "dark-neutral-light": "#e6dfd2", + "light-bg": "#F2F2F2", + "dark-bg": "#0D0D0D", }, }, }, plugins: [require("@tailwindcss/line-clamp")], + darkMode: "class", };