Skip to content

Commit

Permalink
add optional dark mode to API docs
Browse files Browse the repository at this point in the history
  • Loading branch information
xrstf committed Sep 17, 2023
1 parent fdb1bda commit 4b0cc8d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
41 changes: 35 additions & 6 deletions static/css/style_apiref.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ light grey - rgb(161, 160, 158)
background-color: Gainsboro;
}

body.bg-dark .body-content table tr:nth-child(odd) > td {
background-color: #30363c;
}

body.bg-dark .body-content table tr:nth-child(even) > td {
background-color: #2b3035;
}

.body-content dt {
font-weight: bold;
}
Expand All @@ -65,6 +73,10 @@ light grey - rgb(161, 160, 158)
margin-top: 0;
}

body.text-light a {
color: #47a0ff;
}

/* Brodoc CSS */

body > #wrapper {
Expand Down Expand Up @@ -93,6 +105,14 @@ body > #wrapper {
padding: 0 5px;
}

body.bg-dark #sidebar-wrapper {
background: #343a40;
}

body.text-light #sidebar-wrapper a {
color: #f8f9fa;
}

#sidebar-wrapper ul {
list-style: none;
}
Expand Down Expand Up @@ -122,7 +142,7 @@ body > #wrapper {
}

#page-content-wrapper {
padding-top: 60px;
padding-top: 30px;
}

#page-content-wrapper table tr td:first-child {
Expand Down Expand Up @@ -150,12 +170,16 @@ body > #wrapper {

.body-content p code {
text-overflow: ellipsis;
color: #802060;
color: brown;
display: inline-block;
font-size: smaller;
word-break: break-word;
}

body.text-light .body-content code {
color: #d05252;
}

.body-content blockquote {
border-left: 0;
border-radius: 5px;
Expand All @@ -180,10 +204,6 @@ body > #wrapper {
white-space: pre;
}

.body-content code {
color: Brown !important;
}

.code-block {
display: none;
width: 60%;
Expand Down Expand Up @@ -254,3 +274,12 @@ body > #wrapper {
font-weight: bold;
font-family: monospace;
}

/* button for toggling light/dark mode */
.btn.switch-theme {
white-space: pre;
color: #f8f9fa;

/* button is only useful with JavaScript enabled, so the button is hidden by default */
display: none;
}
15 changes: 15 additions & 0 deletions static/js/scroll-apiref.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,18 @@ jQuery(function($) {
// perform an initial update on the navigation
repaint();
});

/* handle dark/light mode */
jQuery(function($) {
let button = $('.switch-theme');
button.show();

button.on('click', function() {
$('body').toggleClass('bg-dark text-light');
});

// enable dark mode if desired by the user agent
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
$('body').toggleClass('bg-dark text-light');
}
});

0 comments on commit 4b0cc8d

Please sign in to comment.