Skip to content

[wip] demo day/night with radios #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 17 additions & 0 deletions pydata_sphinx_theme/docs-navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@
{%- include "search-field.html" %}
{% endif %}

<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">
<label for="pst-mode-day" title="Enable Day Mode">
<i class="fab fas fa-sun"></i>
</label>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<label for="pst-mode-night" title="Enable Night Mode">
<i class="fab fas fa-moon"></i>
</label>
</a>
</li>
</ul>

<ul class="navbar-nav">
{% if theme_github_url | length > 2 %}
<li class="nav-item">
Expand Down
2 changes: 1 addition & 1 deletion pydata_sphinx_theme/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
{%- endif %}
</p>
</div>
</footer>
</footer>
3 changes: 3 additions & 0 deletions pydata_sphinx_theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

{% block body_tag %}
<body data-spy="scroll" data-target="#bd-toc-nav" data-offset="80">
{%- include "modes.html" %}
<div class="pst-main">
{%- endblock %}
{%- block content %}
{% block docs_navbar %}
Expand Down Expand Up @@ -96,4 +98,5 @@

{%- block footer %}
{%- include "footer.html" %}
</div> <!-- end pst-main -->
{%- endblock %}
18 changes: 18 additions & 0 deletions pydata_sphinx_theme/modes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<input id="pst-mode-day" class="pst-visually-hidden" type="radio" name="pst-mode-day-night" checked="checked">
<input id="pst-mode-night" class="pst-visually-hidden" type="radio" name="pst-mode-day-night">

<script>
;(function() {
const MODE = "pst-mode-day-night";
const NIGHT = 'night'
const DAY = 'day';
const night = document.querySelector('#pst-mode-night');
const day = document.querySelector('#pst-mode-day');

day.checked = !(night.checked = localStorage.getItem(MODE) === NIGHT);

[day, night].map((mode) => mode.addEventListener('change', function (event) {
localStorage.setItem(MODE, night.checked ? NIGHT : DAY);
}));
}).call(this);
</script>

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion pydata_sphinx_theme/static/css/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/*****************************************************************************
* Color
*
*
* Colors are defined in rgb string way, "red, green, blue"
**/
--color-primary: 19, 6, 84;
Expand Down Expand Up @@ -74,4 +74,20 @@
--icon-exclamation-circle: '\f06a';
--icon-times-circle: '\f057';
--icon-lightbulb: '\f0eb';

--pst-background: #fff;
--pst-nav-font-color: rgba(var(--color-text-base), 0.5);
}

#pst-mode-night:checked ~ .pst-main {
--color-text-base: 255, 255, 255;
--color-paragraph: 255, 255, 255;
--color-primary: 255, 202, 0;
--color-h1: var(--color-primary);
--color-h2: var(--color-primary);
--color-link: 255, 255, 153;
--color-link-hover: 231, 4, 136;

/* new top-level things */
--pst-background: #050218;
}
6 changes: 3 additions & 3 deletions pydata_sphinx_theme/static/webpack-macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

{% macro head_pre_bootstrap() %}
<link href="{{ pathto('_static/css/theme.css', 1) }}" rel="stylesheet" />
<link href="{{ pathto('_static/css/index.867a4752765d7cafcde5c68b66309846.css', 1) }}" rel="stylesheet" />
<link href="{{ pathto('_static/css/index.86ed8df5e0301cf582c2e9672fd4dc06.css', 1) }}" rel="stylesheet" />
{% endmacro %}

{% macro head_js_preload() %}
<link rel="preload" as="script" href="{{ pathto('_static/js/index.c8075258343c02e88109.js', 1) }}">
<link rel="preload" as="script" href="{{ pathto('_static/js/index.0bd3d3c3320c76629c93.js', 1) }}">
{% endmacro %}

{% macro body_post() %}
<script src="{{ pathto('_static/js/index.c8075258343c02e88109.js', 1) }}"></script>
<script src="{{ pathto('_static/js/index.0bd3d3c3320c76629c93.js', 1) }}"></script>
{% endmacro %}
2 changes: 0 additions & 2 deletions src/scss/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ html {
}

body {
padding-top: 75px;

background-color: white;
font-family: var(--font-family-base);
font-weight: 400;
Expand Down
25 changes: 25 additions & 0 deletions src/scss/_modes.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.pst-main {
background-color: var(--pst-background);

.navbar-light {
background-color: var(--pst-background) !important;

.navbar-nav .nav-link {
color: var(--pst-nav-font-color);
}
}

}


#pst-mode-day:checked ~ .pst-main {
label[for="pst-mode-night"] {
opacity: 0.5;
}
}

#pst-mode-night:checked ~ .pst-main label[for="pst-mode-day"],
#pst-mode-day:checked ~ .pst-main label[for="pst-mode-night"] {
opacity: 0.5;
transition: opacity 0.2s
}
17 changes: 17 additions & 0 deletions src/scss/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ $grid-breakpoints: (
@import './base';
@import './navbar';
@import './admonitions';
@import './modes';

// Custom css, TODO: to be refactored in different partials
div.deprecated {
Expand Down Expand Up @@ -449,3 +450,19 @@ i {
color: #130754;
}
}

.pst-visually-hidden {
position: absolute;
overflow: hidden;
clip: rect(0 0 0 0);
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
border: 0;
white-space: nowrap;
}

.pst-main {
padding-top: 75px;
}