Format product color labels

This commit is contained in:
Cauê Faleiros
2026-07-09 13:58:48 -03:00
parent 634cf4db48
commit d3d8886a90
7 changed files with 57 additions and 33 deletions

26
src/productColors.ts Normal file
View File

@@ -0,0 +1,26 @@
const COLOR_SWATCHES: Array<{ pattern: string; color: string }> = [
{ pattern: 'preto', color: '#171717' },
{ pattern: 'branco', color: '#f8fafc' },
{ pattern: 'bege', color: '#d7bf9a' },
{ pattern: 'cafe', color: '#79553d' },
{ pattern: 'perola', color: '#e7dfcf' },
{ pattern: 'marinho', color: '#172554' },
{ pattern: 'bordo', color: '#6b1226' },
{ pattern: 'verde', color: '#166534' },
{ pattern: 'rosa', color: '#f0a6bf' },
{ pattern: 'cinza', color: '#8f8f8f' },
{ pattern: 'vermelho', color: '#b91c1c' },
{ pattern: 'grafite', color: '#3f3f46' },
{ pattern: 'azul', color: '#2563eb' },
{ pattern: 'marron', color: '#6b4f3b' },
{ pattern: 'marrom', color: '#6b4f3b' }
];
const normalizeColorLabel = (label: string) => (
label.normalize('NFD').replace(/\p{Diacritic}/gu, '').toLowerCase()
);
export const getProductColor = (label: string) => {
const normalizedLabel = normalizeColorLabel(label);
return COLOR_SWATCHES.find(item => normalizedLabel.includes(item.pattern))?.color || '#64748b';
};