Skip to content

Commit

Permalink
Merge pull request #38 from buildkite/dark-mode
Browse files Browse the repository at this point in the history
Dark mode
  • Loading branch information
gilesgas authored Oct 9, 2024
2 parents dcdca34 + 87395ef commit dbb3d87
Show file tree
Hide file tree
Showing 19 changed files with 498 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/frontend/components/copyToClipboardButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const checkedCircleIcon = `

const clipboardDocumentIcon = `
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M8.25 7.5V6.10822C8.25 4.97324 9.09499 4.01015 10.2261 3.91627C10.5994 3.88529 10.9739 3.85858 11.3495 3.83619M15.75 18H18C19.2426 18 20.25 16.9926 20.25 15.75V6.10822C20.25 4.97324 19.405 4.01015 18.2739 3.91627C17.9006 3.88529 17.5261 3.85858 17.1505 3.83619M15.75 18.75V16.875C15.75 15.011 14.239 13.5 12.375 13.5H10.875C10.2537 13.5 9.75 12.9963 9.75 12.375V10.875C9.75 9.01104 8.23896 7.5 6.375 7.5H5.25M17.1505 3.83619C16.8672 2.91757 16.0116 2.25 15 2.25H13.5C12.4884 2.25 11.6328 2.91757 11.3495 3.83619M17.1505 3.83619C17.2152 4.04602 17.25 4.26894 17.25 4.5V5.25H11.25V4.5C11.25 4.26894 11.2848 4.04602 11.3495 3.83619M6.75 7.5H4.875C4.25368 7.5 3.75 8.00368 3.75 8.625V20.625C3.75 21.2463 4.25368 21.75 4.875 21.75H14.625C15.2463 21.75 15.75 21.2463 15.75 20.625V16.5C15.75 11.5294 11.7206 7.5 6.75 7.5Z" stroke="#0F172A" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M8.25 7.5V6.10822C8.25 4.97324 9.09499 4.01015 10.2261 3.91627C10.5994 3.88529 10.9739 3.85858 11.3495 3.83619M15.75 18H18C19.2426 18 20.25 16.9926 20.25 15.75V6.10822C20.25 4.97324 19.405 4.01015 18.2739 3.91627C17.9006 3.88529 17.5261 3.85858 17.1505 3.83619M15.75 18.75V16.875C15.75 15.011 14.239 13.5 12.375 13.5H10.875C10.2537 13.5 9.75 12.9963 9.75 12.375V10.875C9.75 9.01104 8.23896 7.5 6.375 7.5H5.25M17.1505 3.83619C16.8672 2.91757 16.0116 2.25 15 2.25H13.5C12.4884 2.25 11.6328 2.91757 11.3495 3.83619M17.1505 3.83619C17.2152 4.04602 17.25 4.26894 17.25 4.5V5.25H11.25V4.5C11.25 4.26894 11.2848 4.04602 11.3495 3.83619M6.75 7.5H4.875C4.25368 7.5 3.75 8.00368 3.75 8.625V20.625C3.75 21.2463 4.25368 21.75 4.875 21.75H14.625C15.2463 21.75 15.75 21.2463 15.75 20.625V16.5C15.75 11.5294 11.7206 7.5 6.75 7.5Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>`;

const COPY_TIMEOUT = 600;
Expand Down
45 changes: 45 additions & 0 deletions app/frontend/components/themeToggle.js
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();
}
1 change: 1 addition & 0 deletions app/frontend/css/base/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ $navy-600: #4f4a6a;
$navy-700: #383451;
$navy-800: #28243f;
$navy-900: #140d30;
$navy-950: #0e0923;
$gray-100: #f8f8f8;
$gray-200: #f5f5f5;
$gray-300: #eeeeee;
Expand Down
1 change: 1 addition & 0 deletions app/frontend/css/components/_copy_to_clipboard_button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

padding: 0;
border: 0;
color: #0f172a;
}

// Render when focusing sibling (<pre>) element
Expand Down
8 changes: 5 additions & 3 deletions app/frontend/css/components/_global_links.scss
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
.GlobalLinks {
display: flex;
flex-direction: column;
flex-direction: row;
width: 100%;
align-items: center;
justify-content: center;

@media (min-width: $screen-sm) {
flex-direction: row;
@media (min-width: $screen-md) {
justify-content: end;
}
}

Expand Down
1 change: 1 addition & 0 deletions app/frontend/css/components/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
@import "site_header";
@import "status_badges";
@import "tiles";
@import "theme_select";
@import "toc";
3 changes: 3 additions & 0 deletions app/frontend/css/components/_menu_toggle.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
&:checked ~ .SiteHeader__nav,
&:checked ~ .SiteHeader__global-links {
display: flex;
@media (max-width: 959px) {
width: 100%;
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions app/frontend/css/components/_site_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,11 @@
color: map-get($color-aliases, "brand");
}
}

.Wordmark__Brand {
color: #1a002e;
}

.Wordmark__SubBrand {
color: #504581;
}
44 changes: 44 additions & 0 deletions app/frontend/css/components/_theme_select.scss
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;
}
}
Loading

0 comments on commit dbb3d87

Please sign in to comment.