Skip to content

Commit

Permalink
Merge pull request #2 from udohjeremiah/dev
Browse files Browse the repository at this point in the history
Add code for website's root layout
  • Loading branch information
udohjeremiah authored Nov 4, 2023
2 parents 984466e + 181ebb9 commit 811a827
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 7 deletions.
33 changes: 27 additions & 6 deletions src/app/layout.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
import "./globals.css";
import { Inter } from "next/font/google";
import { Inter, Monoton } from "next/font/google";
import { ThemeProvider } from "@/providers/ThemeProvider";
import Header from "@/components/Header";
import Footer from "@/components/Footer";

export const metadata = {
title: "",
description: "",
title: "Elevate Your Exams | ExamShare",
description:
"An open-source project for sharing past examination questions in higher education",
};

const inter = Inter({
subsets: ["latin"],
display: "swap",
});

const monoton = Monoton({
subsets: ["latin"],
display: "swap",
weight: "400",
variable: "--font-monoton",
});

export default function RootLayout({ children }) {
<html lang="en">
<body className={inter.className}>{children}</body>
</html>;
return (
<html lang="en">
<body
className={`${inter.className} ${monoton.variable} flex min-h-screen max-w-[100vw] flex-col bg-white text-slate-600 antialiased dark:bg-slate-800 dark:text-slate-300`}
>
<ThemeProvider>
<Header />
<main>{children}</main>
<Footer />
</ThemeProvider>
</body>
</html>
);
}
3 changes: 3 additions & 0 deletions src/components/Footer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Header() {
return <div>Footer</div>;
}
3 changes: 3 additions & 0 deletions src/components/Header.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Header() {
return <div>Header</div>;
}
53 changes: 53 additions & 0 deletions src/providers/ThemeProvider.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"use client";

import { createContext, useContext, useState, useEffect } from "react";

const ThemeContext = createContext();

export function useTheme() {
return useContext(ThemeContext);
}

export function ThemeProvider({ children }) {
const [theme, setTheme] = useState(null);

useEffect(() => {
if (!localStorage.getItem("theme")) {
localStorage.setItem("theme", "os");
}
setTheme(localStorage.getItem("theme"));
}, []);

useEffect(() => {
const updateThemeFromOS = (e) => {
if (localStorage.getItem("theme") === "os") {
e.matches
? document.documentElement.classList.add("dark")
: document.documentElement.classList.remove("dark");
}
};
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
updateThemeFromOS(mediaQuery);
mediaQuery.addEventListener("change", updateThemeFromOS);

if (
theme === "dark" ||
(localStorage.getItem("theme") === "os" &&
window.matchMedia("(prefers-color-scheme: dark)").matches)
) {
document.documentElement.classList.add("dark");
} else {
document.documentElement.classList.remove("dark");
}

return () => {
mediaQuery.removeEventListener("change", updateThemeFromOS);
};
}, [theme]);

return (
<ThemeContext.Provider value={{ theme, setTheme }}>
{children}
</ThemeContext.Provider>
);
}
6 changes: 5 additions & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ module.exports = {
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
],
theme: {
extend: {},
extend: {
fontFamily: {
monoton: ["var(--font-monoton)", "sans-serif"],
},
},
},
plugins: [],
};

0 comments on commit 811a827

Please sign in to comment.