Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions toggle-dark/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
35 changes: 35 additions & 0 deletions toggle-dark/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
34 changes: 34 additions & 0 deletions toggle-dark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
98 changes: 98 additions & 0 deletions toggle-dark/app/ThemeSwitcher.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"use client";
import { useState, useEffect } from "react";
import { useTheme } from "next-themes";
import elipse from "./assets/EllipseDark.png"
import elipse2 from "./assets/EllipseWhite.png"
import Image from "next/image";
import retangle from './assets/RectangleDark.png'
import retangle2 from './assets/RectangleWhite.png'
import moon from './assets/moon.svg'
import sun from './assets/sun.svg'

export const ThemeSwitcher = () => {
const [mounted, setMounted] = useState(false);
const { theme, setTheme } = useTheme();


useEffect(() => {
setMounted(true);
}, []);


if (!mounted) {
return null;
}

const playAudio = () => {
const audio = new Audio('https://www.fesliyanstudios.com/play-mp3/385');
audio.playbackRate = 5;
audio.play();
};


return (
<div className="flex justify-center items-center h-screen">
<div className="flex relative h-min flex-col-reverse">
{theme === "light" ? <Image
src={retangle}
alt="rectangle"
className=""
width={180}
height={0}
/> :
<Image
src={retangle2}
alt="rectangle"
className=""
width={180}
height={0}
/>
}
<button
className={`absolute flex ${
theme === "dark" ? "left-1/2" : "right-1/2"
}`}
onClick={() => {setTheme(theme === "dark" ? "light" : "dark")
playAudio();
}}
>
{theme === "light" ?
<>
<Image
src={elipse2}
alt="elipse"
className="relative"
width={150}
height={150}
/>
<Image
src={sun}
alt="elipse"
className="absolute top-1 left-2"
width={70}
height={50}
/>
</>
:
<>
<Image
src={elipse}
alt="elipse"
className="relative"
width={150}
height={150}
/>
<Image
src={moon}
alt="elipse"
className="absolute top-4 left-3"
width={60}
height={50}
/>
</>
}
</button>
</div>
</div>
);
};
Binary file added toggle-dark/app/assets/EllipseDark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added toggle-dark/app/assets/EllipseWhite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added toggle-dark/app/assets/RectangleDark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added toggle-dark/app/assets/RectangleWhite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added toggle-dark/app/assets/buttonDark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added toggle-dark/app/assets/buttonWhite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions toggle-dark/app/assets/moon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions toggle-dark/app/assets/sun.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions toggle-dark/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

36 changes: 36 additions & 0 deletions toggle-dark/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import "./globals.css"
import { Inter } from "next/font/google";
import { ThemeProvider } from "./themeProvider"
import { ThemeSwitcher } from "./ThemeSwitcher";


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


export const metadata = {
title: "Darkmode with Next.js and TailwindCSS",
description:
"I simply app to showcase dark mode with Next.js and TailwindCSS",
};


export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body
className={`${inter.className}
transition-colors duration-1000
dark:bg-dark-800 dark:text-white`}
>
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
<ThemeSwitcher />
<main>{children}</main>
</ThemeProvider>
</body>
</html>
);
}
8 changes: 8 additions & 0 deletions toggle-dark/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Image from 'next/image'
import { ThemeSwitcher } from './ThemeSwitcher'

export default function Home() {
return (
<div />
)
}
8 changes: 8 additions & 0 deletions toggle-dark/app/themeProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use client"
import * as React from "react";
import { ThemeProvider as NextThemesProvider } from "next-themes";
import type { ThemeProviderProps } from "next-themes/dist/types";

export function ThemeProvider({ children, ...props }: ThemeProviderProps) {
return <NextThemesProvider {...props}>{children}</NextThemesProvider>;
}
4 changes: 4 additions & 0 deletions toggle-dark/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {}

module.exports = nextConfig
Loading