mirror of
https://github.com/AmanTahiliani/Portfolio.git
synced 2026-08-07 19:56:16 -04:00
Added Dark and Light mode toggels
This commit is contained in:
12
src/App.css
12
src/App.css
@@ -1,12 +1,12 @@
|
|||||||
.App {
|
.App {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
background-color: black;
|
background-color: var(--background-primary);
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0px;
|
top: 0px;
|
||||||
right: 0px;
|
right: 0px;
|
||||||
left: 0px;
|
left: 0px;
|
||||||
font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif;
|
font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif;
|
||||||
color: azure;
|
color: var(--text-primary);
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
scroll-behavior: smooth;
|
scroll-behavior: smooth;
|
||||||
}
|
}
|
||||||
@@ -38,18 +38,18 @@ section.visible {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.App-header {
|
.App-header {
|
||||||
background-color: black;
|
background-color: var(--background-primary);
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
font-size: calc(10px + 2vmin);
|
font-size: calc(10px + 2vmin);
|
||||||
color: white;
|
color: var(--text-primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.App-link {
|
.App-link {
|
||||||
color: #61dafb;
|
color: var(--accent-primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes App-logo-spin {
|
@keyframes App-logo-spin {
|
||||||
@@ -74,7 +74,7 @@ hr {
|
|||||||
width: 70%;
|
width: 70%;
|
||||||
margin-left: 15% !important;
|
margin-left: 15% !important;
|
||||||
margin-right: 15% !important;
|
margin-right: 15% !important;
|
||||||
border: 10px solid aquamarine;
|
border: 10px solid var(--hr-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.publications, .Experience, .DevTools, .Contact {
|
.publications, .Experience, .DevTools, .Contact {
|
||||||
|
|||||||
29
src/App.js
29
src/App.js
@@ -5,6 +5,9 @@ import {
|
|||||||
Routes,
|
Routes,
|
||||||
useLocation,
|
useLocation,
|
||||||
} from "react-router-dom";
|
} from "react-router-dom";
|
||||||
|
import { ThemeProvider, useTheme } from './context/ThemeContext';
|
||||||
|
import './css/theme.css';
|
||||||
|
import ThemeToggle from './components/ThemeToggle';
|
||||||
import { CSSTransition, TransitionGroup } from "react-transition-group";
|
import { CSSTransition, TransitionGroup } from "react-transition-group";
|
||||||
import "./App.css";
|
import "./App.css";
|
||||||
import "./css/home.css";
|
import "./css/home.css";
|
||||||
@@ -17,6 +20,8 @@ import DevToolsComponent from "./components/devtools";
|
|||||||
import SocialMedia from "./components/SocialMedia";
|
import SocialMedia from "./components/SocialMedia";
|
||||||
|
|
||||||
function Portfolio() {
|
function Portfolio() {
|
||||||
|
const { isDarkMode } = useTheme();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const observer = new IntersectionObserver((entries) => {
|
const observer = new IntersectionObserver((entries) => {
|
||||||
entries.forEach(entry => {
|
entries.forEach(entry => {
|
||||||
@@ -36,6 +41,7 @@ function Portfolio() {
|
|||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
<meta name="Aman Tahiliani's Portfolio"></meta>
|
<meta name="Aman Tahiliani's Portfolio"></meta>
|
||||||
|
<ThemeToggle />
|
||||||
<nav>
|
<nav>
|
||||||
<Header />
|
<Header />
|
||||||
</nav>
|
</nav>
|
||||||
@@ -88,8 +94,11 @@ function Books() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Home() {
|
function Home() {
|
||||||
|
const { isDarkMode } = useTheme();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="home">
|
<div className="home">
|
||||||
|
<ThemeToggle />
|
||||||
<div className="content">
|
<div className="content">
|
||||||
<div className="intro">
|
<div className="intro">
|
||||||
<h1>Welcome to Aman Tahiliani's Space</h1>
|
<h1>Welcome to Aman Tahiliani's Space</h1>
|
||||||
@@ -121,15 +130,17 @@ function Home() {
|
|||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
<Router>
|
<ThemeProvider>
|
||||||
<div>
|
<Router>
|
||||||
<Routes>
|
<div>
|
||||||
<Route path="/" element={<Home />} />
|
<Routes>
|
||||||
<Route path="/portfolio" element={<Portfolio />} />
|
<Route path="/" element={<Home />} />
|
||||||
<Route path="/reviews" element={<Books />} />
|
<Route path="/portfolio" element={<Portfolio />} />
|
||||||
</Routes>
|
<Route path="/reviews" element={<Books />} />
|
||||||
</div>
|
</Routes>
|
||||||
</Router>
|
</div>
|
||||||
|
</Router>
|
||||||
|
</ThemeProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
export default App;
|
export default App;
|
||||||
|
|||||||
19
src/components/ThemeToggle.js
Normal file
19
src/components/ThemeToggle.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { useTheme } from '../context/ThemeContext';
|
||||||
|
import '../css/ThemeToggle.css';
|
||||||
|
|
||||||
|
const ThemeToggle = () => {
|
||||||
|
const { isDarkMode, toggleTheme } = useTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
className="theme-toggle"
|
||||||
|
onClick={toggleTheme}
|
||||||
|
aria-label="Toggle theme"
|
||||||
|
>
|
||||||
|
{isDarkMode ? '☀️' : '🌙'}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ThemeToggle;
|
||||||
26
src/context/ThemeContext.js
Normal file
26
src/context/ThemeContext.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import React, { createContext, useState, useContext } from 'react';
|
||||||
|
|
||||||
|
const ThemeContext = createContext();
|
||||||
|
|
||||||
|
export const ThemeProvider = ({ children }) => {
|
||||||
|
const [isDarkMode, setIsDarkMode] = useState(true);
|
||||||
|
|
||||||
|
const toggleTheme = () => {
|
||||||
|
setIsDarkMode(!isDarkMode);
|
||||||
|
document.documentElement.setAttribute('data-theme', !isDarkMode ? 'dark' : 'light');
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ThemeContext.Provider value={{ isDarkMode, toggleTheme }}>
|
||||||
|
{children}
|
||||||
|
</ThemeContext.Provider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useTheme = () => {
|
||||||
|
const context = useContext(ThemeContext);
|
||||||
|
if (context === undefined) {
|
||||||
|
throw new Error('useTheme must be used within a ThemeProvider');
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
};
|
||||||
30
src/css/ThemeToggle.css
Normal file
30
src/css/ThemeToggle.css
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
.theme-toggle {
|
||||||
|
position: fixed;
|
||||||
|
top: 20px;
|
||||||
|
right: 20px;
|
||||||
|
z-index: 1000;
|
||||||
|
background: none;
|
||||||
|
border: 2px solid var(--accent-primary);
|
||||||
|
color: var(--text-primary);
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
border-radius: 50%;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 20px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-toggle:hover {
|
||||||
|
transform: scale(1.1);
|
||||||
|
background-color: var(--accent-primary);
|
||||||
|
color: var(--background-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-toggle:focus {
|
||||||
|
outline: none;
|
||||||
|
box-shadow: 0 0 0 2px var(--accent-secondary);
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
background-color: #f0f0f0;
|
background-color: var(--background-primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
@@ -22,13 +22,13 @@
|
|||||||
|
|
||||||
.intro h1 {
|
.intro h1 {
|
||||||
font-size: 3em;
|
font-size: 3em;
|
||||||
color: #333;
|
color: var(--text-primary);
|
||||||
animation: slideIn 1s ease-in-out;
|
animation: slideIn 1s ease-in-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
.intro p {
|
.intro p {
|
||||||
font-size: 1.5em;
|
font-size: 1.5em;
|
||||||
color: #666;
|
color: var(--text-secondary);
|
||||||
animation: slideIn 1s ease-in-out;
|
animation: slideIn 1s ease-in-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
|
|
||||||
.intro nav ul li a {
|
.intro nav ul li a {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
color: #3498db;
|
color: var(--link-color);
|
||||||
font-size: 1.2em;
|
font-size: 1.2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +97,6 @@
|
|||||||
.footer {
|
.footer {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 20px 0;
|
padding: 20px 0;
|
||||||
background-color: #f0f0f0;
|
background-color: var(--background-primary);
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
||||||
}
|
}
|
||||||
30
src/css/theme.css
Normal file
30
src/css/theme.css
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
:root[data-theme='light'] {
|
||||||
|
--background-primary: #f0f0f0;
|
||||||
|
--background-secondary: #ffffff;
|
||||||
|
--text-primary: #333333;
|
||||||
|
--text-secondary: #666666;
|
||||||
|
--accent-primary: #3498db;
|
||||||
|
--accent-secondary: #2980b9;
|
||||||
|
--border-color: #dddddd;
|
||||||
|
--section-title: #e74c3c;
|
||||||
|
--link-color: #3498db;
|
||||||
|
--hr-color: #2ecc71;
|
||||||
|
}
|
||||||
|
|
||||||
|
:root[data-theme='dark'] {
|
||||||
|
--background-primary: #000000;
|
||||||
|
--background-secondary: #1a1a1a;
|
||||||
|
--text-primary: #ffffff;
|
||||||
|
--text-secondary: #cccccc;
|
||||||
|
--accent-primary: #61dafb;
|
||||||
|
--accent-secondary: #4fa3d1;
|
||||||
|
--border-color: #333333;
|
||||||
|
--section-title: #ff6b6b;
|
||||||
|
--link-color: #61dafb;
|
||||||
|
--hr-color: #00ffbf;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Theme transition */
|
||||||
|
* {
|
||||||
|
transition: background-color 0.3s ease, color 0.3s ease;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user