Format product color labels
This commit is contained in:
26
src/productColors.ts
Normal file
26
src/productColors.ts
Normal 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';
|
||||
};
|
||||
Reference in New Issue
Block a user