Light and dark: a switch in the top bar
Three choices: as the device is (the default), light, or dark, kept in a "theme" cookie per browser. The dark colours move to dark.css, linked with a media attribute from the cookie, so the server renders the page in the chosen colours with no flash (the CSP allows no inline script). app.js sets the cookie and switches the media at once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
<link rel="icon" type="image/png" href="/static/favicon.png">
|
||||
<link rel="apple-touch-icon" href="/static/apple-touch-icon.png">
|
||||
<link rel="stylesheet" href="/static/app.css">
|
||||
<link rel="stylesheet" href="/static/dark.css" media="{{.DarkMedia}}" id="dark-css">
|
||||
<script src="/static/htmx.min.js" defer></script>
|
||||
<script src="/static/app.js" defer></script>
|
||||
</head>
|
||||
@@ -23,6 +24,7 @@
|
||||
{{template "content" .}}
|
||||
</main>
|
||||
<p class="version">Supermarket {{.Version}}</p>
|
||||
{{template "theme-switch" .}}
|
||||
</div>
|
||||
{{else}}
|
||||
<div class="shell">
|
||||
@@ -124,6 +126,7 @@
|
||||
{{with .Section}}{{if ne . $.Title}}<span>{{.}}</span><span class="sep" aria-hidden="true">/</span>{{end}}{{end}}
|
||||
<span class="here">{{.Title}}</span>
|
||||
</nav>
|
||||
{{template "theme-switch" .}}
|
||||
</header>
|
||||
<main>
|
||||
{{with .Viewer}}{{if .Viewing}}<div class="card warn viewing" role="status"><p><strong>Viewing this team as the platform's admin</strong>, read-only, until {{.Session.ViewUntil.Local.Format "15:04"}}: {{.Session.ViewReason}}</p>
|
||||
@@ -139,6 +142,14 @@
|
||||
</body>
|
||||
</html>
|
||||
|
||||
{{/* Light, dark, or as the device is: {{template "theme-switch" .}}. The
|
||||
choice is the "theme" cookie, for this browser; app.js sets it. */}}
|
||||
{{define "theme-switch"}}
|
||||
<div class="theme-switch" role="group" aria-label="Colours">
|
||||
{{range .Themes}}<button type="button" class="icon-button" data-theme-set="{{.}}" aria-pressed="{{if eq . $.ThemeName}}true{{else}}false{{end}}" title="{{if eq . "system"}}As your device is{{else if eq . "light"}}Light{{else}}Dark{{end}}">{{template "icon" .}}<span class="visually-hidden">{{if eq . "system"}}As your device is{{else if eq . "light"}}Light{{else}}Dark{{end}}</span></button>{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{/* Settings pages share this frame: a heading, and the tabs on the left
|
||||
(grouped, as in brain). Call with the page: {{template "settings-start" $}}
|
||||
… {{template "settings-end"}}. */}}
|
||||
@@ -227,6 +238,9 @@
|
||||
{{- else if eq . "backups"}}<path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M12 7v5l4 2"/>
|
||||
{{- else if eq . "chevron"}}<path d="m6 9 6 6 6-6"/>
|
||||
{{- else if eq . "menu"}}<path d="M4 12h16"/><path d="M4 6h16"/><path d="M4 18h16"/>
|
||||
{{- else if eq . "system"}}<rect width="20" height="14" x="2" y="3" rx="2"/><path d="M8 21h8"/><path d="M12 17v4"/>
|
||||
{{- else if eq . "light"}}<circle cx="12" cy="12" r="4"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="m4.93 4.93 1.41 1.41"/><path d="m17.66 17.66 1.41 1.41"/><path d="M2 12h2"/><path d="M20 12h2"/><path d="m6.34 17.66-1.41 1.41"/><path d="m19.07 4.93-1.41 1.41"/>
|
||||
{{- else if eq . "dark"}}<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/>
|
||||
{{- end}}</svg>{{end}}
|
||||
|
||||
{{define "seo-sites"}}
|
||||
|
||||
Reference in New Issue
Block a user