Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add preliminary dark theme implementation
  • Loading branch information
septatrix committed Nov 18, 2022
commit b888ef79dc967ab7afa56efd7dd87820fecbc00c
11 changes: 11 additions & 0 deletions python_docs_theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,24 @@ <h3>{{ _('Navigation') }}</h3>
{% block relbar1 %} {% if builder != 'qthelp' %} {{ relbar() }} {% endif %} {% endblock %}
{% block relbar2 %} {% if builder != 'qthelp' %} {{ relbar() }} {% endif %} {% endblock %}

{% block relbaritems %}
{%- if pagename != "search" and builder != "singlehtml" and builder != "htmlhelp" %}
<li class="right">
{{ searchbox() }}
{{ reldelim2 }}
</li>
{%- endif %}
<li class="right"><input type="button" value="Toggle theme" class="theme-toggle" onclick="toggleTheme()">{{ reldelim2 }}</li>
{% endblock %}

{%- block extrahead -%}
<link rel="stylesheet" href=/proxy/https/github.com/python/python-docs-theme/pull/44/commits/&quot;%7B%7B pathto('_static/pydoctheme_dark.css', 1) }}" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
<link rel="shortcut icon" type="image/png" href=/proxy/https/github.com/python/python-docs-theme/pull/44/commits/&quot;%7B%7B pathto('_static/' + theme_root_icon, 1) }}" />
{%- if builder != "htmlhelp" %}
{%- if not embedded %}
<script type="text/javascript" src=/proxy/https/github.com/python/python-docs-theme/pull/44/commits/&quot;%7B%7B pathto('_static/copybutton.js', 1) }}"></script>
<script type="text/javascript" src=/proxy/https/github.com/python/python-docs-theme/pull/44/commits/&quot;%7B%7B pathto('_static/menu.js', 1) }}"></script>
<script type="text/javascript" src=/proxy/https/github.com/python/python-docs-theme/pull/44/commits/&quot;%7B%7B pathto('_static/themetoggle.js', 1) }}"></script>
{%- endif -%}
{%- endif -%}
{{ super() }}
Expand Down
93 changes: 67 additions & 26 deletions python_docs_theme/static/pydoctheme.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
@import url("default.css");
@import url('classic.css');

/* unset some styles from the classic stylesheet */
div.document,
div.body,
div.related,
div.body h1,
div.body h2,
div.body h3,
div.body h4,
div.body h5,
div.body h6,
div.sphinxsidebar a,
div.sphinxsidebar p,
div.sphinxsidebar ul,
div.sphinxsidebar h3,
div.sphinxsidebar h3 a,
div.sphinxsidebar h4,
table.docutils td,
table.indextable tr.cap,
pre {
background-color: inherit;
color: inherit;
}

