From 767290e1b5e1d3aaeda84639c97c106c95ef45d4 Mon Sep 17 00:00:00 2001 From: Philipp Traber Date: Wed, 14 Oct 2026 16:56:27 +0200 Subject: [PATCH] Replace the palette dark/light toggle with per-palette thumbnails The global "Dark background / Light background" switch sat in the trending header but also affected saved palettes and meant nothing for single colors. Each palette now shows two small page thumbnails (dark and light version) that apply exactly what they show; the selected one is highlighted, and editing a single color deselects it. Co-Authored-By: Claude Opus 5.5 --- src/web/screens/detail/ThemePicker.tsx | 106 +++++++++++++------------ 1 file changed, 57 insertions(+), 49 deletions(-) diff --git a/src/web/screens/detail/ThemePicker.tsx b/src/web/screens/detail/ThemePicker.tsx index 7883258..4683b19 100644 --- a/src/web/screens/detail/ThemePicker.tsx +++ b/src/web/screens/detail/ThemePicker.tsx @@ -5,7 +5,7 @@ import type { Theme } from "../../../shared/validation.js"; import { api, errorMessage, useApi } from "../../api.js"; import { Button } from "../../components/ui/button.js"; import { useConfirm } from "../../components/ui/dialog.js"; -import { ColorInput, Input, Segmented } from "../../components/ui/form.js"; +import { ColorInput, Input } from "../../components/ui/form.js"; import { useToast } from "../../components/ui/toast.js"; import { cx } from "../../lib/cx.js"; import { parseCoolorsInput, themeFromPalette, TRENDING_PALETTES, type Variant } from "../../lib/palette.js"; @@ -59,7 +59,29 @@ function PresetCard({ name, theme, selected, onClick }: { name: string; theme: T ); } -// A palette: each color opens the role menu, the name row applies the whole palette. +// Miniature of a link page (background, a text line and a button) that applies one version of a palette. +function VariantThumb({ theme, label, selected, onClick }: { theme: Theme; label: string; selected: boolean; onClick: () => void }) { + return ( + + ); +} + +// A palette: each color opens the role menu, the two thumbnails apply a dark or light version of it. function PaletteCard({ colors, label, @@ -70,14 +92,14 @@ function PaletteCard({ }: { colors: string[]; label: string; - selected: boolean; - onApply: () => void; + selected: Variant | null; + onApply: (variant: Variant) => void; onPickColor: (color: string, anchor: HTMLElement) => void; onRemove?: () => void; }) { return ( -
-
+
+
{colors.map((c, i) => (
-
- +
+ {label} + {(["dark", "light"] as const).map((v) => ( + onApply(v)} + /> + ))} {onRemove && ( @@ -222,9 +245,8 @@ export function ThemePicker({ theme, onChange }: { theme: Theme; onChange: (them const saved = useApi("/palettes"); const toast = useToast(); const confirm = useConfirm(); - const [variant, setVariant] = useState("dark"); - // The palette the current theme was generated from, so switching dark/light can re-map it. - const [source, setSource] = useState(null); + // The palette version the current theme was generated from, to mark it as selected. + const [source, setSource] = useState<{ colors: string[]; variant: Variant } | null>(null); const [link, setLink] = useState(""); const [linkError, setLinkError] = useState(); const [importing, setImporting] = useState(false); @@ -232,21 +254,20 @@ export function ThemePicker({ theme, onChange }: { theme: Theme; onChange: (them const toggleMenu = (color: string, anchor: HTMLElement) => setMenu((m) => (m?.anchor === anchor ? null : { color, anchor })); - const applyPalette = (colors: string[], v = variant) => { - setSource(colors); - onChange(themeFromPalette(colors, v)); - }; - const changeVariant = (v: Variant) => { - setVariant(v); - if (source) onChange(themeFromPalette(source, v)); + const applyPalette = (colors: string[], variant: Variant) => { + setSource({ colors, variant }); + onChange(themeFromPalette(colors, variant)); }; const setColor = (role: keyof Theme, color: string) => { setSource(null); onChange({ ...theme, [role]: color }); }; - const isSelected = (colors: string[]) => - !!source && paletteKey(source) === paletteKey(colors) && sameTheme(themeFromPalette(colors, variant), theme); + // Which version of this palette is in use, if any (editing a single color deselects it). + const selectedVariant = (colors: string[]): Variant | null => + source && paletteKey(source.colors) === paletteKey(colors) && sameTheme(themeFromPalette(colors, source.variant), theme) + ? source.variant + : null; const importLink = async () => { const colors = parseCoolorsInput(link); @@ -258,7 +279,7 @@ export function ThemePicker({ theme, onChange }: { theme: Theme; onChange: (them try { await api("POST", "/palettes", { colors }); await saved.reload(); - applyPalette(colors); + applyPalette(colors, "dark"); setLink(""); setLinkError(undefined); } catch (err) { @@ -280,7 +301,7 @@ export function ThemePicker({ theme, onChange }: { theme: Theme; onChange: (them } }; - const pickHint = "Click a name to use the whole palette, or a single color to assign it."; + const pickHint = "Pick the dark or light version of a palette, or click a single color to use it for one part."; return (
@@ -303,20 +324,7 @@ export function ThemePicker({ theme, onChange }: { theme: Theme; onChange: (them
- - } - > + Trending on{" "} coolors.co @@ -328,8 +336,8 @@ export function ThemePicker({ theme, onChange }: { theme: Theme; onChange: (them key={p.name} label={p.name} colors={p.colors} - selected={isSelected(p.colors)} - onApply={() => applyPalette(p.colors)} + selected={selectedVariant(p.colors)} + onApply={(v) => applyPalette(p.colors, v)} onPickColor={toggleMenu} /> ))} @@ -376,8 +384,8 @@ export function ThemePicker({ theme, onChange }: { theme: Theme; onChange: (them key={p.id} label={`Imported ${new Date(p.createdAt).toLocaleDateString(undefined, { month: "short", day: "numeric" })}`} colors={p.colors} - selected={isSelected(p.colors)} - onApply={() => applyPalette(p.colors)} + selected={selectedVariant(p.colors)} + onApply={(v) => applyPalette(p.colors, v)} onPickColor={toggleMenu} onRemove={() => void removePalette(p)} />