From 26ac37b1df9e815b79d56bb09fc2e948a8ceb493 Mon Sep 17 00:00:00 2001 From: Andymick Date: Fri, 17 Jul 2026 20:08:56 +0100 Subject: [PATCH] Replace hex color codes with friendly color names for customers - Add colorNames utility with 80+ standard color names - Map hex codes to human-readable names (Black, Navy, Red, Teal, etc) - Display color names in product page (with hex tooltip for reference) - Show selected color name below color swatches - Update shopping cart to display color names instead of hex codes - Admin color picker shows both name and hex code for clarity Improves UX for customers who don't understand hex color codes. Keeps hex codes for internal data and system tooltips. Co-Authored-By: Claude Haiku 4.5 --- src/app/cart/page.tsx | 4 +- src/components/ColorPicker.tsx | 12 ++- src/components/StandardProductView.tsx | 33 ++++--- src/lib/colorNames.ts | 132 +++++++++++++++++++++++++ 4 files changed, 166 insertions(+), 15 deletions(-) create mode 100644 src/lib/colorNames.ts diff --git a/src/app/cart/page.tsx b/src/app/cart/page.tsx index f8d07f9..dc0869a 100644 --- a/src/app/cart/page.tsx +++ b/src/app/cart/page.tsx @@ -3,6 +3,7 @@ import { useEffect, useState } from 'react'; import Link from 'next/link'; import { useCart } from '@/lib/cartStore'; +import { getColorName } from '@/lib/colorNames'; import Price from '@/components/Price'; export default function CartPage() { @@ -70,8 +71,9 @@ export default function CartPage() { - {item.color} + {getColorName(item.color)} {item.size && Size {item.size}} diff --git a/src/components/ColorPicker.tsx b/src/components/ColorPicker.tsx index 89dd0c7..63d80a4 100644 --- a/src/components/ColorPicker.tsx +++ b/src/components/ColorPicker.tsx @@ -1,6 +1,7 @@ 'use client'; import { useEffect, useRef, useState } from 'react'; +import { getColorName } from '@/lib/colorNames'; function frontFieldName(hex: string) { return `colorPhoto__${hex.replace('#', '')}`; @@ -203,6 +204,7 @@ export default function ColorPicker({
{r.hex} + ({getColorName(r.hex)}) {r.filename} {r.variant}
@@ -238,7 +240,10 @@ export default function ColorPicker({ onChange={(e) => setPicked(e.target.value)} className="h-9 w-9 cursor-pointer border border-line bg-paper p-0" /> - {picked} +
+ {getColorName(picked)} + {picked} +
+ {color && ( +

+ Selected: {getColorName(color)} +

+ )} {product.imageUrl && !product.photoRecolorable && Object.keys(product.colorPhotos).length === 0 && (

diff --git a/src/lib/colorNames.ts b/src/lib/colorNames.ts new file mode 100644 index 0000000..d3d3982 --- /dev/null +++ b/src/lib/colorNames.ts @@ -0,0 +1,132 @@ +/** + * Convert hex color codes to friendly color names + * Customers see names, admins/data uses hex codes internally + */ + +const COLOR_NAMES: Record = { + // Neutrals + '#000000': 'Black', + '#1a1a1a': 'Charcoal', + '#333333': 'Dark Gray', + '#4d4d4d': 'Gray', + '#666666': 'Medium Gray', + '#808080': 'Light Gray', + '#999999': 'Silver', + '#b3b3b3': 'Pale Gray', + '#cccccc': 'Very Light Gray', + '#e6e6e6': 'Off-White', + '#ffffff': 'White', + + // Reds & Pinks + '#cc0000': 'Red', + '#ff0000': 'Bright Red', + '#ff3333': 'Light Red', + '#ff6666': 'Coral', + '#ff9999': 'Salmon', + '#ffcccc': 'Pink', + '#ff69b4': 'Hot Pink', + '#ff1493': 'Deep Pink', + '#c71585': 'Crimson', + '#8b0000': 'Dark Red', + + // Oranges & Browns + '#ff6600': 'Orange', + '#ff8c00': 'Dark Orange', + '#ffaa00': 'Burnt Orange', + '#ff9900': 'Apricot', + '#ffbb99': 'Peach', + '#cc6600': 'Rust', + '#996633': 'Brown', + '#8b4513': 'Saddle Brown', + '#a0522d': 'Sienna', + '#d2691e': 'Chocolate', + + // Yellows & Golds + '#ffff00': 'Yellow', + '#ffff99': 'Light Yellow', + '#ffcc00': 'Gold', + '#ffd700': 'Bright Gold', + '#f0e68c': 'Khaki', + '#f4a460': 'Sandy Brown', + '#daa520': 'Goldenrod', + + // Greens + '#00aa00': 'Green', + '#00cc00': 'Lime', + '#66ff66': 'Light Green', + '#99ff99': 'Pale Green', + '#33cc33': 'Kelly Green', + '#228b22': 'Forest Green', + '#006600': 'Dark Green', + '#355c3d': 'Hunter Green', + '#2f4f2f': 'Dark Forest Green', + '#3cb371': 'Medium Sea Green', + '#20b2aa': 'Light Sea Green', + '#008080': 'Teal', + '#006666': 'Dark Teal', + + // Blues + '#0066ff': 'Blue', + '#0099cc': 'Sky Blue', + '#00ccff': 'Cyan', + '#3399ff': 'Light Blue', + '#6699ff': 'Periwinkle', + '#9999ff': 'Lavender Blue', + '#1e90ff': 'Dodger Blue', + '#4169e1': 'Royal Blue', + '#00008b': 'Dark Blue', + '#000080': 'Navy', + '#191970': 'Midnight Blue', + + // Purples & Violets + '#9933ff': 'Purple', + '#cc00ff': 'Magenta', + '#ff00ff': 'Fuchsia', + '#ee82ee': 'Violet', + '#9370db': 'Medium Purple', + '#8b008b': 'Dark Magenta', + '#4b0082': 'Indigo', + '#663399': 'Rebecca Purple', + + // Common craft colors + '#17181c': 'Graphite', + '#1ea7e0': 'Turquoise', + '#fbe9e7': 'Blush', + '#f5f5f5': 'Smoke', +}; + +/** + * Get the friendly name for a hex color + * Falls back to "Custom" if hex code is not in the standard palette + */ +export function getColorName(hex: string): string { + const normalized = hex.toLowerCase(); + return COLOR_NAMES[normalized] || 'Custom'; +} + +/** + * Get the hex code from a color name + * Used for reverse lookup if needed + */ +export function getColorHex(name: string): string | null { + for (const [hex, colorName] of Object.entries(COLOR_NAMES)) { + if (colorName.toLowerCase() === name.toLowerCase()) { + return hex; + } + } + return null; +} + +/** + * Check if a hex code is in our standard palette + */ +export function isStandardColor(hex: string): boolean { + return hex.toLowerCase() in COLOR_NAMES; +} + +/** + * Get all available standard color names + */ +export function getAllColorNames(): string[] { + return Object.values(COLOR_NAMES).sort(); +}