-
Notifications
You must be signed in to change notification settings - Fork 247
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 #38 from buildkite/dark-mode
Dark mode
- Loading branch information
Showing
19 changed files
with
498 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
export function themeToggle() { | ||
const themeSelect = document.querySelector("#theme-select"); | ||
|
||
function setTheme(theme) { | ||
localStorage.setItem("docs-theme", theme); | ||
updateAppearance(); | ||
} | ||
|
||
function updateAppearance() { | ||
let storedTheme = localStorage.getItem("docs-theme") || "system"; | ||
let systemPrefersDark = window.matchMedia( | ||
"(prefers-color-scheme: dark)" | ||
).matches; | ||
|
||
themeSelect.value = storedTheme; | ||
document | ||
.querySelectorAll(".theme-icon") | ||
.forEach((icon) => icon.classList.add("theme-inactive")); | ||
|
||
if ( | ||
storedTheme === "dark" || | ||
(storedTheme === "system" && systemPrefersDark) | ||
) { | ||
document.documentElement.classList.add("dark"); | ||
} else { | ||
document.documentElement.classList.remove("dark"); | ||
} | ||
|
||
document | ||
.querySelector(`.theme-${storedTheme}`) | ||
.classList.remove("theme-inactive"); | ||
} | ||
|
||
themeSelect.addEventListener("change", function () { | ||
setTheme(this.value); | ||
}); | ||
|
||
window.matchMedia("(prefers-color-scheme: dark)").addListener(function () { | ||
if (localStorage.getItem("docs-theme") === "system") { | ||
updateAppearance(); | ||
} | ||
}); | ||
|
||
updateAppearance(); | ||
} |
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
|
||
padding: 0; | ||
border: 0; | ||
color: #0f172a; | ||
} | ||
|
||
// Render when focusing sibling (<pre>) element | ||
|
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 |
---|---|---|
|
@@ -20,4 +20,5 @@ | |
@import "site_header"; | ||
@import "status_badges"; | ||
@import "tiles"; | ||
@import "theme_select"; | ||
@import "toc"; |
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,44 @@ | ||
.theme-ui { | ||
border-radius: 6px; | ||
border: 1px solid $navy-200; | ||
display: block; | ||
position: relative; | ||
svg { | ||
color: $navy-600; | ||
} | ||
} | ||
|
||
.theme-chevron { | ||
width: 16px; | ||
height: 16px; | ||
position: absolute; | ||
right: 6px; | ||
top: 10px; | ||
pointer-events: none; | ||
} | ||
|
||
.theme-icon { | ||
width: 20px; | ||
position: absolute; | ||
top: 8px; | ||
left: 8px; | ||
pointer-events: none; | ||
} | ||
|
||
.theme-inactive { | ||
display: none; | ||
} | ||
|
||
#theme-select { | ||
appearance: none; | ||
font-size: 14px; | ||
margin-left: 12px; | ||
line-height: 16px; | ||
border: 0 none; | ||
background: transparent; | ||
padding: 10px 24px 10px 20px; | ||
color: currentColor; | ||
&:focus { | ||
outline: none; | ||
} | ||
} |
Oops, something went wrong.