adriano2005 commited on
Commit
4913488
·
verified ·
1 Parent(s): b18d247

Create ProductCard.tsx

Browse files
Files changed (1) hide show
  1. ProductCard.tsx +47 -0
ProductCard.tsx ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // src/components/ProductCard.tsx
2
+
3
+ import { Product } from '@/lib/schemas'; // Importa o tipo Zod
4
+ import { useCartStore } from '@/stores/useCartStore'; // Importa a "Bandeja do Cliente" (Zustand)
5
+
6
+ interface ProductCardProps {
7
+ product: Product;
8
+ }
9
+
10
+ export const ProductCard = ({ product }: ProductCardProps) => {
11
+ // 1. Acessamos a função 'addItem' da store Zustand.
12
+ const addItemToCart = useCartStore((state) => state.addItem);
13
+
14
+ // 2. ♿ [A11y STRICT]: Acessibilidade e Semântica
15
+ // O componente deve ser um link para a página de detalhes (se tivéssemos uma)
16
+ // mas o botão de compra precisa ser claro para leitores de tela.
17
+ const handleAddToCart = () => {
18
+ addItemToCart(product);
19
+ // TODO: Adicionar um feedback visual (toast) aqui para o usuário.
20
+ };
21
+
22
+ return (
23
+ <div className="border rounded-lg shadow-md overflow-hidden flex flex-col justify-between p-4 bg-white">
24
+ <div className="flex justify-center h-48 mb-4">
25
+ <img
26
+ src={product.image}
27
+ alt={product.title}
28
+ className="object-contain w-full h-full"
29
+ loading="lazy" // Otimização para LCP
30
+ />
31
+ </div>
32
+ <div className="flex-grow">
33
+ <h2 className="text-lg font-semibold h-12 overflow-hidden mb-2">{product.title}</h2>
34
+ <p className="text-xl font-bold text-gray-800 mb-2">R$ {product.price.toFixed(2)}</p>
35
+ <p className="text-sm text-gray-600 line-clamp-3 mb-4">{product.description}</p>
36
+ </div>
37
+ <button
38
+ onClick={handleAddToCart}
39
+ // ♿ [A11y STRICT]: O botão deve ter um texto claro e semântica de botão.
40
+ // O `aria-label` seria útil se tivéssemos apenas um ícone.
41
+ className="bg-blue-600 text-white font-bold py-2 px-4 rounded hover:bg-blue-700 transition duration-300"
42
+ >
43
+ Adicionar ao Carrinho
44
+ </button>
45
+ </div>
46
+ );
47
+ };