forked from saopaulobitdevs/saopaulobitdevs.org
-
Notifications
You must be signed in to change notification settings - Fork 1
Adding Darkmode functionality with animations and icons #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
epcgrs
wants to merge
1
commit into
poabitdevs:master
Choose a base branch
from
epcgrs:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -9,3 +9,4 @@ gem "jekyll-sitemap" | |
| gem "jekyll-feed" | ||
| gem "jekyll-seo-tag" | ||
| gem "kramdown-parser-gfm" | ||
| gem "webrick", "~> 1.8" | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ | |
| justify-content: space-between; | ||
|
|
||
| a { | ||
| color: #333; | ||
| color: var(--text, #fff); | ||
| opacity: 0.4; | ||
|
|
||
| &:hover { | ||
|
|
||
This file contains hidden or 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 hidden or 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
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.
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 hidden or 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 +1,74 @@ | ||
| // Place JS here | ||
| ;(function () { | ||
| const STORAGE_KEY = 'poabitdevs-theme'; | ||
| const darkClass = 'dark'; | ||
| const btn = document.getElementById('theme-toggle'); | ||
|
|
||
| if (!btn) return; | ||
|
|
||
| function systemPrefersDark() { | ||
| return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches; | ||
| } | ||
|
|
||
| function applyTheme(isDark, explicit = false) { | ||
| const root = document.documentElement; | ||
| if (explicit) { | ||
| if (isDark) { | ||
| root.classList.add('dark'); | ||
| root.classList.remove('light'); | ||
| } else { | ||
| root.classList.add('light'); | ||
| root.classList.remove('dark'); | ||
| } | ||
| } else { | ||
| if (isDark) root.classList.add(darkClass); | ||
| else root.classList.remove(darkClass); | ||
| } | ||
|
|
||
| const use = btn.querySelector('.theme-icon use'); | ||
| if (use) { | ||
| try { | ||
| use.setAttribute('href', '#' + (isDark ? 'moon' : 'sun')); | ||
| } catch (e) { | ||
| use.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', '#' + (isDark ? 'moon' : 'sun')); | ||
| } | ||
|
epcgrs marked this conversation as resolved.
|
||
| } | ||
|
|
||
| btn.setAttribute('aria-pressed', String(isDark)); | ||
| } | ||
|
|
||
| function loadTheme() { | ||
| const stored = localStorage.getItem(STORAGE_KEY); | ||
| if (stored === 'dark') return { isDark: true, explicit: true }; | ||
| if (stored === 'light') return { isDark: false, explicit: true }; | ||
| return { isDark: systemPrefersDark(), explicit: false }; | ||
| } | ||
|
|
||
| const initial = loadTheme(); | ||
| applyTheme(initial.isDark, initial.explicit); | ||
|
|
||
| btn.addEventListener('click', () => { | ||
| const isDark = document.documentElement.classList.toggle(darkClass); | ||
| if (isDark) { | ||
| document.documentElement.classList.remove('light'); | ||
| document.documentElement.classList.add('dark'); | ||
| } else { | ||
| document.documentElement.classList.remove('dark'); | ||
| document.documentElement.classList.add('light'); | ||
| } | ||
|
epcgrs marked this conversation as resolved.
|
||
| localStorage.setItem(STORAGE_KEY, isDark ? 'dark' : 'light'); | ||
| applyTheme(isDark); | ||
|
|
||
| const icon = btn.querySelector('.theme-icon'); | ||
| if (icon) { | ||
| icon.classList.add('anim'); | ||
| setTimeout(() => icon.classList.remove('anim'), 320); | ||
| } | ||
| }); | ||
|
|
||
| if (window.matchMedia) { | ||
| const mq = window.matchMedia('(prefers-color-scheme: dark)'); | ||
| mq.addEventListener && mq.addEventListener('change', (e) => { | ||
| if (!localStorage.getItem(STORAGE_KEY)) applyTheme(e.matches); | ||
| }); | ||
| } | ||
| })(); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.