add optional dark mode to API docs (#43084)

pull/43139/head
Christoph Mewes 2023-09-21 04:54:43 +02:00 committed by GitHub
parent 93f6efb176
commit 8f5daeaead
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 275 additions and 189 deletions

View File

@ -1,22 +1,62 @@
/* /*
Kubernetes colors Kubernetes colors (assets/scss/_skin.scss)
kubernetes blue - rgb(50, 109, 230) $blue: #3371e3;
dark blue - rgb(51, 113, 227) $light-grey: #f7f7f7;
dark grey - rgb(48, 48, 48) $dark-grey: #303030;
light grey - rgb(161, 160, 158) $medium-grey: #4c4c4c;
*/ */
/* User agent CSS overrides */ @import url("https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,700,700i&display=swap");
#sidebar-wrapper ul, #sidebar-wrapper li {
margin-left: 10px; body {
padding-left: 0; font-family: "open sans", -apple-system, BlinkMacSystemFont, "segoe ui", Roboto, "helvetica neue", Arial, sans-serif, "apple color emoji", "segoe ui emoji", "segoe ui symbol";
} }
.body-content hr { body > #wrapper {
margin: 2em 0; padding-bottom: 2rem;
border-top: 2px solid dimgrey; }
border-bottom: 2px solid antiquewhite;
a {
color: #3371e3;
}
a:hover {
color: #0f306e;
text-decoration: none;
}
.toc-item {
padding-top: 1.2rem;
}
h1 {
border-bottom: 3px solid #303030;
}
h2 {
border-bottom: 2px solid #303030;
}
h3.toc-item {
border-bottom: 1px solid #303030;
}
h1, h2, h3, h4 {
margin-bottom: 1rem;
}
code {
color: #b44;
word-wrap: break-word;
}
.alert > ul:last-child {
margin-bottom: 0;
}
#page-content-wrapper {
padding-top: 2rem;
} }
.body-content table { .body-content table {
@ -32,7 +72,7 @@ light grey - rgb(161, 160, 158)
.body-content table th { .body-content table th {
padding: 15px 20px; padding: 15px 20px;
border-bottom: 1px solid lightsteelblue; border-bottom: 1px solid #dee2e6;
vertical-align: bottom; vertical-align: bottom;
} }
@ -41,15 +81,11 @@ light grey - rgb(161, 160, 158)
} }
.body-content table tr:last-child { .body-content table tr:last-child {
border-bottom: 1px solid lightsteelblue; border-bottom: 1px solid #dee2e6;
} }
.body-content table tr:nth-child(odd) > td { .body-content table tr:nth-child(odd) > td {
background-color: WhiteSmoke; background-color: rgba(0,0,0,5%);
}
.body-content table tr:nth-child(even) > td {
background-color: Gainsboro;
} }
.body-content dt { .body-content dt {
@ -60,197 +96,229 @@ light grey - rgb(161, 160, 158)
margin-left: 15px; margin-left: 15px;
} }
.body-content p, .body-content li, .body-content dt, .body-content dd {
line-height: 1.6;
margin-top: 0;
}
/* Brodoc CSS */
body > #wrapper {
display: block;
padding-bottom: 500px;
}
#sidebar-wrapper { #sidebar-wrapper {
display: block; display: block;
height: 100%; height: 100%;
position: fixed; position: fixed;
width: 100%;
z-index: 1; z-index: 1;
top: 0; top: 0;
left: 0; left: 0;
background-color: whitesmoke; background-color: rgba(51, 113, 227, 3%);
border-right: 2px solid slategrey; border-right: 1px solid #dee2e6;
overflow-x: auto; overflow-x: hidden;
padding-top: 30px; padding-top: .5rem;
} }
#sidebar-wrapper a { #navigation {
padding-left: 0;
}
#navigation a {
color: #222;
white-space: pre;
line-height: 1.5rem;
/* room to make the .selected style look better */
padding: 0 .2rem;
}
#navigation a:hover {
color: #3371e3;
text-decoration: none; text-decoration: none;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
padding: 0 5px;
} }
#sidebar-wrapper ul { #navigation li {
list-style: none; list-style-type: none;
} }
#sidebar-wrapper a.selected { /* make group and version less prominent */
font-style: bold; #navigation .gvk .v,
color: whitesmoke; #navigation .gvk .g {
border: 1px solid rgb(161, 160, 158); font-size: 90%;
background-color: rgb(51, 113, 227); opacity: 0.6;
border-radius: 5px;
} }
#sidebar-wrapper .strong-nav { /* reduce indentation for other levels a bit */
font-family: monospace; #navigation ul {
font-weight: bold; padding-left: 0.7rem;
} }
#sidebar-wrapper .nav-level-1.strong-nav { #navigation .level-1,
margin-top: 25px; #navigation .level-2 {
padding-top: .5rem;
} }
#sidebar-wrapper .copyright { /* mark the first TOC layer */
padding-left: 10px; #navigation .level-1 > a {
padding-top: 50px; font-weight: 700;
padding-bottom: 50px;
text-decoration: underline;
} }
#page-content-wrapper { /* at the opposite end, make links thinner */
padding-top: 60px; #navigation .level-4 > a {
} font-weight: 300;
#page-content-wrapper table tr td:first-child {
white-space: pre;
}
.body-content h1, .body-content h2 {
clear: both;
border-bottom: 3px solid lightslategrey;
padding-top: 20px;
}
.body-content > h3, .body-content > h4, .body-content > h5, .body-content > h6, .body-content > p, .body-content > aside, .body-content > ul > li, .body-content > ul > li {
padding-top: 20px;
}
.body-content table tr td:not(:first-child) {
overflow-wrap: break-word;
word-wrap: break-word;
}
.body-content table tr td a {
word-break: break-word;
}
.body-content p code {
text-overflow: ellipsis;
color: #802060;
display: inline-block;
font-size: smaller;
word-break: break-word;
}
.body-content blockquote {
border-left: 0;
border-radius: 5px;
}
.body-content pre.code-block {
margin-top: 5px;
margin-bottom: 5px;
}
.body-content blockquote p, .body-content pre {
color: black;
font-size: 13px;
}
.body-content blockquote.code-block {
background: Wheat;
}
.body-content pre.code-block code {
word-wrap: normal;
white-space: pre;
}
.body-content code {
color: Brown !important;
}
.code-block {
display: none;
width: 60%;
float: left;
clear: right;
}
.code-block.active {
display: initial;
}
#code-tabs-wrapper {
width: 55%;
height: 60px;
/* position: fixed; */
top: 0;
right: 0;
}
#code-tabs-wrapper .code-tab-list {
float: right;
margin-top: 0;
padding: 0 10px;
}
#code-tabs-wrapper .code-tab {
color: white;
/* display: inline-block; */
padding: 0 30px;
background: rgb(48, 48, 48);
border: 1px solid rgb(161, 160, 158);
border-radius: 5px;
}
#code-tabs-wrapper .tab-selected {
background: rgb(51, 113, 227);
font-style: bold;
border-radius: 5px;
}
.side-nav a {
color: black;
}
#navigation .nav-level-1,
#navigation .nav-level-2 {
margin-bottom: 1rem;
}
#navigation .nav-level-1 > ul {
margin-top: 1rem;
} }
/* hide operations by default, reveal them via JS */ /* hide operations by default, reveal them via JS */
#navigation li.nav-level-2 ul { #navigation li.level-2 ul {
display: none; display: none;
} }
/* do not indent resources */ /* always hide definitions for brevity sake */
#navigation .nav-level-1 > ul, #navigation #definitions-nav {
#navigation .nav-level-1 > ul > li { display: none !important;
margin-left: 0;
} }
/* make section links / operation categories bold */ /* highlight selected nodes */
#navigation .nav-level-1 > a, #sidebar-wrapper a.selected {
#navigation .nav-level-3 > a { font-weight: 700;
font-weight: bold; color: #dee2e6;
font-family: monospace; border: 1px solid rgb(161, 160, 158);
background-color: rgb(51, 113, 227);
border-radius: .4rem;
}
.samples-container > div {
padding-top: 1rem;
}
.samples-container .panel-heading {
font-style: italic;
}
pre {
background-color: #f8f8f8;
border: 1px solid rgba(0,0,0,.125);
tab-size: 4;
padding: .9rem;
}
/* button for toggling light/dark mode */
.btn.switch-theme {
/* button is only useful with JavaScript enabled, so the button is hidden by default */
display: none;
}
/* handle dark mode theming */
@media (prefers-color-scheme: dark) {
body.theme-auto {
background: #343a40;
color: #f7f7f7;
}
body.theme-auto a {
color: #6c9ffd;
}
body.theme-auto a:hover {
color: #6c9ffd;
text-decoration: underline;
}
body.theme-auto a.btn {
color: #f7f7f7;
text-decoration: none;
}
body.theme-auto h1,
body.theme-auto h2,
body.theme-auto h3.toc-item {
border-color: #f7f7f7;
}
body.theme-auto code {
color: #c97300;
}
body.theme-auto .body-content table tr:nth-child(odd) > td {
background-color: rgba(0,0,0,15%);
}
body.theme-auto #sidebar-wrapper {
background-color: #25292e;
border-color: #2b2b2b;
}
body.theme-auto #navigation a,
body.theme-auto #navigation a.selected:hover {
color: #f7f7f7;
}
body.theme-auto #navigation a.selected {
border-color: #2b2b2b;
}
body.theme-auto #navigation a:hover {
color: #3371e3;
}
body.theme-auto pre {
background-color: #25292e;
border-color: rgba(0,0,0,.125);
}
body.theme-auto .alert a {
color: #3371e3;
}
}
/* same rules (except theme-auto becomes theme-dark), but for enforced dark mode */
body.theme-dark {
background: #343a40;
color: #f7f7f7;
}
body.theme-dark a {
color: #6c9ffd;
}
body.theme-dark a:hover {
color: #6c9ffd;
text-decoration: underline;
}
body.theme-dark a.btn {
color: #f7f7f7;
text-decoration: none;
}
body.theme-dark h1,
body.theme-dark h2,
body.theme-dark h3.toc-item {
border-color: #f7f7f7;
}
body.theme-dark code {
color: #c97300;
}
body.theme-dark .body-content table tr:nth-child(odd) > td {
background-color: rgba(0,0,0,15%);
}
body.theme-dark #sidebar-wrapper {
background-color: #25292e;
border-color: #2b2b2b;
}
body.theme-dark #navigation a,
body.theme-dark #navigation a.selected:hover {
color: #f7f7f7;
}
body.theme-dark #navigation a.selected {
border-color: #2b2b2b;
}
body.theme-dark #navigation a:hover {
color: #3371e3;
}
body.theme-dark pre {
background-color: #25292e;
border-color: rgba(0,0,0,.125);
}
body.theme-dark .alert a {
color: #3371e3;
} }

View File

@ -6,6 +6,7 @@ the website. Please use caution when moving/renaming them.
## Scripts used by API reference ## Scripts used by API reference
- bootstrap-4.3.1.min.js - bootstrap-4.6.1.min.js
- jquery-3.3.1.min.js (indirect dependency from bootstrap-4.3.1.min.js) - jquery-3.6.0.min.js (indirect dependency from bootstrap-4.3.1.min.js)
- jquery.scrollTo-2.1.2.min.js - jquery.scrollTo-2.1.3.min.js
- apiref.js

View File

@ -104,3 +104,20 @@ jQuery(function($) {
// perform an initial update on the navigation // perform an initial update on the navigation
repaint(); repaint();
}); });
/* handle dark/light mode */
jQuery(function($) {
let button = $('.switch-theme');
button.show();
button.on('click', function() {
$('body').toggleClass('theme-dark');
});
// enable dark mode if desired by the user agent
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
$('body').toggleClass('theme-dark');
}
$('body').toggleClass('theme-auto');
});