-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Прототип тёмной темы * Правит мобильное меню в тёмной теме * Правит очевидные ошибки стилей после обновления верстки * Добавляет переключатель тёмной/светлой темы * Прототип тёмной темы * Правит мобильное меню в тёмной теме * Правит очевидные ошибки стилей после обновления верстки * Добавляет переключатель тёмной/светлой темы * Правит цвет выбранного тега * Merge remote-tracking branch 'upstream/master' into feature/162-dark-mode-prototype # Conflicts: # src/includes/header.njk # src/scripts/index.js * Синхронизирует ветку, обновляет названия переменных, правит ошибки верстки * Меняет цвет посещенных ссылок в тёмной теме * Обновляет svg иконки соцсетей * Обновляет использование масок фотографий для темной темы * Обновляет цвет буквицы в темной теме * Обновляет стили таблиц в темной теме * Обновляет Browserlist и версию Node.js * Добавляет Yaml Lint (#152) * Добавляет Yaml Lint * Добавляет отступ * Обновляет версии экшенов --------- Co-authored-by: Pavel Mineev <[email protected]> Co-authored-by: Vadim Makeev <[email protected]> * Переносит весь код скрпитов в html * Делает весь скрипт отдельным файлом, но инлайнит его в HTML * Удаляет иконки github'а * Правит ошибки стиля в js-коде * Правит стиль кавычек * Удаляет лишнюю запятую * Меняет принцип переключения тем * Правит стили * Правит цвета блоков с кодом в статье об OKLCH * Удаляет пустой блок * Правит опечатку в названии атрибута * Правит вложенность элементов * Добавляет игнорирование атрибутов `media` на элементах `meta` для html-валидатора * Добавляет префикс для токенов * Добавляет обводку лого * Делает иконки контрастнее --------- Co-authored-by: Vadim Makeev <[email protected]> Co-authored-by: Paul <[email protected]> Co-authored-by: Pavel Mineev <[email protected]> Co-authored-by: monochromer <[email protected]> Co-authored-by: monochromer <[email protected]>
- Loading branch information
1 parent
85664cb
commit 82ec6bb
Showing
33 changed files
with
389 additions
and
105 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
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
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 was deleted.
Oops, something went wrong.
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
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,20 @@ | ||
<section class="scheme-switcher" aria-label="Цветовая тема"> | ||
<button class="scheme-switcher__button" type="button" value="dark" aria-pressed="false" title="Тёмная"> | ||
<svg class="scheme-switcher__icon" aria-hidden="true" width="20" height="20"> | ||
<use href="/images/sprite.svg#moon"></use> | ||
</svg> | ||
<span class="visually-hidden">Тёмная</span> | ||
</button> | ||
<button class="scheme-switcher__button" type="button" value="auto" aria-pressed="false" title="Системная"> | ||
<svg class="scheme-switcher__icon" aria-hidden="true" width="20" height="20"> | ||
<use href="/images/sprite.svg#duo"></use> | ||
</svg> | ||
<span class="visually-hidden">Системная</span> | ||
</button> | ||
<button class="scheme-switcher__button" type="button" value="light" aria-pressed="false" title="Светлая"> | ||
<svg class="scheme-switcher__icon" aria-hidden="true" width="20" height="20"> | ||
<use href="/images/sprite.svg#sun"></use> | ||
</svg> | ||
<span class="visually-hidden">Светлая</span> | ||
</button> | ||
</section> |
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,85 @@ | ||
const STORAGE_KEY = 'color-scheme'; | ||
|
||
const THEMES = { | ||
AUTO: 'auto', | ||
LIGHT: 'light', | ||
DARK: 'dark', | ||
}; | ||
|
||
const MEDIA = { | ||
ENABLED: 'all', | ||
DISABLED: 'not all', | ||
[THEMES.LIGHT]: '(prefers-color-scheme: light)', | ||
[THEMES.DARK]: '(prefers-color-scheme: dark)', | ||
}; | ||
|
||
const domRefs = { | ||
meta: { | ||
[THEMES.LIGHT]: document.head.querySelector('meta[name=theme-color][media*=prefers-color-scheme][media*=light]'), | ||
[THEMES.DARK]: document.head.querySelector('meta[name=theme-color][media*=prefers-color-scheme][media*=dark]'), | ||
}, | ||
styles: { | ||
[THEMES.LIGHT]: document.head.querySelector('style[media*=prefers-color-scheme][media*=light]'), | ||
[THEMES.DARK]: document.head.querySelector('style[media*=prefers-color-scheme][media*=dark]'), | ||
}, | ||
switcher: null, | ||
}; | ||
|
||
function getCurrentTheme() { | ||
const storedTheme = localStorage.getItem(STORAGE_KEY); | ||
return storedTheme || THEMES.AUTO; | ||
} | ||
|
||
function saveCurrentTheme(theme) { | ||
if (!theme || theme === THEMES.AUTO) { | ||
localStorage.removeItem(STORAGE_KEY); | ||
} else { | ||
localStorage.setItem(STORAGE_KEY, theme); | ||
} | ||
} | ||
|
||
function applyTheme(theme) { | ||
theme = theme ?? getCurrentTheme(); | ||
|
||
if (domRefs.switcher) { | ||
for (const button of domRefs.switcher.querySelectorAll('.scheme-switcher__button')) { | ||
button.setAttribute('aria-pressed', button.value === theme); | ||
} | ||
} | ||
|
||
[ | ||
...Object.entries(domRefs.meta), | ||
...Object.entries(domRefs.styles), | ||
].forEach(([originalTheme, element]) => { | ||
element.media = theme === THEMES.AUTO | ||
? MEDIA[originalTheme] | ||
: theme === originalTheme ? MEDIA.ENABLED : MEDIA.DISABLED; | ||
; | ||
}); | ||
} | ||
|
||
applyTheme(); | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
domRefs.switcher = document.querySelector('.scheme-switcher'); | ||
|
||
domRefs.switcher?.addEventListener('click', (event) => { | ||
const button = event.target.closest('.scheme-switcher__button'); | ||
if (!button) { | ||
return; | ||
} | ||
const theme = button.value; | ||
saveCurrentTheme(theme); | ||
applyTheme(theme); | ||
}); | ||
|
||
window.addEventListener('storage', (event) => { | ||
if (event.key !== STORAGE_KEY) { | ||
return; | ||
} | ||
const newTheme = event.newValue; | ||
applyTheme(newTheme); | ||
}); | ||
|
||
applyTheme(); | ||
}); |
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
Oops, something went wrong.