Getting started
Theming and brands
One theme contract for every site, and brands that change values without touching components.
The theme contract#
The theme lives in data-theme="light" or data-theme="dark" on the <html> element. It resolves in this order:
- The stored choice in
localStorage, if it is exactly "light" or "dark". - The
prefers-color-schememedia query. - Light.
A tiny inline script in the head sets the attribute before first paint, wrapped in try/catch so blocked storage never breaks the page. Without JavaScript, the stylesheet still follows prefers-color-scheme when no attribute is present.
<meta name="color-scheme" content="light dark">
<meta name="theme-color" content="#fafaf9" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#0a0a0a" media="(prefers-color-scheme: dark)">Storage keys#
Each site keeps the key it already uses, so saved visitor preferences survive the migration. The key is configurable in both the script and the behavior.
| Site | Storage key |
|---|---|
| mateuseap.com and the blog | theme |
| HomeLab landing | theme |
| Origin Labs landing | originlabs-theme |
| Gabarito | gabarito-theme |
| This documentation site | halora-theme |
import { initTheme, themeInitScript } from '@originlabsbr/halora/theme';
// server or build step: generate the head snippet for a site's own key
const snippet = themeInitScript({ storageKey: 'originlabs-theme' });
// browser: wire the toggle buttons and keep the key
initTheme({ storageKey: 'originlabs-theme' });A toggle button#
<button type="button" class="ha-icon-button ha-theme-toggle" data-ha-theme-toggle aria-label="Switch theme">
<span class="ha-theme-toggle__sun"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/></svg></span>
<span class="ha-theme-toggle__moon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z"/></svg></span>
</button>The label is set by initTheme to name the action, for example "Switch to light theme".
Brands#
A brand is a complete set of color tokens for both themes, plus its font families. Origin is the default and needs no attribute. Add data-brand="gabarito" to the root, or to any element, to switch.
<html lang="en" data-theme="dark" data-brand="gabarito">
<!-- or scope one subtree: set both attributes together -->
<section class="ha-scope" data-theme="light" data-brand="origin">...</section>The Gabarito brand#
Gabarito is the product brand of the Gabarito exam practice site. It keeps its own identity: a near-black canvas, lime fills with dark ink, a violet glow, and Plus Jakarta Sans. In light theme the lime stays a fill and text uses a darker green so it passes AA.
| Token | Origin dark | Gabarito dark | Gabarito light |
|---|---|---|---|
canvas | #0a0a0a | #060608 | #f4f6f1 |
accent-fill | #c2410c | #a8e05f | #a8e05f |
on-accent | #ffffff | #101508 | #101508 |
accent-text | #ff8c42 | #a8e05f | #3a6310 |
glow | #8b5cf6 | #8b7cf6 | #7a68ee |
font-sans | Inter | Plus Jakarta Sans | Plus Jakarta Sans |
Create a brand#
- Add an entry to
tokens/index.mjs. Definelightanddarkcolor sets (spread an existing set and override what differs) and the three font families. - Run
npm run build. This writesdist/brands/<id>.cssand a fullbundles/halora.<id>.min.css. - Run
npm test. The contrast gate checks every pair for the new brand and tells you which token fails and by how much. - Add the brand to the documentation site and a note in the changelog.
// tokens/index.mjs
const acmeLight = { ...originLight, canvas: '#f7f7fb', 'accent-fill': '#4338ca', 'on-accent': '#ffffff', 'accent-text': '#4338ca' /* ... */ };
const acmeDark = { ...originDark, canvas: '#0b0b12', 'accent-fill': '#6366f1', 'on-accent': '#0b0b12', 'accent-text': '#a5b4fc' /* ... */ };
brands.acme = {
id: 'acme', name: 'Acme', description: 'Acme product brand.',
fonts: { sans: "'Inter', sans-serif", mono: "ui-monospace, monospace", display: "'Inter', sans-serif" },
themes: { light: acmeLight, dark: acmeDark },
};Using a brand without an attribute#
If a site only ever uses one brand, load its bundle. The values are the defaults, so no data-brand attribute is needed.
<link rel="stylesheet" href="https://designsystem.lab.mateuseap.com/cdn/halora@0.1.0/bundles/halora.gabarito.min.css">