-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from Komal73/fix-issue-#26-komal
Fix: #26 (Add Light/Dark Mode)
- Loading branch information
Showing
18 changed files
with
353 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,9 @@ | |
} | ||
|
||
.input-box-title { | ||
color: white; | ||
/* color: white; | ||
*/ | ||
color: var(--text_color); | ||
font-size: 20px; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
.dark_mode { | ||
margin-top: -20px; | ||
margin-left: 10px; | ||
} | ||
|
||
.dark_mode_label { | ||
width: 65px; | ||
height: 30px; | ||
position: relative; | ||
display: block; | ||
background: #ebebeb; | ||
border-radius: 200px; | ||
box-shadow: inset 0px 5px 15px rgba(0, 0, 0, 0.4), | ||
inset 0px -5px 15px rgba(255, 255, 255, 0.4); | ||
cursor: pointer; | ||
transition: 0.3s; | ||
} | ||
.dark_mode_label:after { | ||
content: ""; | ||
width: 25px; | ||
height: 25px; | ||
position: absolute; | ||
top: 3px; | ||
left: 3px; | ||
background: linear-gradient(180deg, #ffcc89, #d8860b); | ||
border-radius: 180px; | ||
box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.2); | ||
transition: 0.3s; | ||
} | ||
.dark_mode_input { | ||
width: 0; | ||
height: 0; | ||
visibility: hidden; | ||
} | ||
.dark_mode_input:checked + .dark_mode_label { | ||
background: #242424; | ||
} | ||
.dark_mode_input:checked + .dark_mode_label:after { | ||
left: 62px; | ||
transform: translateX(-100%); | ||
background: linear-gradient(180deg, #777, #3a3a3a); | ||
} | ||
.dark_mode_label:active:after { | ||
width: 30px; | ||
} | ||
|
||
.dark_mode_label svg { | ||
position: absolute; | ||
width: 20px; | ||
top: 5px; | ||
z-index: 100; | ||
} | ||
.dark_mode_label svg.sun { | ||
left: 5px; | ||
fill: #fff; | ||
transition: 0.3s; | ||
} | ||
.dark_mode_label svg.moon { | ||
left: 40px; | ||
fill: #7e7e7e; | ||
transition: 0.3s; | ||
} | ||
.dark_mode_input:checked + .dark_mode_label svg.sun { | ||
fill: #7e7e7e; | ||
} | ||
.dark_mode_input:checked + .dark_mode_label svg.moon { | ||
fill: #fff; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { ReactComponent as Sun } from "./Sun.svg"; | ||
import { ReactComponent as Moon } from "./Moon.svg"; | ||
import "./Lightmode.css" | ||
|
||
const Lightmode = () => { | ||
const [darkmode, setDarkMode] = useState(false); | ||
|
||
const setDarkModePreference = () => { | ||
document.querySelector("body").setAttribute('data-theme', 'dark'); | ||
localStorage.setItem('theme', 'dark'); | ||
setDarkMode(true); | ||
} | ||
const setLightModePreference = () => { | ||
document.querySelector("body").setAttribute('data-theme', 'light'); | ||
localStorage.setItem('theme', 'light'); | ||
setDarkMode(false); | ||
} | ||
|
||
useEffect(() => { | ||
const savedTheme = localStorage.getItem('theme'); | ||
if (savedTheme === 'dark') { | ||
setDarkModePreference(); | ||
|
||
} else { | ||
setLightModePreference(); | ||
} | ||
}, []); | ||
|
||
const toggletheme = () => { | ||
if(darkmode) | ||
{ | ||
setLightModePreference(); | ||
localStorage.setItem('theme', 'light'); | ||
} | ||
else{ | ||
setDarkModePreference(); | ||
localStorage.setItem('theme', 'dark'); | ||
} | ||
} | ||
|
||
return ( | ||
<div className='dark_mode'> | ||
<input | ||
className='dark_mode_input' | ||
type='checkbox' | ||
id='darkmode-toggle' | ||
checked={darkmode} | ||
onChange={toggletheme} | ||
/> | ||
<label className='dark_mode_label' for='darkmode-toggle'> | ||
<Sun /> | ||
<Moon /> | ||
</label> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Lightmode; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.