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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 4.5
parent
47bc87692d
commit
26ac37b1df
@@ -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<string, string> = {
|
||||
// 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();
|
||||
}
|
||||
Reference in New Issue
Block a user