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,256 +1,324 @@
/* /*
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;
padding-left: 0;
}
.body-content hr { body {
margin: 2em 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";
border-top: 2px solid dimgrey;
border-bottom: 2px solid antiquewhite;
} }
.body-content table {
margin-bottom: 1em;
overflow: auto;
}
.body-content table th, .body-content table td {
text-align: left;
vertical-align: top;
line-height: 1.5;
}
.body-content table th {
padding: 15px 20px;
border-bottom: 1px solid lightsteelblue;
vertical-align: bottom;
}
.body-content table td {
padding: 10px;
}
.body-content table tr:last-child {
border-bottom: 1px solid lightsteelblue;
}
.body-content table tr:nth-child(odd) > td {
background-color: WhiteSmoke;
}
.body-content table tr:nth-child(even) > td {
background-color: Gainsboro;
}
.body-content dt {
font-weight: bold;
}
.body-content dd {
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 { body > #wrapper {
display: block; padding-bottom: 2rem;
padding-bottom: 500px;
} }
#sidebar-wrapper { a {
display: block; color: #3371e3;
height: 100%;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: whitesmoke;
border-right: 2px solid slategrey;
overflow-x: auto;
padding-top: 30px;
} }
#sidebar-wrapper a { a:hover {
text-decoration: none; color: #0f306e;
white-space: nowrap; text-decoration: none;
overflow: hidden;
text-overflow: ellipsis;
padding: 0 5px;
} }
#sidebar-wrapper ul { .toc-item {
list-style: none; padding-top: 1.2rem;
} }
#sidebar-wrapper a.selected { h1 {
font-style: bold; border-bottom: 3px solid #303030;
color: whitesmoke;
border: 1px solid rgb(161, 160, 158);
background-color: rgb(51, 113, 227);
border-radius: 5px;
} }
#sidebar-wrapper .strong-nav { h2 {
font-family: monospace; border-bottom: 2px solid #303030;
font-weight: bold;
} }
#sidebar-wrapper .nav-level-1.strong-nav { h3.toc-item {
margin-top: 25px; border-bottom: 1px solid #303030;
} }
#sidebar-wrapper .copyright { h1, h2, h3, h4 {
padding-left: 10px; margin-bottom: 1rem;
padding-top: 50px; }
padding-bottom: 50px;
text-decoration: underline; code {
color: #b44;
word-wrap: break-word;
}
.alert > ul:last-child {
margin-bottom: 0;
} }
#page-content-wrapper { #page-content-wrapper {
padding-top: 60px; padding-top: 2rem;
} }
#page-content-wrapper table tr td:first-child { .body-content table {
white-space: pre; margin-bottom: 1em;
overflow: auto;
} }
.body-content h1, .body-content h2 { .body-content table th, .body-content table td {
clear: both; text-align: left;
border-bottom: 3px solid lightslategrey; vertical-align: top;
padding-top: 20px; line-height: 1.5;
} }
.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 { .body-content table th {
padding-top: 20px; padding: 15px 20px;
border-bottom: 1px solid #dee2e6;
vertical-align: bottom;
} }
.body-content table tr td:not(:first-child) { .body-content table td {
overflow-wrap: break-word; padding: 10px;
word-wrap: break-word;
} }
.body-content table tr td a { .body-content table tr:last-child {
word-break: break-word; border-bottom: 1px solid #dee2e6;
} }
.body-content p code { .body-content table tr:nth-child(odd) > td {
text-overflow: ellipsis; background-color: rgba(0,0,0,5%);
color: #802060;
display: inline-block;
font-size: smaller;
word-break: break-word;
} }
.body-content blockquote { .body-content dt {
border-left: 0; font-weight: bold;
border-radius: 5px;
} }
.body-content pre.code-block { .body-content dd {
margin-top: 5px; margin-left: 15px;
margin-bottom: 5px;
} }
.body-content blockquote p, .body-content pre { #sidebar-wrapper {
color: black; display: block;
font-size: 13px; height: 100%;
position: fixed;
width: 100%;
z-index: 1;
top: 0;
left: 0;
background-color: rgba(51, 113, 227, 3%);
border-right: 1px solid #dee2e6;
overflow-x: hidden;
padding-top: .5rem;
} }
.body-content blockquote.code-block { #navigation {
background: Wheat; padding-left: 0;
} }
.body-content pre.code-block code { #navigation a {
word-wrap: normal; color: #222;
white-space: pre; white-space: pre;
line-height: 1.5rem;
/* room to make the .selected style look better */
padding: 0 .2rem;
} }
.body-content code { #navigation a:hover {
color: Brown !important; color: #3371e3;
text-decoration: none;
} }
.code-block { #navigation li {
display: none; list-style-type: none;
width: 60%;
float: left;
clear: right;
} }
.code-block.active { /* make group and version less prominent */
display: initial; #navigation .gvk .v,
#navigation .gvk .g {
font-size: 90%;
opacity: 0.6;
} }
#code-tabs-wrapper { /* reduce indentation for other levels a bit */
width: 55%; #navigation ul {
height: 60px; padding-left: 0.7rem;
/* position: fixed; */
top: 0;
right: 0;
} }
#code-tabs-wrapper .code-tab-list { #navigation .level-1,
float: right; #navigation .level-2 {
margin-top: 0; padding-top: .5rem;
padding: 0 10px;
} }
#code-tabs-wrapper .code-tab { /* mark the first TOC layer */
color: white; #navigation .level-1 > a {
/* display: inline-block; */ font-weight: 700;
padding: 0 30px;
background: rgb(48, 48, 48);
border: 1px solid rgb(161, 160, 158);
border-radius: 5px;
} }
#code-tabs-wrapper .tab-selected { /* at the opposite end, make links thinner */
background: rgb(51, 113, 227); #navigation .level-4 > a {
font-style: bold; font-weight: 300;
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');
});