-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1e2d59
commit bbd2171
Showing
5 changed files
with
124 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
@import "../../styles/global-imports"; | ||
|
||
.CartItem { | ||
display: flex; | ||
align-items: center; | ||
padding: 24px 40px 24px 24px; | ||
|
||
box-sizing: border-box; | ||
|
||
border: 1px solid $c-elements; | ||
|
||
&__delete { | ||
margin-right: 24px; | ||
width: 16px; | ||
height: 16px; | ||
|
||
border: none; | ||
background: no-repeat center url("../../images/icons/icon-close.svg"); | ||
|
||
cursor: pointer; | ||
|
||
@include hover(transform, rotate(90deg)); | ||
} | ||
|
||
&__image { | ||
margin-right: 24px; | ||
padding: 7px; | ||
|
||
& > img { | ||
max-width: 66px; | ||
max-height: 66px; | ||
width: 100%; | ||
} | ||
} | ||
|
||
&__title { | ||
@extend %body-text; | ||
} | ||
|
||
&__quantity { | ||
display: flex; | ||
align-items: center; | ||
gap: 13px; | ||
margin-left: auto; | ||
margin-right: 43px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* eslint-disable jsx-a11y/control-has-associated-label */ | ||
import './CartItem.scss'; | ||
import { useAppDispatch } from '../../app/hooks'; | ||
import { | ||
CartItemType, | ||
decreaseQuantity, | ||
increaseQuantity, | ||
remove, | ||
} from '../../features/cart/cartSlice'; | ||
import { calculateDiscount } from '../../helpers/calculateDiscount'; | ||
import { Button } from '../Button/Button'; | ||
|
||
type Props = { | ||
item: CartItemType; | ||
}; | ||
|
||
export const CartItem: React.FC<Props> = ({ item }) => { | ||
const dispatch = useAppDispatch(); | ||
|
||
const { id, imageUrl, name } = item.product; | ||
|
||
return ( | ||
<div className="CartItem"> | ||
<button | ||
className="CartItem__delete" | ||
type="button" | ||
data-cy="cartDeleteButton" | ||
onClick={() => dispatch(remove(id))} | ||
/> | ||
|
||
<div className="CartItem__image"> | ||
<img | ||
src={imageUrl} | ||
alt={name} | ||
/> | ||
</div> | ||
|
||
<div className="CartItem__title"> | ||
{name} | ||
</div> | ||
|
||
<div className="CartItem__quantity"> | ||
<Button | ||
variant="quantity" | ||
sign="minus" | ||
disabled={item.quantity === 1} | ||
onClick={() => dispatch(decreaseQuantity(id))} | ||
/> | ||
|
||
<span | ||
data-cy="productQauntity" | ||
> | ||
{item.quantity} | ||
</span> | ||
|
||
<Button | ||
variant="quantity" | ||
sign="plus" | ||
onClick={() => dispatch(increaseQuantity(id))} | ||
/> | ||
</div> | ||
|
||
<div className="CartItem__price"> | ||
<h2> | ||
{`$${calculateDiscount(item.product)}`} | ||
</h2> | ||
</div> | ||
|
||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters