Skip to content

Commit 29f795f

Browse files
Add theming support (#1760)
1 parent a6b65a7 commit 29f795f

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-9
lines changed

debug_toolbar/static/debug_toolbar/css/toolbar.css

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/* Variable definitions */
2+
:root {
3+
/* Font families are the same as in Django admin/css/base.css */
4+
--djdt-font-family-primary: -apple-system, BlinkMacSystemFont, "Segoe UI",
5+
system-ui, Roboto, "Helvetica Neue", Arial, sans-serif,
6+
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol",
7+
"Noto Color Emoji";
8+
--djdt-font-family-monospace: ui-monospace, Menlo, Monaco, "Cascadia Mono",
9+
"Segoe UI Mono", "Roboto Mono", "Oxygen Mono", "Ubuntu Monospace",
10+
"Source Code Pro", "Fira Mono", "Droid Sans Mono", "Courier New",
11+
monospace, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol",
12+
"Noto Color Emoji";
13+
}
14+
115
/* Debug Toolbar CSS Reset, adapted from Eric Meyer's CSS Reset */
216
#djDebug {
317
color: #000;
@@ -77,9 +91,7 @@
7791
color: #000;
7892
vertical-align: baseline;
7993
background-color: transparent;
80-
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui,
81-
Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji",
82-
"Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
94+
font-family: var(--djdt-font-family-primary);
8395
text-align: left;
8496
text-shadow: none;
8597
white-space: normal;
@@ -181,7 +193,7 @@
181193

182194
#djDebug #djDebugToolbar li.djdt-active:before {
183195
content: "▶";
184-
font-family: sans-serif;
196+
font-family: var(--djdt-font-family-primary);
185197
position: absolute;
186198
left: 0;
187199
top: 50%;
@@ -246,11 +258,7 @@
246258
#djDebug pre,
247259
#djDebug code {
248260
display: block;
249-
font-family: ui-monospace, Menlo, Monaco, "Cascadia Mono", "Segoe UI Mono",
250-
"Roboto Mono", "Oxygen Mono", "Ubuntu Monospace", "Source Code Pro",
251-
"Fira Mono", "Droid Sans Mono", "Courier New", monospace,
252-
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol",
253-
"Noto Color Emoji";
261+
font-family: var(--djdt-font-family-monospace);
254262
overflow: auto;
255263
}
256264

docs/changes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Pending
88
indentation of ``CASE`` statements and stopped simplifying ``.count()``
99
queries.
1010
* Added support for the new STORAGES setting in Django 4.2 for static files.
11+
* Added support for theme overrides.
1112
* Reworked the cache panel instrumentation code to no longer attempt to undo
1213
monkey patching of cache methods, as that turned out to be fragile in the
1314
presence of other code which also monkey patches those methods.

docs/configuration.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,26 @@ Here's what a slightly customized toolbar configuration might look like::
338338
# Panel options
339339
'SQL_WARNING_THRESHOLD': 100, # milliseconds
340340
}
341+
342+
Theming support
343+
---------------
344+
The debug toolbar uses CSS variables to define fonts. This allows changing
345+
fonts without having to override many individual CSS rules. For example, if
346+
you preferred Roboto instead of the default list of fonts you could add a
347+
**debug_toolbar/base.html** template override to your project:
348+
349+
.. code-block:: django
350+
351+
{% extends 'debug_toolbar/base.html' %}
352+
353+
{% block css %}{{ block.super }}
354+
<style>
355+
:root {
356+
--djdt-font-family-primary: 'Roboto', sans-serif;
357+
}
358+
</style>
359+
{% endblock %}
360+
361+
The list of CSS variables are defined at
362+
`debug_toolbar/static/debug_toolbar/css/toolbar.css
363+
<https://github.com/jazzband/django-debug-toolbar/blob/main/debug_toolbar/static/debug_toolbar/css/toolbar.css>`_

docs/spelling_wordlist.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ Pympler
4040
querysets
4141
refactoring
4242
resizing
43+
Roboto
4344
spellchecking
4445
spooler
4546
stacktrace
4647
stacktraces
4748
startup
4849
timeline
50+
theming
4951
tox
5052
Transifex
5153
unhashable

0 commit comments

Comments
 (0)