Skip to content

Commit bcf9b11

Browse files
Properly set theme based first on local storage value then prefers theme media query (#88)
* update initial theme determination function * small styling fixes
1 parent daa7721 commit bcf9b11

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

src/css/asciidoc/source-block.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
position: absolute;
7373
right: 0;
7474
padding: var(--ds-space-1);
75-
height: calc(100% - var(--ds-space-1));
75+
height: calc(100% - var(--ds-space-2));
7676
margin-top: 0.15em;
7777
z-index: 10;
7878
}

src/js/02-on-this-page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
listItem.dataset.level = level
3535
listItem.className = '!m-0'
3636
link.className =
37-
`block py-1 pr-1 !no-underline !text-secondary
37+
`block py-1 pr-1 !no-underline text-body-small
3838
hover:!text-link [&.is-active]:!text-link [&.is-active]:border-[var(--ds-primary-main)] border-l-2`
3939
if (level === 1) link.classList.add('pl-2', 'text-button')
4040
if (level === 2) link.classList.add('pl-4', '!text-tertiary')

src/partials/head-scripts.hbs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,14 @@
4545
/>
4646

4747
<script>
48-
document.documentElement.setAttribute('data-theme', localStorage.getItem('theme') ||
49-
window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light' || 'light')
48+
function getTheme() {
49+
var localStorage = window.localStorage.getItem("theme");
50+
var prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
51+
if (localStorage) return localStorage;
52+
if (prefersDark) return "dark";
53+
return "light";
54+
}
55+
document.documentElement.setAttribute("data-theme", getTheme());
5056
</script>
5157

5258
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@docsearch/css@3" />

src/partials/nav.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{#with page.navigation}}
2-
<nav id="side-nav" class="h-full bg-level1 overflow-y-scroll flex flex-col w-[18.5rem] py-4 px-2"
2+
<nav id="side-nav" class="h-full bg-level1 overflow-y-scroll flex flex-col w-[18.5rem] pt-4 px-2"
33
{{#if page.component}} data-component="{{page.component.name}}"
44
data-version="{{page.version}}" {{/if}}>
55
{{> nav-tree navigation=this}}

0 commit comments

Comments
 (0)