Exact asger toggle (theme key + prefers-color-scheme), responsive container + full site-chrome components
- weirsoe-theme.js: match asger.weirsoe.dk exactly — localStorage['theme'], prefers-color-scheme default, light<->dark click delegation. - Container tokens + .wt-container(/--wide/--narrow/--bleed); Bulma adapter constrains content to a centred column past tablet (full-bleed on phones). - Site chrome extracted from agw/pw so it can drop its hardcoded CSS: .wt-header /.wt-nav/.wt-brand/.wt-nav-link/.wt-main/.wt-footer, postcard .wt-card(+date/ title/desc, --raised) and .wt-chip. README components table + theme-color note.
This commit is contained in:
@@ -60,6 +60,31 @@ card-styled. `wish.weircon.dk` (Christmas-Community fork) consumes it this way.
|
|||||||
|
|
||||||
Override any of them in your own `:root` to re-skin without forking.
|
Override any of them in your own `:root` to re-skin without forking.
|
||||||
|
|
||||||
|
## Components
|
||||||
|
|
||||||
|
Semantic classes so a site can drop hand-written CSS entirely:
|
||||||
|
|
||||||
|
| Class | What |
|
||||||
|
|---|---|
|
||||||
|
| `.wt-header` / `.wt-nav` / `.wt-brand` `.wt-brand-dot` | sticky blurred header + centred nav bar + wordmark |
|
||||||
|
| `.wt-nav-links` / `.wt-nav-link` (`.is-active` / `[aria-current=page]`) | nav link row |
|
||||||
|
| `.wt-main` | centred content column (= `.wt-container` + vertical padding) |
|
||||||
|
| `.wt-footer` / `.wt-footer-inner` | footer with border + responsive row |
|
||||||
|
| `.wt-card` (`--hover` `--raised` `--link`) + `.wt-card-date/-title/-desc` | post/list card |
|
||||||
|
| `.wt-chip` | pill tag-link |
|
||||||
|
| `.wt-btn` (`--primary`) / `.wt-input` / `.wt-tag` / `.wt-muted` | controls |
|
||||||
|
| `.prose` | long-form markdown |
|
||||||
|
| `.theme-toggle` + `.sun-and-moon` | the sun⇄moon toggle (wire with `weirsoe-theme.js`) |
|
||||||
|
|
||||||
|
These mirror, 1:1, the chrome of `agw/pw` (asger.weirsøe.dk) — the goal is for
|
||||||
|
that site to delete `src/styles/global.css` + its inline utility soup and
|
||||||
|
`@import` this framework instead. Also set the browser UI colour in `<head>`:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<meta name="theme-color" content="#0b0f17" media="(prefers-color-scheme: dark)">
|
||||||
|
<meta name="theme-color" content="#f6f8fb" media="(prefers-color-scheme: light)">
|
||||||
|
```
|
||||||
|
|
||||||
## Theme switching
|
## Theme switching
|
||||||
|
|
||||||
Set `data-theme` on `<html>`: `dark` (default), `light`, or `terminal`.
|
Set `data-theme` on `<html>`: `dark` (default), `light`, or `terminal`.
|
||||||
|
|||||||
Vendored
+8
@@ -101,3 +101,11 @@ hr { background-color: var(--color-border); }
|
|||||||
/* Misc */
|
/* Misc */
|
||||||
details summary { color: var(--color-accent); }
|
details summary { color: var(--color-accent); }
|
||||||
.section { padding-top: 2rem; }
|
.section { padding-top: 2rem; }
|
||||||
|
|
||||||
|
/* Responsive content width: full-bleed on phones, a centred readable column on
|
||||||
|
large screens (so a wishlist doesn't stretch edge-to-edge on a desktop). The
|
||||||
|
app marks a wrapper with .container.fullwidth; constrain it past tablet. */
|
||||||
|
@media (min-width: 769px) {
|
||||||
|
.container.fullwidth { max-width: 52rem; margin-left: auto; margin-right: auto; }
|
||||||
|
.container.fullwidth.is-wide { max-width: 72rem; }
|
||||||
|
}
|
||||||
|
|||||||
+5
-5
@@ -4,7 +4,7 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>weirsoe-theme demo</title>
|
<title>weirsoe-theme demo</title>
|
||||||
<script>try{document.documentElement.dataset.theme=localStorage.getItem('wt-theme')||'dark'}catch(e){document.documentElement.dataset.theme='dark'}</script>
|
<script>(()=>{try{var t=localStorage.getItem('theme')||(matchMedia('(prefers-color-scheme: light)').matches?'light':'dark');document.documentElement.dataset.theme=t}catch(e){document.documentElement.dataset.theme='dark'}})()</script>
|
||||||
<link rel="stylesheet" href="../weirsoe-theme.css">
|
<link rel="stylesheet" href="../weirsoe-theme.css">
|
||||||
<script defer src="../weirsoe-theme.js"></script>
|
<script defer src="../weirsoe-theme.js"></script>
|
||||||
<style>
|
<style>
|
||||||
@@ -20,11 +20,11 @@
|
|||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
<header>
|
<header>
|
||||||
<h1>weirsoe-theme</h1>
|
<h1>weirsoe-theme</h1>
|
||||||
<button class="theme-toggle" data-theme-toggle aria-label="Skift tema">
|
<button type="button" class="theme-toggle" data-theme-toggle aria-label="Skift tema" title="Skift mellem lyst og mørkt tema">
|
||||||
<svg class="sun-and-moon" aria-hidden="true" width="22" height="22" viewBox="0 0 24 24">
|
<svg class="sun-and-moon" aria-hidden="true" width="22" height="22" viewBox="0 0 24 24">
|
||||||
<circle class="sun" cx="12" cy="12" r="6" mask="url(#wt-moon)" fill="currentColor"/>
|
<mask class="moon" id="moon-mask"><rect x="0" y="0" width="100%" height="100%" fill="white"/><circle cx="24" cy="10" r="6" fill="black"/></mask>
|
||||||
<g class="sun-beams" stroke="currentColor"><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.2" y1="4.2" x2="5.6" y2="5.6"/><line x1="18.4" y1="18.4" x2="19.8" y2="19.8"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.2" y1="19.8" x2="5.6" y2="18.4"/><line x1="18.4" y1="5.6" x2="19.8" y2="4.2"/></g>
|
<circle class="sun" cx="12" cy="12" r="6" mask="url(#moon-mask)" fill="currentColor"/>
|
||||||
<mask class="moon" id="wt-moon"><rect x="0" y="0" width="100%" height="100%" fill="white"/><circle cx="24" cy="10" r="6" fill="black"/></mask>
|
<g class="sun-beams" stroke="currentColor"><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"/></g>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
</header>
|
</header>
|
||||||
|
|||||||
+74
-7
@@ -29,6 +29,12 @@
|
|||||||
--wt-radius-sm: 0.55rem;
|
--wt-radius-sm: 0.55rem;
|
||||||
--wt-shadow: 0 10px 30px #00000059;
|
--wt-shadow: 0 10px 30px #00000059;
|
||||||
--wt-shadow-hover: 0 18px 44px #0000006e;
|
--wt-shadow-hover: 0 18px 44px #0000006e;
|
||||||
|
/* responsive content widths — full-bleed on small screens, a readable,
|
||||||
|
centred column on large ones (the asger.weirsøe.dk behaviour). */
|
||||||
|
--wt-container: 48rem;
|
||||||
|
--wt-container-wide: 72rem;
|
||||||
|
--wt-container-narrow: 34rem;
|
||||||
|
--wt-gutter: 1.25rem;
|
||||||
--wt-font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
|
--wt-font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
|
||||||
Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
|
Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
|
||||||
--wt-font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
|
--wt-font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
|
||||||
@@ -86,19 +92,80 @@ body::before {
|
|||||||
radial-gradient(50rem 30rem at 10% 0%, color-mix(in srgb, var(--color-accent-2) 10%, transparent), transparent 70%);
|
radial-gradient(50rem 30rem at 10% 0%, color-mix(in srgb, var(--color-accent-2) 10%, transparent), transparent 70%);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------- responsive container ---------- */
|
||||||
|
/* Full width (with gutters) on small screens; a centred max-width column on
|
||||||
|
larger ones. Use --wt-container / --modifier to control the breakpoint width. */
|
||||||
|
.wt-container {
|
||||||
|
width: 100%;
|
||||||
|
max-width: var(--wt-container);
|
||||||
|
margin-inline: auto;
|
||||||
|
padding-inline: var(--wt-gutter);
|
||||||
|
}
|
||||||
|
.wt-container--wide { max-width: var(--wt-container-wide); }
|
||||||
|
.wt-container--narrow { max-width: var(--wt-container-narrow); }
|
||||||
|
.wt-container--bleed { max-width: none; }
|
||||||
|
|
||||||
|
/* ---------- site chrome (header / nav / footer) ---------- */
|
||||||
|
.wt-header {
|
||||||
|
position: sticky; top: 0; z-index: 50;
|
||||||
|
border-bottom: 1px solid color-mix(in srgb, var(--color-border) 70%, transparent);
|
||||||
|
-webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
|
||||||
|
background: color-mix(in srgb, var(--color-bg) 70%, transparent);
|
||||||
|
}
|
||||||
|
.wt-nav {
|
||||||
|
margin-inline: auto; max-width: var(--wt-container);
|
||||||
|
display: flex; align-items: center; justify-content: space-between;
|
||||||
|
padding: 0.875rem 1.25rem; gap: 1rem;
|
||||||
|
}
|
||||||
|
.wt-brand { font-weight: 700; letter-spacing: -0.02em; font-size: 1.125rem; color: var(--color-text); text-decoration: none; }
|
||||||
|
.wt-brand-dot { color: var(--color-accent); }
|
||||||
|
.wt-nav-links { display: flex; align-items: center; gap: 0.25rem; font-size: 0.875rem; list-style: none; margin: 0; padding: 0; }
|
||||||
|
.wt-nav-link {
|
||||||
|
display: inline-block; border-radius: 0.5rem; padding: 0.375rem 0.75rem;
|
||||||
|
color: var(--color-muted); text-decoration: none;
|
||||||
|
transition: color 0.2s, background-color 0.2s;
|
||||||
|
}
|
||||||
|
.wt-nav-link:hover { color: var(--color-text); }
|
||||||
|
.wt-nav-link.is-active, .wt-nav-link[aria-current="page"] { color: var(--color-text); background: var(--color-surface-2); }
|
||||||
|
|
||||||
|
.wt-main { margin-inline: auto; width: 100%; max-width: var(--wt-container); padding: 3rem 1.25rem; }
|
||||||
|
|
||||||
|
.wt-footer { margin-top: 6rem; border-top: 1px solid color-mix(in srgb, var(--color-border) 70%, transparent); }
|
||||||
|
.wt-footer-inner {
|
||||||
|
margin-inline: auto; max-width: var(--wt-container);
|
||||||
|
display: flex; flex-direction: column; align-items: center; gap: 0.75rem;
|
||||||
|
padding: 2.5rem 1.25rem; font-size: 0.875rem; color: var(--color-muted);
|
||||||
|
}
|
||||||
|
.wt-footer a { color: inherit; text-decoration: none; transition: color 0.2s; }
|
||||||
|
.wt-footer a:hover { color: var(--color-accent); }
|
||||||
|
@media (min-width: 640px) { .wt-footer-inner { flex-direction: row; justify-content: space-between; } }
|
||||||
|
|
||||||
/* ---------- components ---------- */
|
/* ---------- components ---------- */
|
||||||
|
/* Faithful to the asger.weirsøe.dk post card: translucent surface, hairline
|
||||||
|
border, accent-on-hover, no heavy shadow. Add .wt-card--raised for a shadow. */
|
||||||
.wt-card {
|
.wt-card {
|
||||||
background: var(--color-surface);
|
background: color-mix(in srgb, var(--color-surface) 60%, transparent);
|
||||||
border: 1px solid var(--color-border);
|
border: 1px solid var(--color-border);
|
||||||
border-radius: var(--wt-radius);
|
border-radius: 1rem;
|
||||||
box-shadow: var(--wt-shadow);
|
|
||||||
padding: 1.25rem;
|
padding: 1.25rem;
|
||||||
|
transition: border-color 0.2s, transform 0.16s, box-shadow 0.16s;
|
||||||
}
|
}
|
||||||
.wt-card--hover:hover {
|
.wt-card--hover:hover { border-color: color-mix(in srgb, var(--color-accent) 50%, transparent); }
|
||||||
transform: translateY(-2px);
|
.wt-card--raised { background: var(--color-surface); box-shadow: var(--wt-shadow); }
|
||||||
border-color: color-mix(in srgb, var(--color-accent) 45%, var(--color-border));
|
.wt-card--raised.wt-card--hover:hover { transform: translateY(-2px); box-shadow: var(--wt-shadow-hover); }
|
||||||
box-shadow: var(--wt-shadow-hover);
|
.wt-card-date { font-size: 0.75rem; color: var(--color-muted); }
|
||||||
|
.wt-card-title { margin-top: 0.25rem; font-size: 1.125rem; font-weight: 600; letter-spacing: -0.01em; }
|
||||||
|
.wt-card--link:hover .wt-card-title, a.wt-card--hover:hover .wt-card-title { color: var(--color-accent); }
|
||||||
|
.wt-card-desc { margin-top: 0.5rem; font-size: 0.875rem; color: var(--color-muted); }
|
||||||
|
|
||||||
|
/* Pill chip / tag-link (e.g. blog tags) */
|
||||||
|
.wt-chip {
|
||||||
|
display: inline-flex; align-items: center; border-radius: 999px;
|
||||||
|
border: 1px solid var(--color-border); padding: 0.1rem 0.6rem;
|
||||||
|
font-size: 0.75rem; color: var(--color-muted); text-decoration: none;
|
||||||
|
transition: color 0.2s, border-color 0.2s;
|
||||||
}
|
}
|
||||||
|
.wt-chip:hover { color: var(--color-accent); border-color: var(--color-accent); }
|
||||||
.wt-btn {
|
.wt-btn {
|
||||||
display: inline-flex; align-items: center; gap: 0.5rem;
|
display: inline-flex; align-items: center; gap: 0.5rem;
|
||||||
border-radius: var(--wt-radius-sm);
|
border-radius: var(--wt-radius-sm);
|
||||||
|
|||||||
+32
-36
@@ -1,54 +1,50 @@
|
|||||||
/* weirsoe-theme.js — persisted theme toggle for weirsoe-theme.css.
|
/* weirsoe-theme.js — persisted light/dark toggle (matches asger.weirsøe.dk).
|
||||||
*
|
*
|
||||||
* 1) Prevent a flash of the wrong theme: put this MINIMAL snippet inline in
|
* 1) No-flash: put this MINIMAL snippet inline in <head>, BEFORE any stylesheet
|
||||||
* <head>, BEFORE any stylesheet (it runs pre-paint):
|
* (runs pre-paint; respects the OS preference on first visit):
|
||||||
*
|
*
|
||||||
* <script>try{var t=localStorage.getItem('wt-theme');
|
* <script>(()=>{try{var t=localStorage.getItem('theme')||(matchMedia('(prefers-color-scheme: light)').matches?'light':'dark');document.documentElement.dataset.theme=t}catch(e){document.documentElement.dataset.theme='dark'}})()</script>
|
||||||
* document.documentElement.dataset.theme=t||'dark';}catch(e){
|
|
||||||
* document.documentElement.dataset.theme='dark';}</script>
|
|
||||||
*
|
*
|
||||||
* 2) Load this file (defer is fine) and drop a toggle button somewhere:
|
* 2) Load this file and drop the toggle button anywhere (exact markup from
|
||||||
|
* asger.weirsøe.dk):
|
||||||
*
|
*
|
||||||
* <button class="theme-toggle" data-theme-toggle aria-label="Skift tema">
|
* <button type="button" data-theme-toggle class="theme-toggle" aria-label="Skift tema" title="Skift mellem lyst og mørkt tema">
|
||||||
* <svg class="sun-and-moon" aria-hidden="true" width="22" height="22" viewBox="0 0 24 24">
|
* <svg class="sun-and-moon" aria-hidden="true" width="22" height="22" viewBox="0 0 24 24">
|
||||||
* <circle class="sun" cx="12" cy="12" r="6" mask="url(#wt-moon)" fill="currentColor"/>
|
* <mask class="moon" id="moon-mask"><rect x="0" y="0" width="100%" height="100%" fill="white"/><circle cx="24" cy="10" r="6" fill="black"/></mask>
|
||||||
* <g class="sun-beams" stroke="currentColor"><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.2" y1="4.2" x2="5.6" y2="5.6"/><line x1="18.4" y1="18.4" x2="19.8" y2="19.8"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.2" y1="19.8" x2="5.6" y2="18.4"/><line x1="18.4" y1="5.6" x2="19.8" y2="4.2"/></g>
|
* <circle class="sun" cx="12" cy="12" r="6" mask="url(#moon-mask)" fill="currentColor"/>
|
||||||
* <mask class="moon" id="wt-moon"><rect x="0" y="0" width="100%" height="100%" fill="white"/><circle cx="24" cy="10" r="6" fill="black"/></mask>
|
* <g class="sun-beams" stroke="currentColor"><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"/></g>
|
||||||
* </svg>
|
* </svg>
|
||||||
* </button>
|
* </button>
|
||||||
*
|
*
|
||||||
* The toggle cycles dark -> light (add "terminal" yourself if you want a 3-way).
|
* Cycles light ⇄ dark and persists to localStorage['theme'].
|
||||||
*/
|
*/
|
||||||
(function () {
|
(function () {
|
||||||
var KEY = 'wt-theme';
|
|
||||||
var root = document.documentElement;
|
var root = document.documentElement;
|
||||||
|
|
||||||
function set(theme) {
|
function preferred() {
|
||||||
root.dataset.theme = theme;
|
return window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';
|
||||||
try { localStorage.setItem(KEY, theme); } catch (e) { /* ignore */ }
|
}
|
||||||
|
function apply() {
|
||||||
|
var t;
|
||||||
|
try { t = localStorage.getItem('theme'); } catch (e) { /* ignore */ }
|
||||||
|
root.dataset.theme = t || preferred();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure a theme is set even if the inline no-flash snippet was omitted.
|
apply();
|
||||||
if (!root.dataset.theme) {
|
// Re-apply after client-side navigations (Astro etc.) — harmless if unused.
|
||||||
var saved;
|
document.addEventListener('astro:after-swap', apply);
|
||||||
try { saved = localStorage.getItem(KEY); } catch (e) { saved = null; }
|
|
||||||
root.dataset.theme = saved || 'dark';
|
|
||||||
}
|
|
||||||
|
|
||||||
function wire() {
|
document.addEventListener('click', function (e) {
|
||||||
document.querySelectorAll('[data-theme-toggle]').forEach(function (btn) {
|
var btn = e.target.closest && e.target.closest('[data-theme-toggle]');
|
||||||
btn.addEventListener('click', function () {
|
if (!btn) return;
|
||||||
set(root.dataset.theme === 'dark' ? 'light' : 'dark');
|
var next = root.dataset.theme === 'light' ? 'dark' : 'light';
|
||||||
|
root.dataset.theme = next;
|
||||||
|
try { localStorage.setItem('theme', next); } catch (err) { /* ignore */ }
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (document.readyState === 'loading') {
|
// Tiny API for custom controls (e.g. a 3-way picker incl. 'terminal').
|
||||||
document.addEventListener('DOMContentLoaded', wire);
|
window.weirsoeTheme = {
|
||||||
} else {
|
set: function (t) { root.dataset.theme = t; try { localStorage.setItem('theme', t); } catch (e) {} },
|
||||||
wire();
|
get: function () { return root.dataset.theme; },
|
||||||
}
|
};
|
||||||
|
|
||||||
// Expose a tiny API for custom controls (e.g. a 3-way picker).
|
|
||||||
window.weirsoeTheme = { set: set, get: function () { return root.dataset.theme; } };
|
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user