Skip to content

Commit 9344760

Browse files
rendering selected items onto the cart element
1 parent 4fa7fc9 commit 9344760

File tree

4 files changed

+59
-11
lines changed

4 files changed

+59
-11
lines changed
Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
import React from 'react'
2+
import CartItem from '../cart-item/cart-item.component'
3+
import { connect } from 'react-redux'
24
import CustomButton from '../custom-button/custom-button.component'
35
import './cart-dropdown.styles.scss'
4-
export default function CartDropdown() {
5-
return (
6-
<div className="cart-dropdown">
7-
<div className="cart-item">
8-
<CustomButton>GO TO CHECKOUT</CustomButton>
9-
</div>
6+
const CartDropdown = ({ cartItems }) => (
7+
<div className="cart-dropdown">
8+
<div className="cart-items">
9+
{
10+
cartItems.map(cartItem => <CartItem key={cartItem.id} item={cartItem} />)
11+
}
1012
</div>
11-
)
12-
}
13+
<CustomButton>GO TO CHECKOUT</CustomButton>
14+
</div>)
15+
16+
17+
18+
const mapStateToProps = ({ cart: { cartItems } }) => ({
19+
cartItems
20+
})
21+
22+
export default connect(mapStateToProps)(CartDropdown)
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.cart-dropdown {
22
position: absolute;
33
width: 240px;
4-
height: auto;
4+
height: 340px;
55
display: flex;
66
flex-direction: column;
77
padding: 20px;
@@ -12,14 +12,14 @@
1212
z-index: 5;
1313

1414
.cart-items {
15+
width: 100%;
1516
height: 240px;
1617
display: flex;
1718
flex-direction: column;
18-
overflow: scroll;
19+
overflow-y: scroll;
1920
}
2021

2122
button {
22-
width: 100%;
2323
margin-top: auto;
2424
}
2525
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react'
2+
import './cart-item.styles.scss'
3+
function CartItem({ item: { imageUrl, price, name, quantity } }) {
4+
return (
5+
<div className="cart-item">
6+
<img src={imageUrl} alt={name} />
7+
<div className="item-details">
8+
<span className="name">{name}</span>
9+
<span className="price">{quantity}*${price}</span>
10+
</div>
11+
</div>
12+
)
13+
}
14+
15+
export default CartItem
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.cart-item {
2+
width: 100%;
3+
display: flex;
4+
height: 80px;
5+
margin-bottom: 15px;
6+
7+
img {
8+
width: 30%;
9+
}
10+
11+
.item-details {
12+
width: 70%;
13+
display: flex;
14+
flex-direction: column;
15+
align-items: flex-start;
16+
justify-content: center;
17+
padding: 10px 20px;
18+
19+
.name {
20+
font-size: 16px;
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)