Skip to content
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

Enable dark mode #613

Merged
merged 42 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
853fb26
enable dark mode
kevinsung Jun 12, 2024
e444826
add solid Carbon icons
kevinsung Jun 26, 2024
fe1a883
delete width and height
kevinsung Jun 26, 2024
f12ea6c
increase stroke width of furo icons to better match Carbon
kevinsung Jun 26, 2024
b0e0210
fill="currentColor"
kevinsung Jun 27, 2024
f104bc2
delete rect
kevinsung Jun 27, 2024
5e7a984
fix comment
kevinsung Jun 27, 2024
ff011bb
fix previous releases color
kevinsung Jun 27, 2024
71a54bc
remove leftover comment
kevinsung Jun 27, 2024
05b5486
update png diffs
kevinsung Jun 27, 2024
6d7bc4e
add some tests
kevinsung Jun 27, 2024
df68cef
more test
kevinsung Jun 27, 2024
6499c98
Merge branch 'main' into dark-mode
kevinsung Jul 3, 2024
ce58b44
update screenshots
kevinsung Jul 3, 2024
3e41fbf
update screenshots
kevinsung Jul 3, 2024
ed4476b
update screenshots
kevinsung Jul 3, 2024
3d1641e
update screenshots
kevinsung Jul 3, 2024
8e27914
add dark mode version of every screenshot test
kevinsung Jul 3, 2024
f6d545d
update screenshots
kevinsung Jul 3, 2024
4dd95d7
fix dark mode purple accent
kevinsung Jul 3, 2024
e296f9b
update screenshots
kevinsung Jul 3, 2024
c95ba45
use Purple30 for dark mode
kevinsung Jul 3, 2024
43fd3d2
update screenshots
kevinsung Jul 3, 2024
eb5936e
update screenshots
kevinsung Jul 3, 2024
9439d9e
add copyright notices
kevinsung Jul 3, 2024
4272a17
update screenshots
kevinsung Jul 3, 2024
6f6ebf0
move all hard-coded colors to _colors.scss and use variables
kevinsung Jul 3, 2024
50c4125
update screenshots
kevinsung Jul 3, 2024
c7465e6
move admonitions colors to _colors.scss
kevinsung Jul 3, 2024
49755f0
record names of admonitions colors
kevinsung Jul 3, 2024
bebd216
pick some colors for dark mode admonitions
kevinsung Jul 3, 2024
cb26680
update screenshots
kevinsung Jul 3, 2024
dd37a6d
Merge branch 'main' into dark-mode
kevinsung Jul 3, 2024
ace69a6
use yellow70 for warning background
kevinsung Jul 3, 2024
985eae7
update screenshots
kevinsung Jul 3, 2024
49dc5dc
format
kevinsung Jul 5, 2024
9420e39
define toggleColorTheme (TODO still have to handle "header")
kevinsung Jul 5, 2024
f27793f
handle theme-toggle-header
kevinsung Jul 5, 2024
97c91d2
format test file with prettier
kevinsung Jul 5, 2024
bf72818
DRY test
kevinsung Jul 8, 2024
25d819e
update screenshots
kevinsung Jul 8, 2024
f42086d
refactor top nav bar tests
kevinsung Jul 8, 2024
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
42 changes: 18 additions & 24 deletions src/qiskit_sphinx_theme/assets/styles/_admonitions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,18 @@
// See https://carbondesignsystem.com/guidelines/color/usage and
// https://carbondesignsystem.com/components/notification/style/ for where these colors
// come from.
$info-background: #edf5ff;
$info-border: #0043ce;
$warning-background: #fcf4d6;
$warning-border: #f1c21b;
$error-background: #fff1f1;
$error-border: #da1e28;

.topic {
border: 1px solid $info-background;
border: 1px solid var(--qiskit-color-info-background);
}

p.topic-title {
background-color: $info-background;
background-color: var(--qiskit-color-info-background);

&::before {
-webkit-mask-image: var(--icon-info);
mask-image: var(--icon-info);
background-color: $info-border;
background-color: var(--qiskit-color-info-border);
}
}