body {
background-color: white;
margin-left: 1em;
margin-right: 1em;
}
Expand All @@ -14,19 +36,24 @@ body {
div.related {
margin-bottom: 1.2em;
padding: 0.5em 0;
border-bottom: 1px solid #ccc;
border-top: 1px solid #ccc;
margin-top: 0.5em;
}

div.related a:hover {
color: #0095C4;
color: #0095c4;
}

div.related ~ div.related {
border-top: 1px solid #ccc;
border-bottom: none;
}

div.related:first-child {
border-top: 0;
border-bottom: 1px solid #ccc;
}

.related .switchers {
display: inline-flex;
}
Expand All @@ -41,13 +68,19 @@ div.related ~ div.related {
background-color: white;
}

.inline-search {
display: inline;

div.related ul::after {
content: '';
clear: both;
display: block;
}

.inline-search,
form.inline-search input {
display: inline;
}
form.inline-search input[type="submit"] {

form.inline-search input[type='submit'] {
width: 40px;
}

Expand All @@ -60,13 +93,15 @@ div.sphinxsidebar {
position: sticky;
top: 0;
max-height: 100vh;
background-color: #eeeeee;
color: #444;
background-color: #eee;
border-radius: 5px;
line-height: 130%;
font-size: smaller;
}

div.sphinxsidebar h3, div.sphinxsidebar h4 {
div.sphinxsidebar h3,
div.sphinxsidebar h4 {
margin-top: 1.5em;
}

Expand All @@ -86,18 +121,19 @@ div.sphinxsidebarwrapper > ul > li > ul > li {
}

div.sphinxsidebar a:hover {
color: #0095C4;
color: #0095c4;
}

form.inline-search input,
div.sphinxsidebar input {
font-family: 'Lucida Grande',Arial,sans-serif;
div.sphinxsidebar input,
div.related input {
font-family: 'Lucida Grande', Arial, sans-serif;
border: 1px solid #999999;
font-size: smaller;
border-radius: 3px;
}

div.sphinxsidebar input[type=text] {
div.sphinxsidebar input[type='text'] {
max-width: 150px;
}

Expand Down Expand Up @@ -126,7 +162,8 @@ div.body pre {
border: 1px solid #ac9;
}

div.body div.admonition, div.body div.impl-detail {
div.body div.admonition,
div.body div.impl-detail {
border-radius: 3px;
}

Expand All @@ -147,23 +184,28 @@ div.body a:visited {
}

div.body a:hover {
color: #00B0E4;
color: #00b0e4;
}

tt, code, pre {
font-family: "monospace", monospace;
font-size: 96.5%;
}

div.body tt, div.body code {
div.body tt,
div.body code {
border-radius: 3px;
}

div.body tt.descname, div.body code.descname {
div.body tt.descname,
div.body code.descname {
font-size: 120%;
}

div.body tt.xref, div.body a tt, div.body code.xref, div.body a code {
div.body tt.xref,
div.body a tt,
div.body code.xref,
div.body a code {
font-weight: normal;
}

Expand All @@ -175,12 +217,14 @@ table.docutils {
margin-bottom: 10px;
}

table.docutils td, table.docutils th {
table.docutils td,
table.docutils th {
border: 1px solid #ddd !important;
border-radius: 3px;
}

table p, table li {
table p,
table li {
text-align: left !important;
}

Expand All @@ -194,7 +238,8 @@ table.docutils td {
padding: 0.3em 0.5em;
}

table.footnote, table.footnote td {
table.footnote,
table.footnote td {
border: 0 !important;
}

Expand All @@ -207,7 +252,7 @@ div.footer {
}

div.footer a:hover {
color: #0095C4;
color: #0095c4;
}

.refcount {
Expand All @@ -218,10 +263,6 @@ div.footer a:hover {
color: #229;
}

.highlight {
background: none !important;
}

dl > dt span ~ em {
font-family: "monospace", monospace;
}
Expand Down
119 changes: 119 additions & 0 deletions python_docs_theme/static/pydoctheme_dark.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@

/* Browser elements */
:root {
scrollbar-color: #616161 transparent;
color-scheme: dark light;
}

html,
body {
background-color: #222;
color: rgba(255, 255, 255, 0.87);
}

div.related {
color: rgba(255, 255, 255, 0.7); /* classic overwrite */
border-top-color: #424242;
}

div.related:first-child {
/* use :first-child because border-color would need !important */
border-bottom-color: #424242;
}

/* SIDEBAR */
div.sphinxsidebar {
background-color: #333;
color: inherit;
}

#sidebarbutton {
/* important to overwrite style attribute */
background-color: #555 !important;
color: inherit !important;
}

div.sidebar {
background-color: #424242;
border-color: #616161;
}

/* ANCHORS AND HIGHLIGHTS */
div.body a {
color: #7af;
}

div.body a:visited {
color: #09e;
}

a.headerlink:hover {
background-color: #424242;
}

div.related a {
color: currentColor;
}

div.footer,
div.footer a {
color: currentColor; /* classic overwrites */
}

dt:target,
span.highlighted {
background-color: #616161;
}

/* Below for most things in text */

dl.field-list > dt {
background-color: #434;
}

table.docutils td,
table.docutils th {
border-color: #616161 !important;
}

table.docutils th {
background-color: #424242;
}

.refcount {
color: #afa;
}

.stableabi {
color: #bbf;
}

div.body pre {
border-color: #616161;
}

code {
background-color: #424242;
}

div.body div.seealso {
background-color: rgba(255, 255, 0, 0.1);
}

div.warning {
background-color: rgba(255, 0, 0, 0.2);
}

.warning code {
background-color: rgba(255, 0, 0, 0.5);
}

div.topic,
div.note {
background-color: rgba(255, 255, 255, 0.1);
border-color: currentColor;
}

.note code {
background-color: rgba(255, 255, 255, 0.1);
}
39 changes: 39 additions & 0 deletions python_docs_theme/static/themetoggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
let currentTheme = localStorage.getItem('currentTheme') || 'auto'

const pygmentsDark = document.getElementById('pygments_dark_css')
const pydocthemeDark = document.getElementById('pydoctheme_dark_css')

const themeOrder = {
light: 'dark',
dark: 'auto',
auto: 'light',
}

updateTheme()

function toggleTheme() {
currentTheme = themeOrder[currentTheme]
localStorage.setItem('currentTheme', currentTheme)
updateTheme()
}

function updateTheme() {
const buttons = Array.from(document.getElementsByClassName('theme-toggle'))
switch (currentTheme) {
case 'light':
pydocthemeDark.media = 'not all'
pygmentsDark.media = 'not all'
buttons.forEach(e => e.value = "Toggle theme (light)")
break;
case 'dark':
pydocthemeDark.media = 'all'
pygmentsDark.media = 'all'
buttons.forEach(e => e.value = "Toggle theme (dark)")
break;
default:
// auto
pydocthemeDark.media = '(prefers-color-scheme: dark)'
pygmentsDark.media = '(prefers-color-scheme: dark)'
buttons.forEach(e => e.value = "Toggle theme (auto)")
}
}
Loading