Shipyard theme-picker
Latest: v1.0.0
Shipyard v0.10.3
Shipyard theme picker
Part of the Shipyard plugin. It needs the full plugin installed (https://github.com/philipposk/shipyard/blob/main/INSTALL.md): its scripts and key guard do not work on their own.
Read ${CLAUDE_PLUGIN_ROOT}/skills/new-app/references/working-rules.md now, before any other step, and follow it. The rules below only add to it.
1. Make every colour a CSS variable first
Before any picker, the app's CSS must read colours only from variables (--bg, --surface, --text, --accent, --inverse/--on-inverse for buttons, plus derived --subtle, --raised, --line, --muted). Search for hard-coded hex values and replace them. A picker over a half-variabled app looks broken.
2. Store a small, validated theme object
{ preset, accent, colors: { light: {bg, surface, text, button}, dark: {...} } }. Accept only #rrggbb (sanitize on read and on write; drop anything else). Save it with the user (for example Supabase user_metadata.custom_theme), not only in localStorage, so it follows them across devices.
3. Derive the rest, don't ask for it
Users pick 5 colours; compute the in-between tones with a colour mix (for example raised = mix(surface, text, 4%), line = mix(surface, text, 12%), muted = mix(text, bg, 40%)). Pick the readable text on a button by luminance. Warn (don't block) when contrast is below 4.5:1 for text and 3:1 for buttons.
4. Render it on the server, scoped tightly
Emit a <style> in the root layout from the saved theme, scoped like :root[data-ct][data-style][data-theme=dark] { ... } so it beats the presets on specificity and can never leak into other modes. Server rendering means no flash of the default theme. Live preview while editing just rewrites that style tag on the client.
5. The picker itself (about 150 lines, no library)
- Saturation/value square:
background-color: hsl(hue 100% 50%)with two gradient overlays (white→transparent left-to-right, transparent→black top-to-bottom). UsebackgroundColor, not thebackgroundshorthand, or React wipes the gradients. - Hue slider: a rainbow gradient strip.
- Hex input: commits on valid
#rrggbbonly. - Pointer drag with
setPointerCaptureone.currentTarget; arrow keys move 1% (Shift 10%); each control isrole="slider"with aria values. - Keep HSV in local state so the hue doesn't jump when saturation hits 0; resync from the prop with the "adjust state while rendering" pattern, not an effect.
6. Editor layout (phone first)
Presets on top. Below: "Exact colours" with a Light/Dark switch, one row per slot (swatch, name, hex, Clear), and the picker opening under the tapped row. Clear falls back to the preset value. Test at 390x844.
7. Check
Unit-test sanitize, HSV round trip and the generated CSS. Screenshot light and dark with a garish pick (yellow buttons) to catch any hard-coded colour that didn't follow.
