Skip to content
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

Allow for dark mode toggling via keyboard #3526

Open
wants to merge 2 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion _includes/header.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<a id="view-mode-a" title="dark-mode"><img id="view-mode" src="/images/Dim-Night.png"/></a>
<button id="view-mode-toggle" class="theme-selector" type="button" title="Toggle dark mode" aria-pressed="false">
<span class="visually-hidden">Toggle dark mode</span>
<img id="view-mode" alt="" src="/images/Dim-Night.png"/>
</button>

<header role="banner">
<a id="forkme_banner" href="https://github.com/up-for-grabs/up-for-grabs.net">View on GitHub</a>
<div class="container">
Expand Down
41 changes: 24 additions & 17 deletions javascripts/dark-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ define([], () => {
* Apply changes to document to put the page into "dark" mode
*
* @param {HTMLElement} viewModeElement
* @param {HTMLElement} viewModeAnchor
* @param {HTMLElement} viewModeToggleButton
* @param {HTMLElement} goBackHomeElement
*/
function setDarkMode(viewModeElement, viewModeAnchor, goBackHomeElement) {
function setDarkMode(
viewModeElement,
viewModeToggleButton,
goBackHomeElement
) {
root.style.setProperty('--body-back', '#1a2025');
root.style.setProperty('--body-color', '#eeeded');
root.style.setProperty('--abs', 'rgb(39, 47, 55)');
Expand All @@ -33,17 +37,23 @@ define([], () => {

goBackHomeElement.setAttribute('src', '/images/logo_dark_1.png');
viewModeElement.setAttribute('src', '/images/sun-light.png');
viewModeAnchor.title = 'light-mode';
viewModeToggleButton.setAttribute('aria-pressed', 'true');

root.setAttribute('data-theme-preference', 'dark');
}

/**
* Apply changes to document to put the page into "light" mode
*
* @param {HTMLElement} viewModeElement
* @param {HTMLElement} viewModeAnchor
* @param {HTMLElement} viewModeToggleButton
* @param {HTMLElement} goBackHomeElement
*/
function setLightMode(viewModeElement, viewModeAnchor, goBackHomeElement) {
function setLightMode(
viewModeElement,
viewModeToggleButton,
goBackHomeElement
) {
root.style.setProperty('--body-back', '#f9f9f9');
root.style.setProperty('--body-color', '#303030');
root.style.setProperty('--abs', '#FFF');
Expand All @@ -56,7 +66,9 @@ define([], () => {

goBackHomeElement.setAttribute('src', '/images/logo.png');
viewModeElement.setAttribute('src', '/images/Dim-Night.png');
viewModeAnchor.title = 'dark-mode';
viewModeToggleButton.setAttribute('aria-pressed', 'false');

root.setAttribute('data-theme-preference', '');
}

/**
Expand All @@ -79,13 +91,8 @@ define([], () => {
return;
}

const viewModeAnchor = document.getElementById('view-mode-a');
if (!viewModeAnchor) {
return;
}

const goBackHomeAnchor = document.getElementById('go-back-home-a');
if (!goBackHomeAnchor) {
const viewModeToggleButton = document.getElementById('view-mode-toggle');
if (!viewModeToggleButton) {
return;
}

Expand All @@ -95,15 +102,15 @@ define([], () => {
}

if (!lightModeEnabled) {
setDarkMode(viewModeElement, viewModeAnchor, goBackHomeElement);
setDarkMode(viewModeElement, viewModeToggleButton, goBackHomeElement);
}

viewModeAnchor.addEventListener('click', () => {
viewModeToggleButton.addEventListener('click', () => {
if (lightModeEnabled) {
setDarkMode(viewModeElement, viewModeAnchor, goBackHomeElement);
setDarkMode(viewModeElement, viewModeToggleButton, goBackHomeElement);
updateValue('dark');
} else {
setLightMode(viewModeElement, viewModeAnchor, goBackHomeElement);
setLightMode(viewModeElement, viewModeToggleButton, goBackHomeElement);
updateValue('light');
}
});
Expand Down
90 changes: 48 additions & 42 deletions stylesheets/stylesheet.css
Original file line number Diff line number Diff line change
@@ -1,46 +1,34 @@
@import url(pygment_trac.css);

/*******************************************************************************
MeyerWeb Reset
*******************************************************************************/
#view-mode {
position: fixed;
width: 55px;
height: 55px;
z-index: 999;
margin-left: 10px;
}

/* for light mode
--body-back: #f9f9f9;
--body-color:#303030;;
--abs:#FFF ;
--heading-color: #005485;
--container-border: ##dbdbdb;
--databox-bg: #fff
--databox-text: #2e7ba9; */
/* Default [Light Mode] */
:root {
--body-back: #e9eaec;
--body-back: #f9f9f9;
--body-color: #303030;
--abs: #fff;
--box-shadow-color: rgba(0, 0, 0, 0.2);
--abs: #FFF;
--view-mode: true;
--heading-color: #005485;
--container-rgb: 219, 219, 219;
--container-border: rgb(var(--container-rgb));
--container-border: #dbdbdb;
--container-border-alt: #303030;
--databox-bg: #fff;
--databox-text: #2e7ba9;
}

/* for dark mode
/* Dark Mode Preference has been selected */
[data-theme-preference=dark]:root {
--body-back: #1a2025;
--body-color:#eeeded;
--abs:rgb(38 45 49) ;
--body-color: #eeeded;
--abs: rgb(39 47 55);
--box-shadow-color: rgba(27, 30, 33, 0.5);
--heading-color: #7bc6f2;
--container-border: transparent
--databox-bg: #32404d;
--databox-text: #7bceff; */
--container-border: transparent;
--container-border-alt: #dbdbdb;
--databox-bg: #32404d;
--databox-text: #7bceff;
}

/*******************************************************************************
MeyerWeb Reset
*******************************************************************************/

html,
body,
Expand Down Expand Up @@ -238,7 +226,27 @@ img {
}

button {
border: none;
border-color: transparent;
}

.theme-selector {
position: fixed;
width: 55px;
height: 55px;
z-index: 999;
background: transparent;
cursor: pointer;
}

.theme-selector .visually-hidden {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}

#go-back-home {
Expand Down Expand Up @@ -1030,23 +1038,21 @@ ul.popular-tags li {
}

.fork-count {
display: flex;
margin-top: 10px;
height: max-content;
cursor: pointer;
position: relative;
}

.fork-count:hover .tooltip{
visibility: visible;
display: flex;
margin-top: 10px;
height: max-content;
cursor: pointer;
position: relative;
}

.fork-count:hover .tooltip {
visibility: visible;
}


.fork-count-svg {
align-self: center;
fill: var(--fork-svg-fill);
fill: currentColor;
}

@media screen and (max-width : 670px) {
Expand Down Expand Up @@ -1085,4 +1091,4 @@ ul.popular-tags li {
font-size: 28px;
transition: 0.3s;
}
}
}