diff options
Diffstat (limited to 'stepped-solutions/42/frontend/components/CartItem.js')
| -rwxr-xr-x | stepped-solutions/42/frontend/components/CartItem.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/stepped-solutions/42/frontend/components/CartItem.js b/stepped-solutions/42/frontend/components/CartItem.js new file mode 100755 index 0000000..8f6a099 --- /dev/null +++ b/stepped-solutions/42/frontend/components/CartItem.js @@ -0,0 +1,41 @@ +import React from 'react'; +import styled from 'styled-components'; +import PropTypes from 'prop-types'; +import formatMoney from '../lib/formatMoney'; + +const CartItemStyles = styled.li` + padding: 1rem 0; + border-bottom: 1px solid ${props => props.theme.lightgrey}; + display: grid; + align-items: center; + grid-template-columns: auto 1fr auto; + img { + margin-right: 10px; + } + h3, + p { + margin: 0; + } +`; + +const CartItem = ({ cartItem }) => ( + <CartItemStyles> + <img width="100" src={cartItem.item.image} alt={cartItem.item.title} /> + <div className="cart-item-details"> + <h3>{cartItem.item.title}</h3> + <p> + {formatMoney(cartItem.item.price * cartItem.quantity)} + {' - '} + <em> + {cartItem.quantity} × {formatMoney(cartItem.item.price)} each + </em> + </p> + </div> + </CartItemStyles> +); + +CartItem.propTypes = { + cartItem: PropTypes.object.isRequired, +}; + +export default CartItem; |
