Skip to content

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.

Add dark mode toggle to admin UI user menu and theme.

Kailash Nadhb5046a3d6fd7
diff --git a/i18n/en.json b/i18n/en.json
index 73e0f29b..ff8ecc45 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -251,6 +251,7 @@
"globals.terms.subscriber": "Subscriber | Subscribers",
"globals.terms.subscribers": "Subscribers",
"globals.terms.subscriptions": "Subscription | Subscriptions",
+ "globals.terms.system": "System",
"globals.terms.tag": "Tag | Tags",
"globals.terms.tags": "Tags",
"globals.terms.template": "Template | Templates",
@@ -687,6 +688,8 @@
"users.roles": "Roles",
"users.status.disabled": "Disabled",
"users.status.enabled": "Enabled",
+ "users.themeDark": "Dark",
+ "users.themeLight": "Light",
"users.type": "Type",
"users.type.api": "API",
"users.type.super": "Super Admin",
diff --git a/static/admin/assets/css/style.css b/static/admin/assets/css/style.css
index aced9b15..2bff8135 100644
--- a/static/admin/assets/css/style.css
+++ b/static/admin/assets/css/style.css
@@ -26,8 +26,8 @@
/* Theme */
* {
--body: light-dark(#f9f9f9, #171717);
- --primary: #0055d4;
- --ring: #0055d4;
+ --primary: light-dark(#0055d4, #4f8ce6);
+ --ring: light-dark(#0055d4, #4f8ce6);
--muted-foreground: light-dark(#7a7a7a, #a1a1aa);
--container-max: 1150px;
--border: light-dark(#e5e7eb, #52525b);
@@ -36,6 +36,7 @@
--text-regular: var(--text-7);
}
+
/* Global */
html,
body {
@@ -168,8 +169,8 @@ a:has(> .badge:only-child) {
&.api,
&.double,
&.unconfirmed {
- background: #fff1e0;
- color: #ed7b00;
+ background: light-dark(#fff1e0, #2e261a);
+ color: light-dark(#ed7b00, #d3a065);
}
&.public,
@@ -178,30 +179,30 @@ a:has(> .badge:only-child) {
&.campaign,
&.user,
&.primary {
- background: #e6f7ff;
- color: #3b8cff;
+ background: light-dark(#e6f7ff, #1e2733);
+ color: light-dark(#3b8cff, #8aa9cc);
}
/* Subscription/campaign statuses */
sup.status-confirmed {
- color: #36995b;
+ color: light-dark(#36995b, #7eab8b);
}
&.status-confirmed,
&.status-finished {
- background: #dcfce7;
- color: #36995b;
+ background: light-dark(#dcfce7, #1f2a22);
+ color: light-dark(#36995b, #7eab8b);
}
sup.status-unsubscribed {
- color: #ff5722;
+ color: light-dark(#ff5722, #cf9088);
}
&.status-unsubscribed,
&.status-cancelled {
- background: #fff1f0;
- color: #ff5722;
+ background: light-dark(#fff1f0, #2e2320);
+ color: light-dark(#ff5722, #cf9088);
}
&.status-blocklisted {
- background: #fff1f0;
+ background: light-dark(#fff1f0, #2e2320);
color: var(--danger);
}
@@ -213,17 +214,17 @@ a:has(> .badge:only-child) {
&.status-draft,
&.optin,
&.single {
- background: #eee;
- color: #7a7a7a;
+ background: light-dark(#eee, #26262a);
+ color: light-dark(#7a7a7a, #9a9aa3);
}
&.status-unsubscribed sup {
- color: #fa8c16;
+ color: light-dark(#fa8c16, #d3a065);
}
&.confirmed sup,
&.status-confirmed sup {
- color: #52c41a;
+ color: light-dark(#52c41a, #8bb079);
}
}
@@ -451,6 +452,20 @@ nav[data-topnav] {
}
}
+ .theme-switch {
+ display: flex;
+ gap: var(--space-1);
+ padding: var(--space-1) var(--space-2);
+
+ button {
+ &.is-active {
+ background: var(--accent);
+ color: var(--foreground);
+ }
+ }
+ }
+
+
@media (max-width: 768px) {
> .row {
--grid-cols: 12;
diff --git a/static/admin/assets/js/main.js b/static/admin/assets/js/main.js
index f624b55a..788529d1 100644
--- a/static/admin/assets/js/main.js
+++ b/static/admin/assets/js/main.js
@@ -26,6 +26,20 @@ function setupAlpine() {
copyToClipboard: u.copyToClipboard,
listAutocomplete,
+ theme: localStorage.getItem('theme') || 'auto',
+
+ setTheme(mode) {
+ this.theme = mode;
+
+ if (mode === 'auto') {
+ localStorage.removeItem('theme');
+ document.body.style.colorScheme = '';
+ } else {
+ localStorage.setItem('theme', mode);
+ document.body.style.colorScheme = mode;
+ }
+ },
+
// Trigger an app restart (from the "needs restart" notice), then poll the
// health endpoint until the app is back up and reload the page.
async restartApp() {
diff --git a/static/admin/assets/js/views/dashboard.js b/static/admin/assets/js/views/dashboard.js
index 926a74e0..b0ac97ca 100644
--- a/static/admin/assets/js/views/dashboard.js
+++ b/static/admin/assets/js/views/dashboard.js
@@ -1,6 +1,5 @@
import Chart from 'chart.js/auto';
-const PRIMARY = getComputedStyle(document.documentElement).getPropertyValue('--primary').trim() || '#0055d4';
const FONT_FAMILY = "'Inter', sans-serif";
// Format an ISO date ('2024-06-01') to a short 'DD Mon' label.
@@ -20,6 +19,13 @@ function lineChart(id, rows) {
return;
}
+ // Get the primary colour.
+ const el = document.createElement('div');
+ el.style.color = 'var(--primary)';
+ document.documentElement.appendChild(el);
+ const color = getComputedStyle(el).color || '#0055d4';
+ el.remove();
+
const data = rows || [];
Chart.defaults.font.family = FONT_FAMILY;
@@ -30,8 +36,8 @@ function lineChart(id, rows) {
labels: data.map((d) => label(d.date)),
datasets: [{
data: data.map((d) => d.count),
- borderColor: PRIMARY,
- backgroundColor: `${PRIMARY}08`,
+ borderColor: color,
+ backgroundColor: `${color.replace('rgb(', 'rgba(').replace(')', ', 0.0314)')}`,
borderWidth: 2,
fill: true,
tension: 0.35,
diff --git a/static/admin/assets/static/icons.svg b/static/admin/assets/static/icons.svg
index ce431100..37dfba42 100644
--- a/static/admin/assets/static/icons.svg
+++ b/static/admin/assets/static/icons.svg
@@ -119,6 +119,14 @@
<line x1="5" y1="12" x2="19" y2="12" />
</symbol>
+ <symbol id="icon-monitor" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
+ <rect x="2" y="3" width="20" height="14" rx="2" ry="2" /><line x1="8" y1="21" x2="16" y2="21" /><line x1="12" y1="17" x2="12" y2="21" />
+ </symbol>
+
+ <symbol id="icon-moon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
+ <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" />
+ </symbol>
+
<symbol id="icon-more-vertical" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="1" /><circle cx="12" cy="5" r="1" /><circle cx="12" cy="19" r="1" />
</symbol>
@@ -159,6 +167,10 @@
<polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" />
</symbol>
+ <symbol id="icon-sun" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
+ <circle cx="12" cy="12" r="5" /><line x1="12" y1="1" x2="12" y2="3" /><line x1="12" y1="21" x2="12" y2="23" /><line x1="4.22" y1="4.22" x2="5.64" y2="5.64" /><line x1="18.36" y1="18.36" x2="19.78" y2="19.78" /><line x1="1" y1="12" x2="3" y2="12" /><line x1="21" y1="12" x2="23" y2="12" /><line x1="4.22" y1="19.78" x2="5.64" y2="18.36" /><line x1="18.36" y1="5.64" x2="19.78" y2="4.22" />
+ </symbol>
+
<symbol id="icon-tag" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M20.59 13.41l-7.17 7.17a2 2 0 0 1-2.83 0L2 12V2h10l8.59 8.59a2 2 0 0 1 0 2.82z" /><line x1="7" y1="7" x2="7.01" y2="7" />
</symbol>
diff --git a/static/admin/icons.txt b/static/admin/icons.txt
index c1f3ba25..97c1e6da 100644
--- a/static/admin/icons.txt
+++ b/static/admin/icons.txt
@@ -29,6 +29,8 @@ log-out
mail
menu
minus
+monitor
+moon
more-vertical
pause
pause-circle
@@ -39,6 +41,7 @@ search
send
settings
star
+sun
tag
tool
trash-2
diff --git a/static/admin/views/base.html b/static/admin/views/base.html
index 53161367..360e0304 100644
--- a/static/admin/views/base.html
+++ b/static/admin/views/base.html
@@ -26,6 +26,16 @@
{{ template "admin-head-assets" . }}
</head>
<body x-data="adminApp"{{ if .Data.Can "settings:get" }} data-error-events{{ end }}>
+ <script>
+ // Apply the theme early to avoid white flash.
+ (function () {
+ var t = localStorage.getItem('theme');
+ if (t) {
+ document.body.style.colorScheme = t;
+ }
+ })();
+ </script>
+
<div id="app" data-sidebar-layout>
<nav data-topnav>
<div class="row">
@@ -50,6 +60,12 @@
<button type="button" role="menuitem" class="ghost" onclick="fetch('{{ URI "/api/logout" }}', { method: 'POST' }).then(() => { document.location.href = '{{ URI "/admin/login" }}'; })">
{{ Icon "log-out" }} {{ $.L.T "users.logout" }}
</button>
+ <hr />
+ <div class="theme-switch" role="group" aria-label="Theme">
+ <button type="button" class="ghost small" title="{{ $.L.T "globals.terms.system" }}" @click="setTheme('auto')" :class="{ 'is-active': theme === 'auto' }" :aria-pressed="theme === 'auto'">{{ Icon "monitor" }}</button>
+ <button type="button" class="ghost small" title="{{ $.L.T "users.themeLight" }}" @click="setTheme('light')" :class="{ 'is-active': theme === 'light' }" :aria-pressed="theme === 'light'">{{ Icon "sun" }}</button>
+ <button type="button" class="ghost small" title="{{ $.L.T "users.themeDark" }}" @click="setTheme('dark')" :class="{ 'is-active': theme === 'dark' }" :aria-pressed="theme === 'dark'">{{ Icon "moon" }}</button>
+ </div>
</menu>
</ot-dropdown>
{{ end }}