Skip to content

Commit 65121d1

Browse files
committed
theme toggle button
1 parent 77aa58a commit 65121d1

8 files changed

Lines changed: 63 additions & 11 deletions

File tree

‎src/App.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class App extends Component {
3232

3333

3434
return (
35-
<div className = "App dark"> {/* SG 07/11/2022 21:21 remove "dark" to enable light theme, working on a toggle button */}
35+
<div className = "App"> {/* SG 07/11/2022 21:21 remove "dark" to enable light theme, working on a toggle button */}
3636

3737
<AppRouter/>
3838

‎src/Utility/Dropdown/dropdown.css‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
.dropdown-menu li {
1616
background: #565960;
1717
cursor: pointer;
18+
color: #63dbf968
1819
}
1920

2021
.dropdown-menu li:hover {

‎src/components/Canvas/InputField.js‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,32 @@ class InputField extends Component {
4242
this.Strategy.setStrategy = this.selectionSort;
4343
this.setState({algorithm: 'Selection'});
4444
}}
45-
className={`cursor-pointer hover:scale-[1.05] transition-all duration-200 ease-in-out border-2 hover:bg-blue-200 hover:border-blue-300 ${algorithm === 'Selection' ? "bg-blue-100 border-blue-300" : "border-gray-300 bg-white dark:bg-gray-300" } min-w-[150px] rounded-xl text-gray-600 flex flex-col p-3 items-center`}>
46-
<p className="font-semibold">Selection Sort</p>
45+
className={`cursor-pointer hover:scale-[1.05] transition-all duration-200 ease-in-out border-2 hover:border-blue-300 ${algorithm === 'Selection' ? "bg-blue-200 dark:bg-transBlue border-blue-300" : "border-gray-300 bg-white dark:bg-gray-300" } min-w-[150px] rounded-xl text-gray-600 flex flex-col p-3 items-center`}>
46+
<p className={`font-semibold ${algorithm === 'Selection' && "dark:text-white"}`}>Selection Sort</p>
4747
</div>
4848

4949
<div onClick={() => {
5050
this.Strategy.setStrategy = this.mergeSort;
5151
this.setState({algorithm: 'Merge'});
5252
}}
53-
className={`cursor-pointer hover:scale-[1.05] transition-all duration-200 ease-in-out border-2 hover:bg-blue-200 hover:border-blue-300 ${algorithm === 'Merge' ? "bg-blue-100 border-blue-300" : "border-gray-300 bg-white dark:bg-gray-300"} min-w-[150px] rounded-xl text-gray-600 flex flex-col p-3 items-center`}>
54-
<p className="font-semibold">Merge Sort</p>
53+
className={`cursor-pointer hover:scale-[1.05] transition-all duration-200 ease-in-out border-2 hover:border-blue-300 ${algorithm === 'Merge' ? "bg-blue-200 dark:bg-transBlue border-blue-300" : "border-gray-300 bg-white dark:bg-gray-300"} min-w-[150px] rounded-xl text-gray-600 flex flex-col p-3 items-center`}>
54+
<p className={`font-semibold ${algorithm === 'Merge' && "dark:text-white"}`}>Merge Sort</p>
5555
</div>
5656

5757
<div onClick={() => {
5858
this.Strategy.setStrategy = this.selectionSort;
5959
this.setState({algorithm: 'Quick'});
6060
}}
61-
className={`cursor-pointer hover:scale-[1.05] transition-all duration-200 ease-in-out border-2 hover:bg-blue-200 hover:border-blue-300 ${algorithm === 'Quick' ? "bg-blue-100 border-blue-300" : "border-gray-300 bg-white dark:bg-gray-300"} min-w-[150px] rounded-xl text-gray-600 flex flex-col p-3 items-center`}>
62-
<p className="font-semibold">Quick Sort</p>
61+
className={`cursor-pointer hover:scale-[1.05] transition-all duration-200 ease-in-out border-2 hover:border-blue-300 ${algorithm === 'Quick' ? "bg-blue-200 dark:bg-transBlue border-blue-300" : "border-gray-300 bg-white dark:bg-gray-300"} min-w-[150px] rounded-xl text-gray-600 flex flex-col p-3 items-center`}>
62+
<p className={`font-semibold ${algorithm === 'Quick' && "dark:text-white"}`}>Quick Sort</p>
6363
</div>
6464

6565
<div onClick={() => {
6666
this.Strategy.setStrategy = this.radixSortLSD;
6767
this.setState({algorithm: 'Radix'});
6868
}}
69-
className={`cursor-pointer hover:scale-[1.05] transition-all duration-200 ease-in-out border-2 hover:bg-blue-200 hover:border-blue-300 ${algorithm === 'Radix' ? "bg-blue-100 border-blue-300" : "border-gray-300 bg-white dark:bg-gray-300"} min-w-[150px] rounded-xl text-gray-600 flex flex-col p-3 items-center`}>
70-
<p className="font-semibold">Radix Sort</p>
69+
className={`cursor-pointer hover:scale-[1.05] transition-all duration-200 ease-in-out border-2 hover:border-blue-300 ${algorithm === 'Radix' ? "bg-blue-200 dark:bg-transBlue border-blue-300" : "border-gray-300 bg-white dark:bg-gray-300"} min-w-[150px] rounded-xl text-gray-600 flex flex-col p-3 items-center`}>
70+
<p className={`font-semibold ${algorithm === 'Radix' && "dark:text-white"}`}>Radix Sort</p>
7171
</div>
7272

7373
</div>
@@ -81,7 +81,7 @@ class InputField extends Component {
8181
? this.props.InputHandler.setState({inputArrayLength: e.target.value.replace(/\D/g, '')})
8282
: this.props.InputHandler.setState({inputArrayLength: InputHandler.getAllowedMaxInputSize()})
8383
}}
84-
className=" bg-gray-200 dark:bg-gray-300 rounded-lg text-center p-[.7em] font-medium w-[57%] sm:w-100"
84+
className=" bg-gray-200 dark:bg-gray-300 rounded-full text-center p-[.7em] font-medium w-[57%] sm:w-100"
8585
maximum={InputHandler.getAllowedMaxInputSize()}
8686
/>
8787
<button onClick={() => {

‎src/components/Page/partial/Navbar/Navigation.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import './navbar.css';
44

55
import {Button} from '../GenericButton/Button';
66
import Dropdown from '../../../../Utility/Dropdown/Dropdown';
7+
import ThemeToggle from './ThemeToggle';
78

89

910

@@ -94,6 +95,7 @@ function Navigation() {
9495
</Link>
9596
</li>
9697
</ul>
98+
<ThemeToggle/>
9799
</nav>
98100
</>
99101
);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React, { useEffect, useState } from 'react'
2+
import { ReactComponent as Moon } from '../../../../img/moon.svg'
3+
import { ReactComponent as Sun } from '../../../../img/sun.svg'
4+
const ThemeToggle = () => {
5+
6+
const [night, setNightMode] = useState(false);
7+
8+
9+
useEffect(() => {
10+
if (JSON.parse(localStorage.getItem('dark')) || night) {
11+
document.documentElement.classList.add('dark');
12+
setNightMode(true);
13+
} else {
14+
document.documentElement.classList.remove('dark')
15+
setNightMode(false);
16+
}
17+
}, [night])
18+
19+
return (
20+
<div className={`${night ? 'bg-gradient-to-r from-gray-900 to-gray-800' : "bg-gradient-to-r from-gray-300 to-white"} w-[3.5em] h-[36px] bg-white rounded-full relative border-[2px] border-gray-400`}
21+
onClick={() => {
22+
setNightMode(!night)
23+
localStorage.setItem("dark", !night);
24+
}}>
25+
<div className={`transition-all duration-300 ease-in-out absolute w-[28px] h-[28px] bg-gray-100 shadow-sm ${night ? "top-[.1em] translate-x-[1.75em] shadow-black" : " shadow-gray-400 top-[.1em] translate-x-[.1em]"} rounded-full`}>
26+
<div className={`transition-all duration-300 ease-in-out absolute w-[26px] h-[26px] bg-gray-200 top-[3%] left-[7%] rounded-full flex items-center justify-center`}>
27+
{night ? <Moon className={`text-gray-800 scale-[.8]`}/> : <Sun className={`text-gray-500 scale-[.8]`}/>}
28+
</div>
29+
</div>
30+
</div>
31+
)
32+
}
33+
34+
export default ThemeToggle

‎src/img/moon.svg‎

Lines changed: 3 additions & 0 deletions
Loading

‎src/img/sun.svg‎

Lines changed: 11 additions & 0 deletions
Loading

‎tailwind.config.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ module.exports = {
1212
"lightDark": "#20232A",
1313
"darkGray": "#282C34",
1414
"lightGray": "#33373E",
15-
"lightBlue": "#63DAF9"
15+
"lightBlue": "#63DAF9",
16+
"transBlue": "#63dbf968",
1617
}
1718

1819
},

0 commit comments

Comments
 (0)