Let superadmins change the whole colour palette
Panel -> Site settings -> Colours: any colour token, with a light and a dark value (migration 041). The server writes the overrides into each page's head in the same cascade layers as index.css, so a light-only change leaves dark mode alone. Values must be #rrggbb (a table CHECK), and saving refuses a palette that puts any text under 4.5:1 in either mode, through a new descriptor hook, check(db, id), run inside the save's transaction. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a225e84408
commit
f1edaaf92a
9 changed files with 258 additions and 4 deletions
|
|
@ -125,6 +125,14 @@ const inputLocked =
|
|||
|
||||
/* ── Dotted paths ────────────────────────────────────────────── */
|
||||
|
||||
/* What an empty colour field shows in its swatch and placeholder:
|
||||
the field's own default (a value, or one worked out from the row),
|
||||
else the brand teal. */
|
||||
function colorPlaceholder(field, row): string {
|
||||
const own = typeof field.placeholder === "function" ? field.placeholder(row) : field.placeholder;
|
||||
return own || "#138ba0";
|
||||
}
|
||||
|
||||
export function getPath(object, path) {
|
||||
// An entity with no slug has no heading path either, and a missing
|
||||
// path should read as "no value" rather than throwing on .split.
|
||||
|
|
@ -274,7 +282,7 @@ export function Field({ field, value, row, options, error, onChange, onPatch }:
|
|||
<div className="flex gap-2">
|
||||
<input
|
||||
type="color"
|
||||
value={/^#[0-9a-f]{6}$/i.test(value ?? "") ? value : "#138ba0"}
|
||||
value={/^#[0-9a-f]{6}$/i.test(value ?? "") ? value : colorPlaceholder(field, row)}
|
||||
disabled={locked}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
className="h-9 w-12 shrink-0 rounded border border-muted/25 bg-surface disabled:opacity-50"
|
||||
|
|
@ -282,7 +290,7 @@ export function Field({ field, value, row, options, error, onChange, onPatch }:
|
|||
<input
|
||||
{...common}
|
||||
readOnly={locked}
|
||||
placeholder="#138ba0"
|
||||
placeholder={colorPlaceholder(field, row)}
|
||||
className={locked ? inputLocked : common.className}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -8,6 +8,29 @@ const SITE_PAGES: [string, string][] = Object.entries(siteConfiguration.pages).m
|
|||
([path, page]) => [path, `${page.title} (${path})`],
|
||||
);
|
||||
|
||||
/* The palette an admin can change: token, label, light default, dark
|
||||
default. Keep in step with THEME_DEFAULTS in server/src/theme.js
|
||||
and the tokens in src/index.css. */
|
||||
const THEME_COLORS: [string, string, string, string][] = [
|
||||
["ink", "Headings", "#073d4a", "#eaf6f8"],
|
||||
["body", "Body text", "#26454c", "#cde0e4"],
|
||||
["muted", "Secondary text and quiet borders", "#4a6b72", "#9fb9bf"],
|
||||
["link", "Links and teal text", "#0f7183", "#5ccbdc"],
|
||||
["brand", "Brand teal (borders, rules, rings)", "#138ba0", "#2aa7bc"],
|
||||
["action", "Buttons (under white text)", "#0f7183", "#0f7183"],
|
||||
["action-hover", "Buttons, hovered", "#0b5c6a", "#0b5c6a"],
|
||||
["surface", "Page and card background", "#ffffff", "#0c1d21"],
|
||||
["tint", "Tinted sections and panels", "#eef9fb", "#11292e"],
|
||||
["tint-soft", "Faint panels and hovered rows", "#f6fbfc", "#0f2428"],
|
||||
["danger", "Errors and warnings", "#b3261e", "#ff8a80"],
|
||||
["danger-tint", "Error panel background", "#fdf3f2", "#3b1714"],
|
||||
];
|
||||
|
||||
const defaultHelp = (row, column: 2 | 3) => {
|
||||
const entry = THEME_COLORS.find(([token]) => token === row?.token);
|
||||
return entry ? `Default: ${entry[column]}` : undefined;
|
||||
};
|
||||
|
||||
export const siteSettings = {
|
||||
key: "site_settings",
|
||||
label: "Site settings",
|
||||
|
|
@ -93,6 +116,37 @@ export const siteSettings = {
|
|||
],
|
||||
|
||||
children: [
|
||||
{
|
||||
key: "colors",
|
||||
label: "Colours",
|
||||
note: "Change any of the site's colours, for light mode, dark mode or both; a blank keeps the default. Saving refuses a palette that would make text hard to read (under 4.5:1). Changes show on the next page load.",
|
||||
addLabel: "Change a colour",
|
||||
title: (row) => THEME_COLORS.find(([token]) => token === row.token)?.[1] ?? "New colour",
|
||||
blank: { token: "", light: "", dark: "" },
|
||||
fields: [
|
||||
{
|
||||
path: "token",
|
||||
label: "Colour",
|
||||
widget: "select",
|
||||
options: THEME_COLORS.map(([token, label]) => [token, label]),
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
path: "light",
|
||||
label: "Light mode",
|
||||
widget: "color",
|
||||
placeholder: (row) => THEME_COLORS.find(([token]) => token === row?.token)?.[2],
|
||||
help: (row) => defaultHelp(row, 2),
|
||||
},
|
||||
{
|
||||
path: "dark",
|
||||
label: "Dark mode",
|
||||
widget: "color",
|
||||
placeholder: (row) => THEME_COLORS.find(([token]) => token === row?.token)?.[3],
|
||||
help: (row) => defaultHelp(row, 3),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: "pages",
|
||||
label: "Page titles and intros",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue