@@ -9,39 +9,77 @@ import { Link, useNavigate } from "react-router-dom";
9
9
export const Card = ( { name, id, description, price, url} ) => {
10
10
11
11
const navigate = useNavigate ( ) ;
12
+ const truncatedDescription =
13
+ description . length > 40 ? description . slice ( 0 , 40 ) + "..." : description ;
14
+ const truncatedName = name . length > 30 ? name . slice ( 0 , 30 ) + "..." : name ;
12
15
13
16
const { store, actions } = useContext ( Context ) ;
14
17
15
18
const handleAddToCart = ( ) => {
16
19
17
- // Verifica si el usuario está registrado
18
- if ( store . user ) { // Asumiendo que `store.user` contiene información del usuario si está autenticado
19
- actions . addToCart ( { name, id, price, url } ) ; // Añade el producto al carrito
20
+
21
+ if ( store . user ) {
22
+ actions . addToCart ( { name, id, price, url } ) ;
20
23
} else {
21
24
navigate ( "/##" ) ; // Redirige al login si no está autenticado
22
25
}
23
26
} ;
24
27
25
28
return (
26
29
27
- < div className = "card m-2" style = { { width : "18rem" } } >
30
+ < div className = "card m-2 d-flex flex-column"
31
+ style = { {
32
+ // background: "linear-gradient(to bottom,#FD841F,hsl(61, 80.60%, 71.80%)",
33
+ // background: "hsl(61, 80.60%, 71.80%)",
34
+ width : "15rem" } } >
28
35
< Link to = { `/vista-producto/${ id } ` } className = "text-decoration-none" >
29
36
< img
30
37
src = { url }
31
- style = { { width : "100px" , height : "150px" } }
38
+ style = { {
39
+ width : "130px" , height : "150px" } }
32
40
className = "card-img-top mx-auto d-block mt-2"
33
41
alt = "..."
34
42
/>
35
- < div className = "card-body text-center" >
36
- < h5 className = "card-title" > { name } </ h5 >
37
- < p className = "card-text" > { description } </ p >
38
- < h6 className = "card-price" > { price } €</ h6 >
43
+ < div className = "card-body text-center d-flex flex-column" >
44
+ < h5 className = "card-title text-black" > { truncatedName } </ h5 >
45
+
46
+ < div >
47
+ < p className = "card-text" style = { {
48
+ color :"grey" ,
49
+ height : "60px" ,
50
+ overflow : "hidden" ,
51
+ textOverflow : "ellipsis" ,
52
+ display : "-webkit-box" ,
53
+ WebkitLineClamp : 3 ,
54
+ WebkitBoxOrient : "vertical" ,
55
+ } }
56
+ >
57
+ { truncatedDescription } </ p >
58
+ </ div >
39
59
</ div >
40
60
</ Link >
41
61
42
62
43
63
< div className = "mt-auto text-center" >
44
- < button onClick = { handleAddToCart } className = "btn btn-primary m-2" >
64
+ < h6 className = "card-price mt-auto"
65
+ style = { {
66
+ fontSize : "20px" ,
67
+ fontWeight : "bold" ,
68
+ // color: "#9C2C77", // Cambia el color del precio
69
+ marginBottom : "10px" , // Añade un margen inferior
70
+ } }
71
+
72
+ > { price } €</ h6 >
73
+ < button
74
+ onClick = { handleAddToCart }
75
+ className = "btn btn-warning mb-3 "
76
+ style = { {
77
+ // background: "#EB5A3C",
78
+ color : "black" , // Color del texto
79
+ width : "auto" , // Ancho automático (ajusta al contenido)
80
+ padding : "0.375rem 1rem" , // Ajusta el padding para hacerlo más estrecho
81
+ fontSize : "0.875rem" , // Tamaño de la fuente
82
+ } } >
45
83
Añadir al carrito
46
84
</ button >
47
85
0 commit comments