Skip to content

Commit 377d29e

Browse files
committed
feat: add default_mode theme option
1 parent 441d58c commit 377d29e

File tree

5 files changed

+91
-2
lines changed

5 files changed

+91
-2
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# 🌗 Light and dark mode
2+
3+
Breeze supports light and dark themes with automatic system preference detection.
4+
5+
## Default mode
6+
7+
Set the default theme mode via `html_theme_options` in `conf.py`:
8+
9+
```python
10+
html_theme_options = {
11+
"default_mode": "auto", # "auto", "light", or "dark"
12+
}
13+
```
14+
15+
| Value | Behavior |
16+
|-------|----------|
17+
| `auto` | Follows system preference (default) |
18+
| `light` | Always starts in light mode |
19+
| `dark` | Always starts in dark mode |
20+
21+
Users can override this using the theme switcher, which saves their preference to localStorage.
22+
23+
## Theme-specific content
24+
25+
Use CSS classes to show or hide content based on the active theme.
26+
27+
### Only in dark mode
28+
29+
::::{tab-set}
30+
:::{tab-item} MyST
31+
````
32+
```{image} logo-dark.png
33+
:class: only-dark
34+
```
35+
````
36+
:::
37+
:::{tab-item} RST
38+
```rst
39+
.. image:: logo-dark.png
40+
:class: only-dark
41+
```
42+
:::
43+
::::
44+
45+
### Only in light mode
46+
47+
::::{tab-set}
48+
:::{tab-item} MyST
49+
````
50+
```{image} logo-light.png
51+
:class: only-light
52+
```
53+
````
54+
:::
55+
:::{tab-item} RST
56+
```rst
57+
.. image:: logo-light.png
58+
:class: only-light
59+
```
60+
:::
61+
::::
62+
63+
### Combining both
64+
65+
Display different images for each theme:
66+
67+
::::{tab-set}
68+
:::{tab-item} MyST
69+
````
70+
```{image} logo-light.png
71+
:class: only-light
72+
```
73+
```{image} logo-dark.png
74+
:class: only-dark
75+
```
76+
````
77+
:::
78+
:::{tab-item} RST
79+
```rst
80+
.. image:: logo-light.png
81+
:class: only-light
82+
83+
.. image:: logo-dark.png
84+
:class: only-dark
85+
```
86+
:::
87+
::::

docs/user_guide/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ quickstart
1919
customisation/announcement
2020
customisation/branding
2121
customisation/styling
22+
customisation/light-dark
2223
customisation/layout
2324
```

src/sphinx_breeze_theme/theme/breeze/layout.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
{%- block scripts -%}
1818
{{- script() }}
1919
<script data-cfasync="false">
20-
const mode = localStorage.getItem("breeze-mode") || "auto";
20+
const mode = localStorage.getItem("breeze-mode") || "{{ theme_default_mode }}";
2121
document.documentElement.dataset.mode = mode;
2222
if (mode === "auto") {
2323
const prefers = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"

src/sphinx_breeze_theme/theme/breeze/search.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<script defer src="{{ pathto('_static/language_data.js', 1) }}"></script>
1010
<script defer src="{{ pathto('searchindex.js', 1) }}"></script>
1111
<script data-cfasync="false">
12-
const mode = localStorage.getItem("breeze-mode") || "auto";
12+
const mode = localStorage.getItem("breeze-mode") || "{{ theme_default_mode }}";
1313
document.documentElement.dataset.mode = mode;
1414
if (mode === "auto") {
1515
const prefers = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"

src/sphinx_breeze_theme/theme/breeze/theme.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ announcement =
77
external_links =
88
lang_switcher =
99
version_switcher =
10+
default_mode = auto
1011
header_tabs = True
1112
emojis_title = False
1213
emojis_header_nav = False

0 commit comments

Comments
 (0)