feat: give every Ekklesia screen one set of design tokens and elements
Modules have owned their own UI since ADR 0021, but the platform has never said what that UI should look like. Every screen here — the Dashboard shell, the display host, the module template — invented its own hex colours, font stack, spacing, and radii, and they already disagreed. A module author had no vocabulary for "the ordinary panel background", so the only available answer was to invent one, and two modules would invent two. Add `@ekklesia/design-tokens`: one validated, enumerable registry of semantic tokens. A token declares a name, label, description, and default value; its category and `--ekklesia-*` identifier are derived from the name, so it can never claim one category while being named for another. Construction rejects duplicates, malformed names, unknown categories, empty or overlong text, and any value that is not a bounded literal — no declaration terminator, rule block, comment, at-rule, `url(`, `!important`, escape, control character, or markup. A registry that constructs can therefore be emitted as CSS without escaping, because nothing needing escaping can be in it. That validation is also what makes a future theme editor implementable rather than aspirational. Add `@ekklesia/ui`: button, icon button, text input, select, checkbox, field wrapper, panel, dialog, tabs, table and list primitives, badge, toast, and empty/error/loading states — every value a token reference, with real `:focus-visible` treatment and status that never depends on colour alone. Deliberately small: an element earns its place when two consumers need it. The stylesheet is a string rather than a `.css` file so the identical bytes install into a document or an isolated artifact root, and so hover, disabled, and focus-visible are real CSS rather than JavaScript approximations of them. `pnpm boundaries` opens exactly two shared roles to modules, by name — every other role stays rejected — and pins both design packages to the bottom of the presentation stack. Both are browser-safe by construction, proven by a real compile of module-shaped source in which `process.env` must fail to typecheck. The shell installs the defaults at its document root for the Dashboard and the display; custom properties inherit into module artifacts, so a module reads `var(--ekklesia-…)` with nothing to import at run time and nothing for a host to forget to pass. Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5
parent
b14613decd
commit
e03d38fcab
@@ -0,0 +1,550 @@
|
||||
import {
|
||||
createDesignTokenRegistry,
|
||||
type DesignTokenInput,
|
||||
type DesignTokenScope,
|
||||
} from "./token.js";
|
||||
|
||||
/**
|
||||
* Ekklesia's global semantic theme.
|
||||
*
|
||||
* These are **semantic** tokens, not a palette. Nothing here is named for the colour it currently
|
||||
* happens to be, because the whole point is that a future theme editor can change the value without
|
||||
* every consumer's meaning changing with it: `background.raised` stays "the surface that sits above
|
||||
* an ordinary surface" whatever a church's brand makes it.
|
||||
*
|
||||
* The default values are a neutral, high-contrast light theme. They are defaults, not a brand —
|
||||
* a deployment overrides them by installing different values at its host root, and this pass
|
||||
* deliberately ships no theme editor, brand builder, or dark-mode variant to do that with.
|
||||
*
|
||||
* ## Status is never colour alone
|
||||
*
|
||||
* Each status family carries a `symbol` token alongside its colours. A status that is only red is
|
||||
* invisible to a person who cannot distinguish it, and unreadable on a projector or a washed-out
|
||||
* lobby screen. Component code renders the symbol next to the label, so the meaning survives losing
|
||||
* the colour entirely (WCAG 2.2 §1.4.1).
|
||||
*/
|
||||
const declarations = [
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Backgrounds — the elevation ladder, from the page behind everything to the overlay above it.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
{
|
||||
description: "The furthest-back background of a whole page or a full-viewport display.",
|
||||
label: "Page background",
|
||||
name: "background.page",
|
||||
value: "#f6f6f5",
|
||||
},
|
||||
{
|
||||
description:
|
||||
"A large working area inside a page — a scrolling list region, a preview area, an editor body.",
|
||||
label: "Canvas background",
|
||||
name: "background.canvas",
|
||||
value: "#fbfbfa",
|
||||
},
|
||||
{
|
||||
description: "An ordinary panel, card, table, or dialog body sitting on the page.",
|
||||
label: "Surface background",
|
||||
name: "background.surface",
|
||||
value: "#ffffff",
|
||||
},
|
||||
{
|
||||
description: "A surface deliberately lifted above an ordinary surface, such as a popover.",
|
||||
label: "Raised surface background",
|
||||
name: "background.raised",
|
||||
value: "#ffffff",
|
||||
},
|
||||
{
|
||||
description: "The scrim drawn behind a modal dialog to separate it from the page beneath.",
|
||||
label: "Overlay background",
|
||||
name: "background.overlay",
|
||||
value: "rgba(23, 23, 21, 0.55)",
|
||||
},
|
||||
{
|
||||
description: "A recessed area such as a text input, a code block, or a well.",
|
||||
label: "Inset background",
|
||||
name: "background.inset",
|
||||
value: "#f2f2f0",
|
||||
},
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Text.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
{
|
||||
description: "Body copy and headings — the default foreground for readable content.",
|
||||
label: "Primary text",
|
||||
name: "text.primary",
|
||||
value: "#1c1917",
|
||||
},
|
||||
{
|
||||
description: "Supporting text that is still content: captions, secondary columns, help text.",
|
||||
label: "Secondary text",
|
||||
name: "text.secondary",
|
||||
value: "#57534e",
|
||||
},
|
||||
{
|
||||
description: "De-emphasised text such as placeholders, timestamps, and disabled labels.",
|
||||
label: "Muted text",
|
||||
name: "text.muted",
|
||||
value: "#79716b",
|
||||
},
|
||||
{
|
||||
description: "Text drawn on a strongly coloured background, such as a primary button.",
|
||||
label: "Inverse text",
|
||||
name: "text.inverse",
|
||||
value: "#ffffff",
|
||||
},
|
||||
{
|
||||
description: "Text reporting a successful outcome, paired with the success symbol.",
|
||||
label: "Success text",
|
||||
name: "text.success",
|
||||
value: "#166534",
|
||||
},
|
||||
{
|
||||
description: "Text reporting a caution or a degraded state, paired with the warning symbol.",
|
||||
label: "Warning text",
|
||||
name: "text.warning",
|
||||
value: "#854d0e",
|
||||
},
|
||||
{
|
||||
description: "Text reporting a failure or a destructive consequence, paired with its symbol.",
|
||||
label: "Danger text",
|
||||
name: "text.danger",
|
||||
value: "#9f1239",
|
||||
},
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Accent and interactive states.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
{
|
||||
description: "The primary action colour: primary buttons, selected tabs, active links.",
|
||||
label: "Accent",
|
||||
name: "accent.base",
|
||||
value: "#1d4ed8",
|
||||
},
|
||||
{
|
||||
description: "A deeper accent for pressed primary actions and high-emphasis emphasis.",
|
||||
label: "Strong accent",
|
||||
name: "accent.strong",
|
||||
value: "#1e3a8a",
|
||||
},
|
||||
{
|
||||
description: "A faint accent wash for selected rows and subtle accent backgrounds.",
|
||||
label: "Subtle accent",
|
||||
name: "accent.subtle",
|
||||
value: "#e8effc",
|
||||
},
|
||||
{
|
||||
description: "Foreground drawn on top of the accent background.",
|
||||
label: "Accent foreground",
|
||||
name: "accent.foreground",
|
||||
value: "#ffffff",
|
||||
},
|
||||
{
|
||||
description: "The focus ring colour. Never the only signal that something has focus.",
|
||||
label: "Focus ring",
|
||||
name: "accent.focus",
|
||||
value: "#1d4ed8",
|
||||
},
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Borders.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
{
|
||||
description: "The default border around panels, inputs, and table cells.",
|
||||
label: "Border",
|
||||
name: "border.base",
|
||||
value: "#d7d3d0",
|
||||
},
|
||||
{
|
||||
description: "A heavier border for emphasis, active inputs, and selected outlines.",
|
||||
label: "Strong border",
|
||||
name: "border.strong",
|
||||
value: "#a8a29e",
|
||||
},
|
||||
{
|
||||
description: "A hairline rule separating rows or sections inside one surface.",
|
||||
label: "Divider",
|
||||
name: "border.divider",
|
||||
value: "#e7e5e4",
|
||||
},
|
||||
{
|
||||
description: "The border width used by controls and panels.",
|
||||
label: "Border width",
|
||||
name: "border.width",
|
||||
value: "1px",
|
||||
},
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Status families. Each carries a symbol so meaning never depends on colour.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
{
|
||||
description: "Background of a success badge, banner, or row highlight.",
|
||||
label: "Success background",
|
||||
name: "status.success-background",
|
||||
value: "#dcfce7",
|
||||
},
|
||||
{
|
||||
description: "Border of a success badge or banner.",
|
||||
label: "Success border",
|
||||
name: "status.success-border",
|
||||
value: "#86efac",
|
||||
},
|
||||
{
|
||||
description: "The non-colour signal for success, rendered beside the label.",
|
||||
label: "Success symbol",
|
||||
name: "status.success-symbol",
|
||||
value: '"✓"',
|
||||
},
|
||||
{
|
||||
description: "Background of a warning badge, banner, or row highlight.",
|
||||
label: "Warning background",
|
||||
name: "status.warning-background",
|
||||
value: "#fef3c7",
|
||||
},
|
||||
{
|
||||
description: "Border of a warning badge or banner.",
|
||||
label: "Warning border",
|
||||
name: "status.warning-border",
|
||||
value: "#fcd34d",
|
||||
},
|
||||
{
|
||||
description: "The non-colour signal for a warning, rendered beside the label.",
|
||||
label: "Warning symbol",
|
||||
name: "status.warning-symbol",
|
||||
value: '"!"',
|
||||
},
|
||||
{
|
||||
description: "Background of a danger badge, banner, or row highlight.",
|
||||
label: "Danger background",
|
||||
name: "status.danger-background",
|
||||
value: "#ffe4e6",
|
||||
},
|
||||
{
|
||||
description: "Border of a danger badge or banner.",
|
||||
label: "Danger border",
|
||||
name: "status.danger-border",
|
||||
value: "#fda4af",
|
||||
},
|
||||
{
|
||||
description: "The non-colour signal for danger or failure, rendered beside the label.",
|
||||
label: "Danger symbol",
|
||||
name: "status.danger-symbol",
|
||||
value: '"✕"',
|
||||
},
|
||||
{
|
||||
description: "Background of a neutral informational badge or banner.",
|
||||
label: "Info background",
|
||||
name: "status.info-background",
|
||||
value: "#e8effc",
|
||||
},
|
||||
{
|
||||
description: "Border of a neutral informational badge or banner.",
|
||||
label: "Info border",
|
||||
name: "status.info-border",
|
||||
value: "#bfd3f7",
|
||||
},
|
||||
{
|
||||
description: "The non-colour signal for information, rendered beside the label.",
|
||||
label: "Info symbol",
|
||||
name: "status.info-symbol",
|
||||
value: '"i"',
|
||||
},
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Interaction states.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
{
|
||||
description: "Background wash under a hovered control or row.",
|
||||
label: "Hover background",
|
||||
name: "state.hover-background",
|
||||
value: "#f2f2f0",
|
||||
},
|
||||
{
|
||||
description: "Background wash under a control being pressed.",
|
||||
label: "Pressed background",
|
||||
name: "state.pressed-background",
|
||||
value: "#e7e5e4",
|
||||
},
|
||||
{
|
||||
description: "Background of a selected row, tab, or list item.",
|
||||
label: "Selected background",
|
||||
name: "state.selected-background",
|
||||
value: "#e8effc",
|
||||
},
|
||||
{
|
||||
description: "Foreground of a selected row, tab, or list item.",
|
||||
label: "Selected foreground",
|
||||
name: "state.selected-foreground",
|
||||
value: "#1e3a8a",
|
||||
},
|
||||
{
|
||||
description: "Opacity applied to a disabled control. Disabled state is never colour alone.",
|
||||
label: "Disabled opacity",
|
||||
name: "state.disabled-opacity",
|
||||
value: "0.55",
|
||||
},
|
||||
{
|
||||
description: "Thickness of the keyboard focus ring.",
|
||||
label: "Focus ring width",
|
||||
name: "state.focus-visible-width",
|
||||
value: "2px",
|
||||
},
|
||||
{
|
||||
description: "Gap between a focused control and its focus ring.",
|
||||
label: "Focus ring offset",
|
||||
name: "state.focus-visible-offset",
|
||||
value: "2px",
|
||||
},
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Typography.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
{
|
||||
description: "The interface font stack for all ordinary text.",
|
||||
label: "Interface font family",
|
||||
name: "typography.family-sans",
|
||||
value: "system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif",
|
||||
},
|
||||
{
|
||||
description: "The monospace stack for identifiers, keys, and code.",
|
||||
label: "Monospace font family",
|
||||
name: "typography.family-mono",
|
||||
value: "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
|
||||
},
|
||||
{
|
||||
description: "Smallest supported text size, for dense metadata only.",
|
||||
label: "Extra small font size",
|
||||
name: "typography.size-xs",
|
||||
value: "0.75rem",
|
||||
},
|
||||
{
|
||||
description: "Small text: captions, table metadata, help text.",
|
||||
label: "Small font size",
|
||||
name: "typography.size-sm",
|
||||
value: "0.875rem",
|
||||
},
|
||||
{
|
||||
description: "The default body text size.",
|
||||
label: "Body font size",
|
||||
name: "typography.size-md",
|
||||
value: "1rem",
|
||||
},
|
||||
{
|
||||
description: "Large body text and small headings.",
|
||||
label: "Large font size",
|
||||
name: "typography.size-lg",
|
||||
value: "1.125rem",
|
||||
},
|
||||
{
|
||||
description: "Third-level heading size.",
|
||||
label: "Heading 3 font size",
|
||||
name: "typography.size-heading-3",
|
||||
value: "1.25rem",
|
||||
},
|
||||
{
|
||||
description: "Second-level heading size.",
|
||||
label: "Heading 2 font size",
|
||||
name: "typography.size-heading-2",
|
||||
value: "1.5rem",
|
||||
},
|
||||
{
|
||||
description: "First-level heading size — one per screen.",
|
||||
label: "Heading 1 font size",
|
||||
name: "typography.size-heading-1",
|
||||
value: "1.875rem",
|
||||
},
|
||||
{
|
||||
description: "Normal text weight.",
|
||||
label: "Regular font weight",
|
||||
name: "typography.weight-regular",
|
||||
value: "400",
|
||||
},
|
||||
{
|
||||
description: "Weight for labels, table headers, and emphasised body text.",
|
||||
label: "Medium font weight",
|
||||
name: "typography.weight-medium",
|
||||
value: "500",
|
||||
},
|
||||
{
|
||||
description: "Weight for headings and primary actions.",
|
||||
label: "Bold font weight",
|
||||
name: "typography.weight-bold",
|
||||
value: "600",
|
||||
},
|
||||
{
|
||||
description: "Tight line height for headings and single-line controls.",
|
||||
label: "Tight line height",
|
||||
name: "typography.line-height-tight",
|
||||
value: "1.2",
|
||||
},
|
||||
{
|
||||
description: "Default line height for body copy.",
|
||||
label: "Normal line height",
|
||||
name: "typography.line-height-normal",
|
||||
value: "1.5",
|
||||
},
|
||||
{
|
||||
description: "Relaxed line height for long-form reading.",
|
||||
label: "Relaxed line height",
|
||||
name: "typography.line-height-relaxed",
|
||||
value: "1.7",
|
||||
},
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Spacing scale.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
{
|
||||
description: "No space. Named so a component never hardcodes a bare zero.",
|
||||
label: "No spacing",
|
||||
name: "spacing.none",
|
||||
value: "0",
|
||||
},
|
||||
{
|
||||
description: "Hairline spacing between tightly related inline elements.",
|
||||
label: "Extra extra small spacing",
|
||||
name: "spacing.2xs",
|
||||
value: "0.125rem",
|
||||
},
|
||||
{
|
||||
description: "Spacing inside a compact control.",
|
||||
label: "Extra small spacing",
|
||||
name: "spacing.xs",
|
||||
value: "0.25rem",
|
||||
},
|
||||
{
|
||||
description: "Spacing between a label and its field.",
|
||||
label: "Small spacing",
|
||||
name: "spacing.sm",
|
||||
value: "0.5rem",
|
||||
},
|
||||
{
|
||||
description: "The default gap between related elements.",
|
||||
label: "Medium spacing",
|
||||
name: "spacing.md",
|
||||
value: "0.75rem",
|
||||
},
|
||||
{
|
||||
description: "Padding inside a panel or dialog.",
|
||||
label: "Large spacing",
|
||||
name: "spacing.lg",
|
||||
value: "1rem",
|
||||
},
|
||||
{
|
||||
description: "Spacing between sections of one screen.",
|
||||
label: "Extra large spacing",
|
||||
name: "spacing.xl",
|
||||
value: "1.5rem",
|
||||
},
|
||||
{
|
||||
description: "Spacing between major regions of a page.",
|
||||
label: "Extra extra large spacing",
|
||||
name: "spacing.2xl",
|
||||
value: "2.5rem",
|
||||
},
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Radii and shadows.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
{
|
||||
description: "Square corners.",
|
||||
label: "No radius",
|
||||
name: "radius.none",
|
||||
value: "0",
|
||||
},
|
||||
{
|
||||
description: "Corner radius for badges and small inline elements.",
|
||||
label: "Small radius",
|
||||
name: "radius.sm",
|
||||
value: "0.25rem",
|
||||
},
|
||||
{
|
||||
description: "Corner radius for controls, inputs, and buttons.",
|
||||
label: "Medium radius",
|
||||
name: "radius.md",
|
||||
value: "0.375rem",
|
||||
},
|
||||
{
|
||||
description: "Corner radius for panels and dialogs.",
|
||||
label: "Large radius",
|
||||
name: "radius.lg",
|
||||
value: "0.75rem",
|
||||
},
|
||||
{
|
||||
description: "Fully rounded ends, for pills and status dots.",
|
||||
label: "Pill radius",
|
||||
name: "radius.pill",
|
||||
value: "9999px",
|
||||
},
|
||||
{
|
||||
description: "No shadow.",
|
||||
label: "No shadow",
|
||||
name: "shadow.none",
|
||||
value: "none",
|
||||
},
|
||||
{
|
||||
description: "Subtle lift for a resting panel.",
|
||||
label: "Small shadow",
|
||||
name: "shadow.sm",
|
||||
value: "0 1px 2px rgba(23, 23, 21, 0.08)",
|
||||
},
|
||||
{
|
||||
description: "Shadow for a popover or a raised surface.",
|
||||
label: "Medium shadow",
|
||||
name: "shadow.md",
|
||||
value: "0 4px 12px rgba(23, 23, 21, 0.12)",
|
||||
},
|
||||
{
|
||||
description: "Shadow for a modal dialog.",
|
||||
label: "Large shadow",
|
||||
name: "shadow.lg",
|
||||
value: "0 16px 40px rgba(23, 23, 21, 0.22)",
|
||||
},
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Control sizing.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
{
|
||||
description: "Height of a compact control.",
|
||||
label: "Small control height",
|
||||
name: "control.height-sm",
|
||||
value: "1.75rem",
|
||||
},
|
||||
{
|
||||
description: "Height of an ordinary button, input, or select.",
|
||||
label: "Medium control height",
|
||||
name: "control.height-md",
|
||||
value: "2.25rem",
|
||||
},
|
||||
{
|
||||
description: "Height of a prominent primary control.",
|
||||
label: "Large control height",
|
||||
name: "control.height-lg",
|
||||
value: "2.75rem",
|
||||
},
|
||||
{
|
||||
description: "Horizontal padding inside a control.",
|
||||
label: "Control padding",
|
||||
name: "control.padding-inline",
|
||||
value: "0.75rem",
|
||||
},
|
||||
] as const satisfies readonly DesignTokenInput[];
|
||||
|
||||
/** Every registered token name, as a union — the compile-time half of "modules consume registered
|
||||
* tokens and never invent new global theme variables". */
|
||||
export type EkklesiaDesignTokenName = (typeof declarations)[number]["name"];
|
||||
|
||||
/**
|
||||
* The one global semantic token registry. Built (and therefore validated) at module evaluation, so
|
||||
* an invalid declaration fails where it was written rather than in a browser.
|
||||
*/
|
||||
export const ekklesiaDesignTokens = createDesignTokenRegistry(declarations);
|
||||
|
||||
/** `var(--ekklesia-…)` for a registered token. The typed reference component and module code use;
|
||||
* an unregistered name is a compile error, and also a runtime `DesignTokenError`. */
|
||||
export function designToken(name: EkklesiaDesignTokenName): string {
|
||||
return ekklesiaDesignTokens.reference(name);
|
||||
}
|
||||
|
||||
/** The complete default theme as one installable CSS rule. */
|
||||
export function ekklesiaDesignTokenStylesheet(scope: DesignTokenScope = "root"): string {
|
||||
return ekklesiaDesignTokens.stylesheet(scope);
|
||||
}
|
||||
Reference in New Issue
Block a user