@@ -12,6 +12,11 @@ interface Product {
1212 name : string ;
1313 } [ ] ;
1414 } ;
15+ allPaColors ?: {
16+ nodes : {
17+ name : string ;
18+ } [ ] ;
19+ } ;
1520}
1621
1722interface ProductFiltersProps {
@@ -43,14 +48,27 @@ const ProductFilters = ({
4348 product . allPaSizes ?. nodes . map ( ( node : { name : string } ) => node . name ) || [ ]
4449 )
4550 ) ) . sort ( ) as string [ ] ;
46- const colors = [
47- { name : 'Svart' , class : 'bg-black' } ,
48- { name : 'Brun' , class : 'bg-brown-500' } ,
49- { name : 'Beige' , class : 'bg-[#D2B48C]' } ,
50- { name : 'Grå' , class : 'bg-gray-500' } ,
51- { name : 'Hvit' , class : 'bg-white border border-gray-300' } ,
52- { name : 'Blå' , class : 'bg-blue-500' }
53- ] ;
51+ // Get unique colors from all products
52+ const availableColors = Array . from ( new Set (
53+ products . flatMap ( ( product : Product ) =>
54+ product . allPaColors ?. nodes . map ( ( node : { name : string } ) => node . name ) || [ ]
55+ )
56+ ) ) . sort ( ) as string [ ] ;
57+
58+ // Map color names to their CSS classes
59+ const colorMap : { [ key : string ] : string } = {
60+ 'Svart' : 'bg-black' ,
61+ 'Brun' : 'bg-brown-500' ,
62+ 'Beige' : 'bg-[#D2B48C]' ,
63+ 'Grå' : 'bg-gray-500' ,
64+ 'Hvit' : 'bg-white border border-gray-300' ,
65+ 'Blå' : 'bg-blue-500'
66+ } ;
67+
68+ const colors = availableColors . map ( colorName => ( {
69+ name : colorName ,
70+ class : colorMap [ colorName ] || 'bg-gray-300' // Fallback color if not in map
71+ } ) ) ;
5472
5573 const toggleSize = ( size : string ) => {
5674 setSelectedSizes ( prev =>
0 commit comments