Expand Down Expand Up @@ -70,14 +64,14 @@ p.topic-title {
.admonition.caution,
.admonition.important,
.admonition.warning {
border-color: $warning-background;
border-color: var(--qiskit-color-warning-background);

&::before {
background: $warning-border;
background: var(--qiskit-color-warning-border);
}

> .admonition-title {
background-color: $warning-background;
background-color: var(--qiskit-color-warning-background);
}

> .admonition-title::before {
Expand All @@ -90,53 +84,53 @@ p.topic-title {
content: var(--icon-warning);
-webkit-mask-image: unset;
mask-image: unset;
background-color: $warning-background;
background-color: var(--qiskit-color-warning-background);
}
}

.admonition.danger,
.admonition.error {
border-color: $error-background;
border-color: var(--qiskit-color-error-background);

&::before {
background: $error-border;
background: var(--qiskit-color-error-border);
}

> .admonition-title {
background-color: $error-background;
background-color: var(--qiskit-color-error-background);
}

> .admonition-title::before {
-webkit-mask-image: var(--icon-failure);
mask-image: var(--icon-failure);
background-color: $error-border;
background-color: var(--qiskit-color-error-border);
}
}

.admonition,
.admonition.hint,
.admonition.note,
.admonition.tip {
border-color: $info-background;
border-color: var(--qiskit-color-info-background);

&::before {
background: $info-border;
background: var(--qiskit-color-info-border);
}

> .admonition-title {
background-color: $info-background;
background-color: var(--qiskit-color-info-background);
}

> .admonition-title::before {
-webkit-mask-image: var(--icon-info);
mask-image: var(--icon-info);
background-color: $info-border;
background-color: var(--qiskit-color-info-border);
}
}

// Style deprecations like a warning.
div.deprecated {
border-color: $warning-background;
border-color: var(--qiskit-color-warning-background);
border-left: 0;
border-right-style: solid;
border-right-width: 1px;
Expand All @@ -156,7 +150,7 @@ div.deprecated {
}

div.deprecated::before {
background: $warning-border;
background: var(--qiskit-color-warning-border);
content: "";
position: absolute;
top: 0;
Expand All @@ -166,7 +160,7 @@ div.deprecated::before {
}

span.deprecated {
background-color: $warning-background;
background-color: var(--qiskit-color-warning-background);
font-size: var(--admonition-title-font-size);
line-height: 1.3;
margin: 0 -0.5rem 0.25rem -0.55rem;
Expand Down
73 changes: 59 additions & 14 deletions src/qiskit_sphinx_theme/assets/styles/_colors.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,59 @@
body {
// Define the Carbon color schemes from
// https://github.com/carbon-design-system/carbon/blob/v10/packages/colors/src/colors.js
//
// Projects can override `--color-brand-primary` to whatever they want.
--qiskit-color-purple: #6929C4; // purple70

// Furo normally distinguishes between these two variables, but
// we want them to be the same.
--color-brand-content: var(--color-brand-primary);

// For the Qiskit theme, use purple.
--color-brand-primary: var(--qiskit-color-purple);
}
/* This code is a Qiskit project.
*
* (C) Copyright IBM 2024.
*
* This code is licensed under the Apache License, Version 2.0. You may
* obtain a copy of this license in the LICENSE.txt file in the root directory
* of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
*
* Any modifications or derivative works of this code must retain this
* copyright notice, and modified files need to carry a notice indicating
* that they have been altered from the originals.
*/

@mixin colors {
// Define the Carbon color schemes from
// https://github.com/carbon-design-system/carbon/blob/v10/packages/colors/src/colors.js
//
// Projects can override `--color-brand-primary` to whatever they want.
--qiskit-color-purple: #6929c4; // purple70

// Furo normally distinguishes between these two variables, but
// we want them to be the same.
--color-brand-content: var(--color-brand-primary);

// For the Qiskit theme, use purple.
--color-brand-primary: var(--qiskit-color-purple);

// Use the same table header color previously used on qiskit.org.
--color-table-header-background: #dde1e6;

// Use gray for the top-level links to be more muted.
--color-sidebar-link-text--top-level: var(--color-sidebar-link-text);

// Turn off gradient for hover.
--color-sidebar-item-background--hover: var(--color-background-hover);

// Colors for admonitions
--qiskit-color-info-background: #edf5ff; //blue10
--qiskit-color-info-border: #0043ce; // blue70
--qiskit-color-warning-background: #fcf4d6; // yellow10
--qiskit-color-warning-border: #f1c21b; // yellow30
--qiskit-color-error-background: #fff1f1; // red10
--qiskit-color-error-border: #da1e28; // red60
}

@mixin colors-dark {
--qiskit-color-purple: #d4bbff; // purple30
--color-brand-content: var(--color-brand-primary);
--color-brand-primary: var(--qiskit-color-purple);
--color-table-header-background: var(--color-background-secondary);
--color-sidebar-link-text--top-level: var(--color-sidebar-link-text);
--color-sidebar-item-background--hover: var(--color-background-hover);
--qiskit-color-info-background: #002d9c; // blue80
--qiskit-color-info-border: #78a9ff; // blue40
--qiskit-color-warning-background: #684e00; // yellow70
--qiskit-color-warning-border: #f1c21b; // yellow30
--qiskit-color-error-background: #750e13; // red80
--qiskit-color-error-border: #fa4d56; // red50
}
11 changes: 4 additions & 7 deletions src/qiskit_sphinx_theme/assets/styles/_left-sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@
// Colors
// ------------------------------------------------------------------------------

body {
// Use gray for the top-level links to be more muted.
--color-sidebar-link-text--top-level: var(--color-sidebar-link-text);
// Turn off gradient for hover.
--color-sidebar-item-background--hover: #efeff4;
}

// Even though we override --color-sidebar-link--top-level to be a more muted look, we change
// the currently selected page to be the brand color to make it more obvious.
.sidebar-tree .current-page > .reference {
Expand Down Expand Up @@ -220,6 +213,10 @@ body {
font-size: var(--sidebar-item-font-size);
margin-bottom: var(--sidebar-item-spacing-vertical);
margin-top: 0;

.icon {
color: var(--color-sidebar-link-text--top-level)
}
}

.qiskit-previous-releases-header-container p {
Expand Down
5 changes: 0 additions & 5 deletions src/qiskit_sphinx_theme/assets/styles/_tables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
* that they have been altered from the originals.
*/

body {
// Use the same table header color previously used on qiskit.org.
--color-table-header-background: #dde1e6;
}

table.docutils {
// Add a border to the top of the table so that tables without headers have a border.
//
Expand Down
49 changes: 49 additions & 0 deletions src/qiskit_sphinx_theme/assets/styles/_theme.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* This code is a Qiskit project.
*
* (C) Copyright IBM 2024.
*
* This code is licensed under the Apache License, Version 2.0. You may
* obtain a copy of this license in the LICENSE.txt file in the root directory
* of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
*
* Any modifications or derivative works of this code must retain this
* copyright notice, and modified files need to carry a notice indicating
* that they have been altered from the originals.
*/

// Adapted from furo/assets/styles/base/_theme.sass

@import "colors";

body {
@include colors;
}

// Ignore dark-mode hints if print media.
@media not print {
// Enable dark-mode, if requested.
body[data-theme="dark"] {
@include colors-dark;

html & .only-light {
display: none !important;
}
.only-dark {
display: block !important;
}
}

// Enable dark mode, unless explicitly told to avoid.
@media (prefers-color-scheme: dark) {
body:not([data-theme="light"]) {
@include colors-dark;

html & .only-light {
display: none !important;
}
.only-dark {
display: block !important;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

@import "admonitions";
@import "api";
@import "colors";
@import "custom-directives";
@import "drop-shadows";
@import "icons";
Expand All @@ -22,15 +21,10 @@
@import "scaffold";
@import "sphinx-extensions";
@import "tables";
@import "theme";
@import "typography";

// Turn off scroll animation for anchor links: https://github.com/pradyunsg/furo/discussions/384
html {
scroll-behavior: auto;
}

// Disable dark mode for now, but probably re-enable in
// https://github.com/Qiskit/qiskit_sphinx_theme/issues/575.
.theme-toggle-container {
display: none;
}
4 changes: 1 addition & 3 deletions src/qiskit_sphinx_theme/theme/qiskit-sphinx-theme/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@
<body>
{% block body %}
<script>
{#- QISKIT CHANGE: start. Force light mode. -#}
document.body.dataset.theme = "light";
{#- QISKIT CHANGE: end. -#}
document.body.dataset.theme = localStorage.getItem("theme") || "auto";
</script>
{% endblock %}

Expand Down
Loading