Skip to content

Commit 181bf83

Browse files
committed
Theming Done
1 parent 8e38f29 commit 181bf83

File tree

3 files changed

+67
-10
lines changed

3 files changed

+67
-10
lines changed

Countries-Info/app/layout.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
1-
import './globals.css'
2-
import type { Metadata } from 'next'
3-
import { Inter } from 'next/font/google'
1+
import { ThemeProvider } from "@/context/ThemeProvider";
2+
import "./globals.css";
3+
import type { Metadata } from "next";
4+
import { Inter } from "next/font/google";
5+
import Navbar from "@/components/Navbar";
46

5-
const inter = Inter({ subsets: ['latin'] })
7+
const inter = Inter({ subsets: ["latin"] });
68

79
export const metadata: Metadata = {
8-
title: 'Create Next App',
9-
description: 'Generated by create next app',
10-
}
10+
title: "Countries Info",
11+
description:
12+
"Its a website, containing all information about every nation on the planet.",
13+
};
1114

1215
export default function RootLayout({
1316
children,
1417
}: {
15-
children: React.ReactNode
18+
children: React.ReactNode;
1619
}) {
1720
return (
1821
<html lang="en">
19-
<body className={inter.className}>{children}</body>
22+
<body className={inter.className}>
23+
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
24+
<Navbar />
25+
{children}
26+
</ThemeProvider>
27+
</body>
2028
</html>
21-
)
29+
);
2230
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"use client";
2+
3+
import * as React from "react";
4+
import { MoonIcon, SunIcon } from "@radix-ui/react-icons";
5+
import { useTheme } from "next-themes";
6+
7+
import { Button } from "@/components/ui/button";
8+
import {
9+
DropdownMenu,
10+
DropdownMenuContent,
11+
DropdownMenuItem,
12+
DropdownMenuTrigger,
13+
} from "@/components/ui/dropdown-menu";
14+
15+
export function ThemeToggle() {
16+
const { setTheme } = useTheme();
17+
18+
return (
19+
<DropdownMenu>
20+
<DropdownMenuTrigger asChild>
21+
<Button variant="outline" size="icon">
22+
<SunIcon className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0 duration-200" />
23+
<MoonIcon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100 duration-200" />
24+
<span className="sr-only">Toggle theme</span>
25+
</Button>
26+
</DropdownMenuTrigger>
27+
<DropdownMenuContent align="end">
28+
<DropdownMenuItem onClick={() => setTheme("light")}>
29+
Light
30+
</DropdownMenuItem>
31+
<DropdownMenuItem onClick={() => setTheme("dark")}>
32+
Dark
33+
</DropdownMenuItem>
34+
<DropdownMenuItem onClick={() => setTheme("system")}>
35+
System
36+
</DropdownMenuItem>
37+
</DropdownMenuContent>
38+
</DropdownMenu>
39+
);
40+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use client";
2+
3+
import * as React from "react";
4+
import { ThemeProvider as NextThemesProvider } from "next-themes";
5+
import { type ThemeProviderProps } from "next-themes/dist/types";
6+
7+
export function ThemeProvider({ children, ...props }: ThemeProviderProps) {
8+
return <NextThemesProvider {...props}>{children}</NextThemesProvider>;
9+
}

0 commit comments

Comments
 (0)