Add dark mode; align table headers with numeric columns

Dark mode:
- Theme toggle in the header (System → Light → Dark); "System" follows
  the OS setting and its changes. The choice is kept per browser and
  applied before first paint, so there's no light flash.
- Implemented by remapping the palette under :root[data-theme=dark]:
  grays flip, color tints become translucent, dark colored text becomes
  its light counterpart. Page, surface, header and accent colors are
  semantic tokens. Native controls follow via color-scheme.
- Chart text and grid colors follow the theme.
- Public share pages get the toggle too.
- Contrast checked against WCAG 4.5:1 (primary button text and error
  text adjusted for dark).

Tables:
- Shared table style no longer forces header text left, so right-aligned
  numeric headers line up with their columns everywhere.
- Flight log: units in headers, muted dashes for empty cells, GPS marker
  beside the route instead of its own column.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-05 19:53:11 -05:00
1 parent 5bf682502b
commit 86aadfcf6c
13 files changed
+216 -25

No files matched your search

+16
View File
@@ -3,3 +3,19 @@ import "@hotwired/turbo-rails"
import "controllers"
import "chartkick"
import "Chart.bundle"
// Chart text and grid colors follow the light/dark theme.
function styleCharts() {
if (!window.Chart) return
const dark = document.documentElement.dataset.theme === "dark"
window.Chart.defaults.color = dark ? "#a3b1c6" : "#64748b"
window.Chart.defaults.borderColor = dark ? "rgba(148, 163, 184, 0.18)" : "rgba(100, 116, 139, 0.15)"
}
function restyleCharts() {
styleCharts()
if (window.Chartkick) window.Chartkick.eachChart((chart) => chart.redraw())
}
styleCharts()
// Charts can be created before this module runs, so restyle after each page load too.
document.addEventListener("turbo:load", restyleCharts)
window.addEventListener("theme:change", restyleCharts)
@@ -0,0 +1,50 @@
import { Controller } from "@hotwired/stimulus"
const CHOICES = ["system", "light", "dark"]
const LABELS = { system: "System", light: "Light", dark: "Dark" }
// Light / dark / follow-the-OS theme toggle. The choice is kept in
// localStorage; the layout's inline script applies it before first paint.
export default class extends Controller {
static targets = ["button"]
connect() {
this.media = window.matchMedia("(prefers-color-scheme: dark)")
this.onSystemChange = () => { if (this.choice === "system") this.apply() }
this.media.addEventListener("change", this.onSystemChange)
this.apply()
}
disconnect() {
this.media.removeEventListener("change", this.onSystemChange)
}
cycle() {
this.choice = CHOICES[(CHOICES.indexOf(this.choice) + 1) % CHOICES.length]
this.apply()
}
get choice() {
try { return localStorage.getItem("theme") || "system" } catch { return "system" }
}
set choice(value) {
try { localStorage.setItem("theme", value) } catch {}
}
apply() {
const choice = this.choice
const dark = choice === "dark" || (choice === "system" && this.media.matches)
const theme = dark ? "dark" : "light"
const changed = document.documentElement.dataset.theme !== theme
document.documentElement.dataset.theme = theme
this.element.querySelectorAll("[data-theme-icon]").forEach((icon) => {
icon.classList.toggle("hidden", icon.dataset.themeIcon !== choice)
})
const label = `Theme: ${LABELS[choice]}${choice === "system" ? ` (${theme})` : ""}`
this.element.title = label
this.element.setAttribute("aria-label", label)
if (changed) window.dispatchEvent(new CustomEvent("theme:change", { detail: { theme } }))
}
}