feat(panel): Faceplate component library + Overview showcase

Token-driven, accessible components: Faceplate/FaceplateHeader, Module, Toggle,
Led, SegMeter, QueryLog, Button, Clock, ThemeSwitch + reduced-motion hook. App
is a realistic Overview showcase (throughput VU meters, module grid, streaming
query log, apply->toast, theme switch). Built to match the north-star prototype:
instrument-panel language, orange only as accent, semantic good/warn/crit.

Verified (Playwright): dark+light, desktop+mobile (3->1 col), :focus-visible ring,
reduced-motion honored, no console errors. dist ~162KB (49KB gzip), no heavy deps.
This commit is contained in:
omar committed 2026-07-14 16:03:54 +03:00
1 parent 2309759d9b
commit 1cf03fec5f
22 files changed
+1266 -61

No files matched your search

+12
View File
@@ -4,7 +4,19 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="color-scheme" content="dark light" />
<link
rel="icon"
href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='5' fill='%23e5590d'/%3E%3C/svg%3E"
/>
<title>shater</title>
<script>
// Apply the saved theme before first paint to avoid a flash of the wrong panel.
try {
var t = localStorage.getItem('shater-theme')
if (t === 'dark' || t === 'light')
document.documentElement.setAttribute('data-theme', t)
} catch (e) {}
</script>
</head>
<body>
<div id="root"></div>
+24 -48
View File
@@ -1,52 +1,28 @@
.boot {
min-height: 100%;
display: grid;
place-items: center;
padding: 24px;
}
.boot-plate {
position: relative;
max-width: 420px;
width: 100%;
padding: 40px 32px;
text-align: center;
background: var(--raised);
border: 1px solid var(--edge);
border-radius: 10px;
box-shadow:
0 1px 0 var(--edge) inset,
0 12px 32px var(--shadow);
}
.boot-wordmark {
font-size: 28px;
font-weight: 700;
letter-spacing: var(--track-label-wide);
color: var(--ink);
}
.boot-sub {
margin-top: 6px;
/* Showcase-only styling. The Faceplate layout/components live in components/*.css;
* this file only owns the transient "Applied" toast. */
.toast {
position: fixed;
left: 50%;
bottom: 24px;
transform: translateX(-50%);
padding: 10px 18px;
border-radius: 6px;
background: var(--accent);
color: #fff;
font-family: var(--font-mono);
font-size: 11px;
font-size: 12px;
letter-spacing: 0.14em;
text-transform: uppercase;
letter-spacing: var(--track-label);
color: var(--dim);
box-shadow: 0 8px 24px -8px var(--shadow);
animation: toast-in 0.25s ease;
}
.boot-led {
width: 9px;
height: 9px;
margin: 20px auto 0;
border-radius: 50%;
background: var(--led-on);
box-shadow: 0 0 8px var(--led-on);
}
.boot-note {
margin: 20px 0 0;
font-size: 13px;
line-height: 1.5;
color: var(--faint);
@keyframes toast-in {
from {
opacity: 0;
transform: translate(-50%, 8px);
}
to {
opacity: 1;
transform: translate(-50%, 0);
}
}
+189 -13
View File
@@ -1,19 +1,195 @@
import './App.css'
import { useCallback, useEffect, useRef, useState } from 'react'
import {
Button,
Faceplate,
FaceplateHeader,
Module,
QueryLog,
SegMeter,
} from './components'
import type { QueryEntry, QueryTag } from './components'
// Realistic streaming sample — domains a household router actually sees.
const FEED: ReadonlyArray<[string, string, QueryTag]> = [
['youtube.com', 'tv-livingroom', 'proxy'],
['googleads.g.doubleclick.net', 'iphone-lena', 'block'],
['github.com', 'macbook-max', 'proxy'],
['telegram.org', 'iphone-lena', 'proxy'],
['app-measurement.com', 'android-kolya', 'block'],
['cloudflare.com', 'macbook-max', 'pass'],
['pool.ntp.org', 'router', 'pass'],
['ads.tiktok.com', 'iphone-nina', 'block'],
['reality.example.net', 'tv-livingroom', 'proxy'],
['analytics.google.com', 'macbook-max', 'block'],
['discord.gg', 'desktop-pc', 'proxy'],
['tracker.metrics.io', 'android-kolya', 'block'],
['wikipedia.org', 'ipad-kids', 'pass'],
]
function stamp(): string {
const d = new Date()
const p = (n: number) => String(n).padStart(2, '0')
return `${p(d.getUTCHours())}:${p(d.getUTCMinutes())}:${p(d.getUTCSeconds())}`
}
const LOG_LEN = 7
// Placeholder shell. The real component library — <Faceplate> <Module> <Toggle>
// <Led> <SegMeter> <QueryLog> — and the pages are built per docs-shater/DESIGN.md
// (north-star prototype) in Phase 3. This only proves the scaffold + tokens load.
export function App() {
const seq = useRef(0)
const makeEntry = useCallback((): QueryEntry => {
const [domain, device, tag] = FEED[Math.floor(Math.random() * FEED.length)]
return { id: seq.current++, time: stamp(), domain, device, tag }
}, [])
// ---- throughput targets (the meters ease toward these) ----
const [dn, setDn] = useState(62)
const [up, setUp] = useState(9)
useEffect(() => {
const id = window.setInterval(() => {
if (Math.random() < 0.55) setDn(8 + Math.random() * 90)
if (Math.random() < 0.55) setUp(2 + Math.random() * 22)
}, 1400)
return () => window.clearInterval(id)
}, [])
// ---- streaming query log ----
const [entries, setEntries] = useState<QueryEntry[]>(() =>
Array.from({ length: LOG_LEN }, makeEntry),
)
useEffect(() => {
const id = window.setInterval(() => {
setEntries((prev) => [makeEntry(), ...prev].slice(0, LOG_LEN))
}, 2200)
return () => window.clearInterval(id)
}, [makeEntry])
// ---- module switches ----
const [tunnel, setTunnel] = useState(true)
const [filter, setFilter] = useState(true)
// ---- apply flow → toast ----
const [toast, setToast] = useState<string | null>(null)
const toastTimer = useRef<number | undefined>(undefined)
const apply = useCallback(() => {
setToast('Applied')
window.clearTimeout(toastTimer.current)
toastTimer.current = window.setTimeout(() => setToast(null), 2400)
}, [])
useEffect(() => () => window.clearTimeout(toastTimer.current), [])
// ---- stable per-device activity bars ----
const bars = useRef<number[]>(
Array.from({ length: 12 }, () => 20 + Math.random() * 80),
).current
return (
<div className="boot">
<div className="boot-plate">
<div className="boot-wordmark mono">SHATER</div>
<div className="boot-sub">admin panel · v0.2</div>
<div className="boot-led" aria-hidden />
<p className="boot-note">
Faceplate scaffold ready. Component library and pages land in Phase 3.
</p>
</div>
</div>
<Faceplate
ariaLabel="shater appliance overview"
header={
<FaceplateHeader
wordmark="SHATER"
subline="v0.2 · openwrt appliance · bpi-r4"
status={{ label: 'Online', variant: 'on', pulse: true }}
/>
}
footer={
<footer className="foot">
<span>SN 5AC4-B177-689C-B8E0</span>
<span>feed signed · gitea</span>
<span className="spacer" />
<Button onClick={apply}>Apply config</Button>
<Button variant="primary">Open panel →</Button>
</footer>
}
>
<section className="meters" aria-label="Throughput">
<SegMeter label="↓ Download" value={dn} max={100} />
<SegMeter label="↑ Upload" value={up} max={26} />
</section>
<section className="grid" aria-label="Modules">
<Module
name="Tunnel"
value="AmneziaWG"
unit="2.0"
toggle={{ pressed: tunnel, onChange: setTunnel, label: 'Tunnel enabled' }}
rows={[
{ k: 'exit', v: '🇳🇱 amsterdam' },
{ k: 'handshake', v: '12 s ago' },
{ k: 'ping', v: '38 ms' },
]}
/>
<Module
name="Filter"
value="3 481"
unit="blocked"
toggle={{ pressed: filter, onChange: setFilter, label: 'Filter enabled' }}
rows={[
{ k: 'lists', v: '6 · 1.2M rules' },
{ k: 'block rate', v: '27.4%', hot: true },
{ k: 'updated', v: '4 h ago' },
]}
/>
<Module
name="Devices"
value="12"
unit="online"
led={{ variant: 'on' }}
rows={[{ k: 'flagged', v: '2 devices', hot: true }]}
>
<div className="bars" aria-hidden="true">
{bars.map((h, i) => (
<i key={i} style={{ height: `${h}%` }} />
))}
</div>
</Module>
<Module
name="DNS"
value="DoH"
unit="· fakeip"
led={{ variant: 'on' }}
rows={[
{ k: 'resolver', v: 'cloudflare' },
{ k: 'leaks', v: '0 detected' },
{ k: 'client doh', v: 'blocked' },
]}
/>
<Module
name="Nodes"
value="5"
unit="/ 6 up"
led={{ variant: 'on' }}
rows={[
{ k: 'balancer', v: 'least-ping' },
{ k: 'active', v: 'nl-reality-2', hot: true },
{ k: 'observatory', v: 'healthy' },
]}
/>
<Module
name="Kill-switch"
value="ARMED"
led={{ variant: 'on' }}
rows={[
{ k: 'policy', v: 'fail-closed' },
{ k: 'ipv6', v: 'dropped' },
{ k: 'last apply', v: 'ok · rollback ready' },
]}
/>
</section>
<QueryLog hint="tap a row to block / allow" entries={entries} />
{toast && (
<div className="toast" role="status">
{toast}
</div>
)}
</Faceplate>
)
}
+32
View File
@@ -0,0 +1,32 @@
/* Buttons — mono, uppercase. .btn is ghost; .btn.primary is solid orange. */
.btn {
display: inline-block;
padding: 7px 12px;
border: 1px solid var(--groove);
border-radius: 6px;
background: var(--raised);
color: var(--ink);
box-shadow: 0 1px 0 var(--edge) inset;
font-family: var(--font-mono);
font-size: 11px;
letter-spacing: 0.12em;
text-transform: uppercase;
text-decoration: none;
cursor: pointer;
transition:
border-color 0.15s,
color 0.15s;
}
.btn:hover {
border-color: var(--accent);
color: var(--accent);
}
.btn.primary {
border-color: transparent;
background: var(--accent);
color: #fff;
}
.btn.primary:hover {
color: #fff;
filter: brightness(1.05);
}
+19
View File
@@ -0,0 +1,19 @@
import './Button.css'
import type { ButtonHTMLAttributes } from 'react'
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
/** `primary` is the solid-orange call to action; `ghost` is the default. */
variant?: 'ghost' | 'primary'
}
export function Button({ variant = 'ghost', className, type, ...rest }: ButtonProps) {
return (
<button
type={type ?? 'button'}
className={['btn', variant === 'primary' ? 'primary' : '', className]
.filter(Boolean)
.join(' ')}
{...rest}
/>
)
}
+18
View File
@@ -0,0 +1,18 @@
import { useEffect, useState } from 'react'
function format(d: Date): string {
const p = (n: number) => String(n).padStart(2, '0')
return `${p(d.getUTCHours())}:${p(d.getUTCMinutes())}:${p(d.getUTCSeconds())} UTC`
}
/** Live UTC readout, tabular digits, ticking once a second. */
export function Clock({ className }: { className?: string }) {
const [now, setNow] = useState(() => format(new Date()))
useEffect(() => {
const id = window.setInterval(() => setNow(format(new Date())), 1000)
return () => window.clearInterval(id)
}, [])
return <span className={['clock', className].filter(Boolean).join(' ')}>{now}</span>
}
+179
View File
@@ -0,0 +1,179 @@
/* <Faceplate> — the rack-unit panel shell, plus the shared page-layout bands
* (1U header, throughput meters, module grid, footer) every page reuses. */
:root {
--u: 8px; /* layout rhythm; not a colour token */
}
.fp-app {
min-height: 100vh;
padding: calc(var(--u) * 3) calc(var(--u) * 2);
/* faint accent bloom from the top — the only place orange touches the field */
background: radial-gradient(
120% 80% at 50% -10%,
color-mix(in srgb, var(--accent) 5%, var(--panel)),
var(--panel) 55%
);
}
.fp-wrap {
max-width: 1080px;
margin: 0 auto;
}
/* the plate: brushed texture, hairline edge, corner screws */
.plate {
position: relative;
padding: calc(var(--u) * 3);
border: 1px solid var(--groove);
border-radius: 14px;
background:
repeating-linear-gradient(
90deg,
transparent 0 2px,
color-mix(in srgb, var(--edge) 30%, transparent) 2px 3px
),
linear-gradient(180deg, var(--raised), var(--panel));
box-shadow:
0 1px 0 var(--edge) inset,
0 22px 50px -24px var(--shadow),
0 2px 6px var(--shadow);
}
.screw {
position: absolute;
width: 12px;
height: 12px;
border-radius: 50%;
background: radial-gradient(
circle at 35% 30%,
color-mix(in srgb, var(--edge) 60%, var(--sink)),
var(--sink) 70%
);
box-shadow:
0 1px 1px var(--edge) inset,
0 1px 2px var(--shadow);
}
.screw::after {
content: '';
position: absolute;
inset: 3px;
top: 5px;
border-top: 1.5px solid var(--groove);
transform: rotate(38deg);
}
.screw.tl {
top: 10px;
left: 10px;
}
.screw.tr {
top: 10px;
right: 10px;
}
.screw.bl {
bottom: 10px;
left: 10px;
}
.screw.br {
bottom: 10px;
right: 10px;
}
/* ---- 1U header ---- */
.u1 {
display: flex;
align-items: center;
gap: calc(var(--u) * 2.5);
flex-wrap: wrap;
padding-bottom: calc(var(--u) * 2.5);
border-bottom: 1px solid var(--groove);
}
.brand {
display: flex;
flex-direction: column;
gap: 2px;
padding: 0 calc(var(--u) * 1.5) 0 calc(var(--u) * 0.5);
}
.wordmark {
padding-left: 0.32em;
font-family: var(--font-mono);
font-weight: 700;
font-size: 26px;
letter-spacing: 0.32em;
color: var(--ink);
text-shadow:
0 1px 0 var(--edge),
0 -1px 1px var(--shadow);
}
.subline {
font-family: var(--font-mono);
font-size: 10px;
letter-spacing: 0.22em;
color: var(--faint);
text-transform: uppercase;
}
.u1 .spacer,
.foot .spacer {
flex: 1;
}
.master {
display: flex;
align-items: center;
gap: 10px;
font-family: var(--font-mono);
font-size: 12px;
letter-spacing: 0.18em;
color: var(--dim);
text-transform: uppercase;
}
.clock {
font-family: var(--font-mono);
font-size: 12px;
letter-spacing: 0.1em;
color: var(--dim);
font-variant-numeric: tabular-nums;
}
/* ---- layout bands ---- */
.meters {
display: grid;
grid-template-columns: 1fr 1fr;
gap: calc(var(--u) * 2);
padding: calc(var(--u) * 2.5) 0;
border-bottom: 1px solid var(--groove);
}
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: calc(var(--u) * 2);
padding-top: calc(var(--u) * 3);
}
/* ---- footer plate ---- */
.foot {
display: flex;
align-items: center;
gap: calc(var(--u) * 2);
flex-wrap: wrap;
margin-top: calc(var(--u) * 2.5);
padding-top: calc(var(--u) * 2);
border-top: 1px solid var(--groove);
font-family: var(--font-mono);
font-size: 10.5px;
letter-spacing: 0.14em;
color: var(--faint);
text-transform: uppercase;
}
@media (max-width: 820px) {
.grid {
grid-template-columns: 1fr 1fr;
}
}
@media (max-width: 560px) {
.grid,
.meters {
grid-template-columns: 1fr;
}
.wordmark {
font-size: 22px;
}
}
+39
View File
@@ -0,0 +1,39 @@
import './Faceplate.css'
import type { ReactNode } from 'react'
export interface FaceplateProps {
/** The 1U header row (usually <FaceplateHeader/>). */
header?: ReactNode
/** The footer plate (serial + actions). */
footer?: ReactNode
/** Panel body — meters, module grid, query log, etc. */
children: ReactNode
ariaLabel?: string
}
/**
* The rack-unit faceplate shell: brushed plate, corner screws, header/body/footer
* slots, centered to ~1080px. Every page mounts inside one of these.
*/
export function Faceplate({
header,
footer,
children,
ariaLabel = 'shater appliance',
}: FaceplateProps) {
return (
<div className="fp-app">
<div className="fp-wrap">
<main className="plate" aria-label={ariaLabel}>
<span className="screw tl" aria-hidden="true" />
<span className="screw tr" aria-hidden="true" />
<span className="screw bl" aria-hidden="true" />
<span className="screw br" aria-hidden="true" />
{header}
{children}
{footer}
</main>
</div>
</div>
)
}
+33
View File
@@ -0,0 +1,33 @@
import { Led } from './Led'
import type { LedVariant } from './Led'
import { Clock } from './Clock'
import { ThemeSwitch } from './ThemeSwitch'
export interface FaceplateHeaderProps {
/** Etched wordmark, e.g. "SHATER". */
wordmark: string
/** Sub-line under it (device / build). */
subline: string
/** Master status indicator on the right. */
status?: { label: string; variant?: LedVariant; pulse?: boolean }
}
/** The shared 1U header: wordmark + sub-line, master LED, live UTC clock, theme switch. */
export function FaceplateHeader({ wordmark, subline, status }: FaceplateHeaderProps) {
return (
<header className="u1">
<div className="brand">
<div className="wordmark">{wordmark}</div>
<div className="subline">{subline}</div>
</div>
<div className="spacer" />
{status && (
<div className="master">
<Led variant={status.variant ?? 'on'} pulse={status.pulse} /> {status.label}
</div>
)}
<Clock />
<ThemeSwitch />
</header>
)
}
+36
View File
@@ -0,0 +1,36 @@
/* <Led> — status dot with glow. Semantic colors, never the brand accent. */
.led {
display: inline-block;
width: 10px;
height: 10px;
flex: none;
border-radius: 50%;
background: var(--seg-off);
box-shadow: 0 0 0 1px var(--groove) inset;
}
.led.on {
background: var(--led-on);
box-shadow:
0 0 0 1px color-mix(in srgb, var(--led-on) 50%, #000) inset,
0 0 8px var(--led-on);
}
.led.amber {
background: var(--amber);
box-shadow: 0 0 8px var(--amber);
}
.led.crit {
background: var(--crit);
box-shadow: 0 0 8px var(--crit);
}
.led.pulse {
animation: led-pulse 2.4s ease-in-out infinite;
}
@keyframes led-pulse {
0%,
100% {
opacity: 1;
}
50% {
opacity: 0.45;
}
}
+37
View File
@@ -0,0 +1,37 @@
import './Led.css'
export type LedVariant = 'on' | 'amber' | 'crit' | 'off'
export interface LedProps {
/** Semantic status. `off` is an unlit socket. */
variant?: LedVariant
/** Slow breathing glow (killed under reduced-motion). */
pulse?: boolean
/**
* Accessible name. When set the dot is exposed as an image with this label;
* otherwise it is decorative (`aria-hidden`) and the surrounding text carries
* the meaning.
*/
label?: string
className?: string
}
export function Led({ variant = 'off', pulse = false, label, className }: LedProps) {
const cls = [
'led',
variant !== 'off' ? variant : '',
pulse ? 'pulse' : '',
className ?? '',
]
.filter(Boolean)
.join(' ')
return (
<span
className={cls}
role={label ? 'img' : undefined}
aria-label={label}
aria-hidden={label ? undefined : true}
/>
)
}
+84
View File
@@ -0,0 +1,84 @@
/* <Module> — an engraved-label card. */
.mod {
position: relative;
display: flex;
flex-direction: column;
gap: calc(var(--u, 8px) * 1.25);
min-height: 132px;
padding: calc(var(--u, 8px) * 2);
border: 1px solid var(--groove);
border-radius: 9px;
background: linear-gradient(
180deg,
var(--raised),
color-mix(in srgb, var(--raised) 82%, var(--panel))
);
box-shadow:
0 1px 0 var(--edge) inset,
0 8px 18px -14px var(--shadow);
}
.mod .hd {
display: flex;
align-items: center;
gap: 8px;
}
.mod .name {
flex: 1;
font-family: var(--font-mono);
font-size: 11px;
letter-spacing: 0.24em;
color: var(--dim);
text-transform: uppercase;
}
.mod .big {
font-family: var(--font-mono);
font-weight: 700;
font-size: 22px;
letter-spacing: 0.01em;
line-height: 1;
color: var(--ink);
font-variant-numeric: tabular-nums;
}
.mod .big small {
font-size: 12px;
font-weight: 500;
letter-spacing: 0.08em;
color: var(--dim);
}
.mod .rows {
display: flex;
flex-direction: column;
gap: 5px;
margin-top: auto;
}
.mod .row {
display: flex;
justify-content: space-between;
font-family: var(--font-mono);
font-size: 12px;
letter-spacing: 0.04em;
}
.mod .row .k {
color: var(--faint);
}
.mod .row .v {
color: var(--ink);
font-variant-numeric: tabular-nums;
}
.mod .row .v.hot {
color: var(--accent);
}
/* mini activity bars (e.g. per-device load) — accent used as a data mark */
.bars {
display: flex;
gap: 3px;
align-items: flex-end;
height: 26px;
}
.bars i {
flex: 1;
border-radius: 1px;
background: var(--accent);
opacity: 0.85;
}
+74
View File
@@ -0,0 +1,74 @@
import './Module.css'
import type { ReactNode } from 'react'
import { Led } from './Led'
import type { LedProps } from './Led'
import { Toggle } from './Toggle'
import type { ToggleProps } from './Toggle'
export interface ModuleRow {
/** Key (silkscreen, dim). */
k: string
/** Value; `hot` paints it with the accent. */
v: ReactNode
hot?: boolean
}
export interface ModuleProps {
/** Engraved label. */
name: string
/** Big mono headline value. */
value: ReactNode
/** Small unit trailing the value. */
unit?: ReactNode
/** A status LED in the header (used when there is no toggle). */
led?: LedProps
/** A switch in the header (size/tone are fixed to the module style). */
toggle?: Omit<ToggleProps, 'size'> & Partial<Pick<ToggleProps, 'tone'>>
/** Key/value lines pinned to the bottom of the card. */
rows?: ModuleRow[]
/** Custom content (e.g. mini bars) between the value and the rows. */
children?: ReactNode
className?: string
}
export function Module({
name,
value,
unit,
led,
toggle,
rows,
children,
className,
}: ModuleProps) {
return (
<div className={['mod', className].filter(Boolean).join(' ')}>
<div className="hd">
<span className="name">{name}</span>
{toggle ? (
<Toggle size="sm" tone={toggle.tone ?? 'led'} {...toggle} />
) : led ? (
<Led {...led} />
) : null}
</div>
<div className="big">
{value}
{unit != null ? <small> {unit}</small> : null}
</div>
{children}
{rows && rows.length > 0 && (
<div className="rows">
{rows.map((r, i) => (
<div className="row" key={i}>
<span className="k">{r.k}</span>
<span className={r.hot ? 'v hot' : 'v'}>{r.v}</span>
</div>
))}
</div>
)}
</div>
)
}
+107
View File
@@ -0,0 +1,107 @@
/* <QueryLog> — streaming ticker, newest on top. */
.log {
margin-top: calc(var(--u, 8px) * 2);
overflow: hidden;
border: 1px solid var(--groove);
border-radius: 9px;
background: var(--sink);
box-shadow: 0 2px 6px -3px var(--shadow) inset;
}
.log .lh {
display: flex;
align-items: center;
gap: 10px;
padding: calc(var(--u, 8px) * 1.25) calc(var(--u, 8px) * 2);
border-bottom: 1px solid var(--groove);
font-family: var(--font-mono);
font-size: 11px;
letter-spacing: 0.2em;
color: var(--dim);
text-transform: uppercase;
}
.log .lh .spacer {
flex: 1;
}
.log .lh .hint {
letter-spacing: 0.14em;
text-transform: none;
color: var(--faint);
}
.qrows {
list-style: none;
margin: 0;
padding: calc(var(--u, 8px) * 0.5) 0;
max-height: 210px;
overflow: hidden;
}
.qrow {
display: grid;
grid-template-columns: 76px 1fr auto auto;
align-items: center;
gap: calc(var(--u, 8px) * 1.5);
padding: 7px calc(var(--u, 8px) * 2);
font-family: var(--font-mono);
font-size: 12.5px;
font-variant-numeric: tabular-nums;
}
.qrow .t {
color: var(--faint);
}
.qrow .d {
overflow: hidden;
color: var(--ink);
text-overflow: ellipsis;
white-space: nowrap;
}
.qrow .dev {
font-size: 11px;
color: var(--faint);
}
.qrow.new {
animation: qrow-slidein 0.4s ease;
}
@keyframes qrow-slidein {
from {
opacity: 0;
transform: translateY(-6px);
}
to {
opacity: 1;
transform: none;
}
}
/* tags carry semantics, not the accent: pass=led, block=crit, proxy=accent */
.tag {
padding: 2px 8px;
border: 1px solid transparent;
border-radius: 4px;
font-family: var(--font-mono);
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.tag.pass {
color: var(--led-on);
border-color: color-mix(in srgb, var(--led-on) 45%, transparent);
background: color-mix(in srgb, var(--led-on) 12%, transparent);
}
.tag.block {
color: var(--crit);
border-color: color-mix(in srgb, var(--crit) 45%, transparent);
background: color-mix(in srgb, var(--crit) 12%, transparent);
}
.tag.proxy {
color: var(--accent);
border-color: color-mix(in srgb, var(--accent) 45%, transparent);
background: color-mix(in srgb, var(--accent) 12%, transparent);
}
@media (max-width: 560px) {
.qrow {
grid-template-columns: 64px 1fr auto;
}
.qrow .dev {
display: none;
}
}
+50
View File
@@ -0,0 +1,50 @@
import './QueryLog.css'
import { Led } from './Led'
export type QueryTag = 'proxy' | 'block' | 'pass'
export interface QueryEntry {
/** Stable identity — drives the slide-in of a freshly-added top row. */
id: string | number
/** Timestamp text, e.g. "12:04:33". */
time: string
domain: string
device?: string
tag: QueryTag
}
export interface QueryLogProps {
title?: string
/** Small right-aligned instruction in the header. */
hint?: string
/** Entries, newest first (index 0 renders on top and animates in). */
entries: QueryEntry[]
}
export function QueryLog({
title = 'Query log · streaming',
hint,
entries,
}: QueryLogProps) {
return (
<section className="log" aria-label="Live query log">
<div className="lh">
<Led variant="on" pulse /> {title}
<span className="spacer" />
{hint && <span className="hint">{hint}</span>}
</div>
<ul className="qrows">
{entries.map((e, i) => (
// Only the newest node gets `new`; with stable keys React replays the
// slide-in for exactly the row that just entered.
<li className={i === 0 ? 'qrow new' : 'qrow'} key={e.id}>
<span className="t">{e.time}</span>
<span className="d">{e.domain}</span>
<span className="dev">{e.device ?? ''}</span>
<span className={`tag ${e.tag}`}>{e.tag}</span>
</li>
))}
</ul>
</section>
)
}
+53
View File
@@ -0,0 +1,53 @@
/* <SegMeter> — segmented VU meter. The top few segments read crit at peak. */
.meter {
display: flex;
flex-direction: column;
gap: 10px;
}
.meter .top {
display: flex;
align-items: baseline;
justify-content: space-between;
font-family: var(--font-mono);
}
.meter .lab {
font-size: 11px;
letter-spacing: 0.22em;
color: var(--dim);
text-transform: uppercase;
}
.meter .val {
font-size: 26px;
font-weight: 700;
letter-spacing: 0.02em;
color: var(--ink);
font-variant-numeric: tabular-nums;
}
.meter .val .unit {
margin-left: 4px;
font-size: 12px;
font-weight: 500;
color: var(--dim);
}
.segs {
display: flex;
gap: 3px;
height: 22px;
}
.seg {
flex: 1;
border-radius: 2px;
background: var(--seg-off);
box-shadow: 0 0 0 1px var(--shadow) inset;
transition:
background 0.12s,
box-shadow 0.12s;
}
.seg.lit {
background: var(--seg-on);
box-shadow: 0 0 6px color-mix(in srgb, var(--seg-on) 60%, transparent);
}
.seg.peak {
background: var(--crit);
box-shadow: 0 0 6px var(--crit);
}
+79
View File
@@ -0,0 +1,79 @@
import './SegMeter.css'
import { useEffect, useRef, useState } from 'react'
import { usePrefersReducedMotion } from './usePrefersReducedMotion'
export interface SegMeterProps {
/** Silkscreen label, e.g. "↓ Download". */
label: string
/** Target reading; the meter eases toward it. */
value: number
/** Full-scale value (maps to all segments lit). */
max: number
/** Small unit shown after the number. */
unit?: string
/** Segment count. */
segments?: number
/** How many top segments turn crit when lit. */
peak?: number
}
function formatValue(v: number): string {
return v < 10 ? v.toFixed(1) : String(Math.round(v))
}
export function SegMeter({
label,
value,
max,
unit = 'Mb/s',
segments = 28,
peak = 3,
}: SegMeterProps) {
const reduced = usePrefersReducedMotion()
const [display, setDisplay] = useState(value)
const displayRef = useRef(value)
useEffect(() => {
// Reduced motion: snap straight to the target, no rAF loop.
if (reduced) {
displayRef.current = value
setDisplay(value)
return
}
let raf = 0
const step = () => {
let cur = displayRef.current
cur += (value - cur) * 0.18 // exponential ease toward target
if (Math.abs(value - cur) < 0.05) cur = value
displayRef.current = cur
setDisplay(cur)
if (cur !== value) raf = requestAnimationFrame(step)
}
raf = requestAnimationFrame(step)
return () => cancelAnimationFrame(raf)
}, [value, reduced])
const lit = Math.max(0, Math.min(segments, Math.round((display / max) * segments)))
return (
<div className="meter">
<div className="top">
<span className="lab">{label}</span>
<span className="val">
{formatValue(display)}
<span className="unit">{unit}</span>
</span>
</div>
<div className="segs" aria-hidden="true">
{Array.from({ length: segments }, (_, i) => {
const on = i < lit
const isPeak = on && i >= segments - peak
return (
<span key={i} className={isPeak ? 'seg peak' : on ? 'seg lit' : 'seg'} />
)
})}
</div>
</div>
)
}
+56
View File
@@ -0,0 +1,56 @@
import { useEffect, useState } from 'react'
import { Toggle } from './Toggle'
const STORAGE_KEY = 'shater-theme'
function systemDark(): boolean {
return (
typeof window !== 'undefined' &&
window.matchMedia('(prefers-color-scheme: dark)').matches
)
}
/** Resolve the *effective* theme: explicit override wins, else the OS preference. */
function currentDark(): boolean {
const attr = document.documentElement.getAttribute('data-theme')
if (attr === 'dark') return true
if (attr === 'light') return false
return systemDark()
}
/**
* Header theme switch. Stamps `data-theme` on the root element (which the tokens
* honour in both directions) and persists the choice to localStorage. An inline
* script in index.html applies the stored value before first paint to avoid a flash.
*/
export function ThemeSwitch() {
const [dark, setDark] = useState(() =>
typeof document !== 'undefined' ? currentDark() : false,
)
// Reconcile with whatever the pre-paint script / OS settled on.
useEffect(() => {
setDark(currentDark())
}, [])
const apply = (next: boolean) => {
const theme = next ? 'dark' : 'light'
document.documentElement.setAttribute('data-theme', theme)
try {
localStorage.setItem(STORAGE_KEY, theme)
} catch {
// storage may be unavailable (private mode) — the in-memory state still holds.
}
setDark(next)
}
return (
<Toggle
size="md"
tone="accent"
pressed={dark}
onChange={apply}
label="Toggle dark mode"
/>
)
}
+66
View File
@@ -0,0 +1,66 @@
/* <Toggle> — a physical sliding switch. A real <button aria-pressed>, so it is
* keyboard-operable for free (Enter / Space). */
.toggle {
position: relative;
flex: none;
appearance: none;
border: 0;
cursor: pointer;
background: var(--sink);
box-shadow:
0 1px 2px var(--shadow) inset,
0 0 0 1px var(--groove);
transition: background 0.18s;
}
.toggle::after {
content: '';
position: absolute;
border-radius: 50%;
background: radial-gradient(circle at 35% 30%, var(--edge), var(--raised));
box-shadow: 0 1px 3px var(--shadow);
transition: transform 0.18s;
}
.toggle:disabled {
cursor: not-allowed;
opacity: 0.5;
}
/* md — header / theme switch */
.toggle.md {
width: 52px;
height: 26px;
border-radius: 13px;
}
.toggle.md::after {
top: 3px;
left: 3px;
width: 20px;
height: 20px;
}
.toggle.md[aria-pressed='true']::after {
transform: translateX(26px);
}
/* sm — module switch */
.toggle.sm {
width: 42px;
height: 22px;
border-radius: 11px;
}
.toggle.sm::after {
top: 2.5px;
left: 2.5px;
width: 17px;
height: 17px;
}
.toggle.sm[aria-pressed='true']::after {
transform: translateX(20px);
}
/* tone when engaged — accent (theme) vs led-on (a running module) */
.toggle.accent[aria-pressed='true'] {
background: color-mix(in srgb, var(--accent) 55%, var(--sink));
}
.toggle.led[aria-pressed='true'] {
background: color-mix(in srgb, var(--led-on) 55%, var(--sink));
}
+37
View File
@@ -0,0 +1,37 @@
import './Toggle.css'
export interface ToggleProps {
/** Current on/off state. */
pressed: boolean
/** Called with the next state on click / keypress. */
onChange: (next: boolean) => void
/** Accessible name — required; the switch has no visible label of its own. */
label: string
/** `md` for the header/theme switch, `sm` for a module switch. */
size?: 'sm' | 'md'
/** Engaged colour: `accent` (theme) or `led` (a running module). */
tone?: 'accent' | 'led'
disabled?: boolean
className?: string
}
export function Toggle({
pressed,
onChange,
label,
size = 'sm',
tone = 'led',
disabled,
className,
}: ToggleProps) {
return (
<button
type="button"
className={['toggle', size, tone, className].filter(Boolean).join(' ')}
aria-pressed={pressed}
aria-label={label}
disabled={disabled}
onClick={() => onChange(!pressed)}
/>
)
}
+20
View File
@@ -0,0 +1,20 @@
// Faceplate component library — build once, reuse on every page.
export { Faceplate } from './Faceplate'
export type { FaceplateProps } from './Faceplate'
export { FaceplateHeader } from './FaceplateHeader'
export type { FaceplateHeaderProps } from './FaceplateHeader'
export { Module } from './Module'
export type { ModuleProps, ModuleRow } from './Module'
export { Toggle } from './Toggle'
export type { ToggleProps } from './Toggle'
export { Led } from './Led'
export type { LedProps, LedVariant } from './Led'
export { SegMeter } from './SegMeter'
export type { SegMeterProps } from './SegMeter'
export { QueryLog } from './QueryLog'
export type { QueryLogProps, QueryEntry, QueryTag } from './QueryLog'
export { Button } from './Button'
export type { ButtonProps } from './Button'
export { Clock } from './Clock'
export { ThemeSwitch } from './ThemeSwitch'
export { usePrefersReducedMotion } from './usePrefersReducedMotion'
@@ -0,0 +1,22 @@
import { useEffect, useState } from 'react'
/**
* Tracks the user's `prefers-reduced-motion` setting, live.
* Components use it to snap instead of animate (meters, LED pulse, log slide-in).
*/
export function usePrefersReducedMotion(): boolean {
const [reduced, setReduced] = useState(
() =>
typeof window !== 'undefined' &&
window.matchMedia('(prefers-reduced-motion: reduce)').matches,
)
useEffect(() => {
const mq = window.matchMedia('(prefers-reduced-motion: reduce)')
const onChange = () => setReduced(mq.matches)
mq.addEventListener('change', onChange)
return () => mq.removeEventListener('change', onChange)
}, [])
return reduced
}