|
1 |
| -import React, { useState } from 'react'; |
| 1 | +import React, { useEffect, useState } from 'react'; |
2 | 2 | import logo from '@/assets/images/logo.png';
|
3 | 3 | import { Link, useNavigate } from 'react-router-dom';
|
4 | 4 | import courses from '@/data/courseData';
|
5 | 5 |
|
6 | 6 | function Navbar({ loggedin }) {
|
7 | 7 | const [searchTerm, setSearchTerm] = useState('');
|
8 | 8 | const [suggestions, setSuggestions] = useState([]);
|
| 9 | + const [theme, setTheme] = useState('light'); |
9 | 10 | const navigate = useNavigate();
|
10 | 11 |
|
| 12 | + const toggleTheme = () => { |
| 13 | + const newTheme = theme === 'light' ? 'dark' : 'light'; |
| 14 | + setTheme(newTheme); |
| 15 | + document.body.setAttribute('data-bs-theme', newTheme) |
| 16 | + }; |
| 17 | + |
11 | 18 | const handleSearchChange = (event) => {
|
12 | 19 | const searchInput = event.target.value;
|
13 | 20 | setSearchTerm(searchInput);
|
@@ -38,8 +45,13 @@ function Navbar({ loggedin }) {
|
38 | 45 | setSuggestions([]);
|
39 | 46 | };
|
40 | 47 |
|
| 48 | + useEffect(() => { |
| 49 | + document.body.setAttribute('data-bs-theme', theme); |
| 50 | + }, []); |
| 51 | + |
| 52 | + |
41 | 53 | return (
|
42 |
| - <nav className="navbar navbar-expand-lg sticky-top bg-body-tertiary"> |
| 54 | + <nav className={`navbar navbar-expand-lg sticky-top bg-body-tertiary navbar-${theme}`}> |
43 | 55 | <div className="container-fluid">
|
44 | 56 | <button
|
45 | 57 | className="navbar-toggler"
|
@@ -114,6 +126,20 @@ function Navbar({ loggedin }) {
|
114 | 126 |
|
115 | 127 | {loggedin === 'true' ? (
|
116 | 128 | <div className="d-flex align-items-center flex-column flex-lg-row">
|
| 129 | + <span className="me-3"> |
| 130 | + <button |
| 131 | + className="btn clk rounded-circle" |
| 132 | + onClick={toggleTheme} |
| 133 | + data-bs-toggle="tooltip" |
| 134 | + title={`Switch to ${theme === 'light' ? 'Dark' : 'Light'} Mode`} |
| 135 | + > |
| 136 | + {theme === 'light' ? ( |
| 137 | + <i className="fa-solid fa-moon"></i> |
| 138 | + ) : ( |
| 139 | + <i className="fa-solid fa-sun"></i> |
| 140 | + )} |
| 141 | + </button> |
| 142 | + </span> |
117 | 143 | <div className="me-2 mb-2 mb-lg-0 position-relative">
|
118 | 144 | <form className="input-group" onSubmit={handleSearchSubmit}>
|
119 | 145 | <span className="input-group-text" id="basic-addon1">
|
|
0 commit comments