-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCard.jsx
43 lines (39 loc) · 1.2 KB
/
Card.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import React, { useState } from "react";
import "./Card.css";
import Button from "../Button/Button";
function Card({ food, onAdd, onRemove }) {
const [count, setCount] = useState(0);
const { title, Image, price, id } = food;
const handleIncrement = () => {
setCount(count + 1);
onAdd(food);
};
const handleDecrement = () => {
setCount(count - 1);
onRemove(food);
};
return (
<div className="card">
<span
className={`${count !== 0 ? "card__badge" : "card__badge--hidden"}`}
>
{count}
</span>
<div className="image__container">
<img src={Image} alt={title} />
</div>
<h4 className="card__title">
{title} . <span className="card__price">$ {price}</span>
</h4>
<div className="btn-container">
<Button title={"+"} type={"add"} onClick={handleIncrement} />
{count !== 0 ? (
<Button title={"-"} type={"remove"} onClick={handleDecrement} />
) : (
""
)}
</div>
</div>
);
}
export default Card;