Skip to content

Commit 1b4f054

Browse files
committed
Toggle theme functionality
1 parent 3a5de0b commit 1b4f054

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Contact from './pages/Contact';
99

1010
function App() {
1111
return (
12-
<div className="App">
12+
<div className=" bg-secondary-light dark:bg-primary-dark transition duration-500">
1313
<Router>
1414
<AppHeader></AppHeader>
1515
<Routes>

src/components/AppHeader.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import { FiMoon, FiSun } from 'react-icons/fi';
22
import { Link } from 'react-router-dom';
3+
import ThemeSwitcher from '../hooks/ThemeSwitcher';
34

45
// import logoLight from '../images/logo-light.svg';
56
import logoDark from '../images/logo-dark.svg';
67

78
const AppHeader = () => {
9+
const [activeTheme, setTheme] = ThemeSwitcher();
10+
811
return (
912
<div>
1013
<nav id="nav" className="sm:container sm:mx-auto">
1114
{/* Header start */}
12-
<div className="z-10 max-w-screen-lg xl:max-w-screen-xl block sm:flex sm:justify-between sm:items-center my-6">
15+
<div className="z-10 max-w-screen-lg xl:max-w-screen-xl block sm:flex sm:justify-between sm:items-center py-6">
1316
{/* Header menu links and small screen hamburger menu start */}
1417
<div className="flex justify-between items-center px-4 sm:px-0">
1518
<div>
@@ -103,12 +106,15 @@ const AppHeader = () => {
103106

104107
{/* Theme switcher large screen */}
105108
<div
106-
onClick="toggleTheme"
109+
onClick={() => setTheme(activeTheme)}
107110
aria-label="Theme Switcher"
108111
className="ml-8 bg-primary-light dark:bg-ternary-dark px-3 py-2 shadow-sm rounded-xl cursor-pointer"
109112
>
110-
<FiMoon class="text-liText-ternary-dark hover:text-gray-400 dark:text-liText-ternary-light dark:hover:text-liBorder-primary-light w-5" />
111-
<FiSun class="text-gray-200 hover:text-gray-50 w-5" />
113+
{activeTheme === 'dark' ? (
114+
<FiMoon class="text-liText-ternary-dark hover:text-gray-400 dark:text-liText-ternary-light dark:hover:text-liBorder-primary-light w-5" />
115+
) : (
116+
<FiSun class="text-gray-200 hover:text-gray-50 w-5" />
117+
)}
112118
</div>
113119
</div>
114120
</div>

0 commit comments

Comments
 (0)