generated from goitacademy/vanilla-app-template
-
Notifications
You must be signed in to change notification settings - Fork 1
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 #7 from Robertw8/dark-theme
Dark theme
- Loading branch information
Showing
7 changed files
with
125 additions
and
32 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,18 +1,19 @@ | ||
@import "./scss/common/reset"; | ||
@import "./scss/common/global"; | ||
@import "./scss/common/typography"; | ||
@import "./scss/utilities/mixins"; | ||
@import "./scss/utilities/variables"; | ||
@import "./scss/partials/header"; | ||
@import "./scss/partials/hero"; | ||
@import "./scss/partials/catalog/catalog"; | ||
@import "./scss/partials/catalog/category-filter"; | ||
@import "./scss/partials/catalog/popular-recipes"; | ||
@import "./scss/partials/catalog/recipes-list"; | ||
@import "./scss/partials/catalog/search-filter"; | ||
@import "./scss/partials/favorites-page"; | ||
@import "./scss/partials/mobile-menu"; | ||
@import "./scss/partials/recipe-popup"; | ||
@import "./scss/partials/order-popup"; | ||
@import "./scss/partials/rating-popup"; | ||
@import "./scss/partials/footer"; | ||
@import './scss/common/reset'; | ||
@import './scss/common/global'; | ||
@import './scss/common/typography'; | ||
@import './scss/utilities/mixins'; | ||
@import './scss/utilities/variables'; | ||
@import './scss/partials/header'; | ||
@import './scss/partials/hero'; | ||
@import './scss/partials/catalog/catalog'; | ||
@import './scss/partials/catalog/category-filter'; | ||
@import './scss/partials/catalog/popular-recipes'; | ||
@import './scss/partials/catalog/recipes-list'; | ||
@import './scss/partials/catalog/search-filter'; | ||
@import './scss/partials/favorites-page'; | ||
@import './scss/partials/mobile-menu'; | ||
@import './scss/partials/recipe-popup'; | ||
@import './scss/partials/order-popup'; | ||
@import './scss/partials/rating-popup'; | ||
@import './scss/partials/footer'; | ||
@import './scss/partials/dark-theme'; |
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,30 @@ | ||
const STORAGE_KEY = 'dark-theme'; | ||
const themeSwitcher = document.getElementById('theme-switcher'); | ||
const isEnabledDarkTheme = localStorage.getItem(STORAGE_KEY) === 'true'; | ||
|
||
setLocalStorageTheme(); | ||
|
||
themeSwitcher.addEventListener('change', setThemeOnClick); | ||
|
||
// Функція для встановлення теми по кліку | ||
function setThemeOnClick(evt) { | ||
const isEnabledDarkTheme = evt.target.checked; | ||
|
||
if (isEnabledDarkTheme) { | ||
document.body.classList.add('dark-theme'); | ||
localStorage.setItem(STORAGE_KEY, 'true'); | ||
} else { | ||
document.body.classList.remove('dark-theme'); | ||
localStorage.removeItem(STORAGE_KEY); | ||
} | ||
} | ||
|
||
// Функція для встановлення теми з localStorage | ||
function setLocalStorageTheme() { | ||
if (isEnabledDarkTheme) { | ||
document.body.classList.add('dark-theme'); | ||
themeSwitcher.querySelector('input').checked = true; | ||
} | ||
} | ||
|
||
export { setLocalStorageTheme, setThemeOnClick }; |
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,51 @@ | ||
#theme-switcher { | ||
position: relative; | ||
display: inline-block; | ||
width: 47px; | ||
height: 20px; | ||
border-radius: 10px; | ||
box-shadow: 7px 5px 15px 0px #a09ea066; | ||
} | ||
|
||
#theme-switcher input { | ||
display: block; | ||
width: 0; | ||
height: 0; | ||
position: absolute; | ||
z-index: -1; | ||
opacity: 0; | ||
} | ||
|
||
#theme-switcher span { | ||
position: absolute; | ||
cursor: pointer; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
background-color: $color-theme-switch-disabled; | ||
transition: 0.4s; | ||
border-radius: 34px; | ||
box-shadow: 4px 4px 15px rgba(243, 243, 243, 0.25); | ||
} | ||
#theme-switcher span:before { | ||
content: ''; | ||
position: absolute; | ||
height: 17px; | ||
width: 17px; | ||
left: 2px; | ||
bottom: 2px; | ||
background-color: $color-white; | ||
transition: 0.2s; | ||
border-radius: 50%; | ||
} | ||
|
||
#theme-switcher input:checked + span { | ||
background: linear-gradient(#9bb537, #9bb537); | ||
box-shadow: 4px 4px 15px rgba(243, 243, 243, 0.25); | ||
} | ||
|
||
#theme-switcher input:checked + span:before { | ||
box-shadow: 4px 4px 15px rgba(243, 243, 243, 0.25); | ||
transform: translateX(26px); | ||
} |
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