diff --git a/src/assets/images/shopping-cart-solid.svg b/src/assets/images/shopping-cart-solid.svg new file mode 100644 index 0000000..e7c58dc --- /dev/null +++ b/src/assets/images/shopping-cart-solid.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/assets/index.js b/src/assets/index.js index 1aa4aa1..3684fc2 100644 --- a/src/assets/index.js +++ b/src/assets/index.js @@ -1,4 +1,6 @@ import plc from "./images/B1-14MR2-D24.jpg"; import w2c from "./images/W2C.jpg"; import banner from "./images/banner-plc.png" -export { plc, w2c, banner }; +import carticon from "./images/shopping-cart-solid.svg" + +export { plc, w2c, banner, carticon } ; diff --git a/src/components/cart/cartIcon.css b/src/components/cart/cartIcon.css new file mode 100644 index 0000000..a78e19b --- /dev/null +++ b/src/components/cart/cartIcon.css @@ -0,0 +1,70 @@ +.top-menu{ + color: white; + background-color: navy; + padding-top: 4rem; + position: relative; + bottom: 0; + width: 100%; + height: 40px; + text-align: center; +} + +svg { + display: block; + width: 60px; + z-index: 0; + position: absolute; + left: 3.4rem; + right: 1 rem; + bottom: 5px; + margin-left: auto; + margin-right: auto; +} + +.cart-badge { + position: absolute; + left: 75px; + bottom: 30px; + display: block; + width: 27px; + height: 27px; + font-size: 1rem; + font-weight: light; + font-family: "Trebuchet MS", sans-serif; + text-transform: uppercase; + text-align: center; + line-height: 1.8rem; + color: white; + border: none; + border-radius: 50%; + background: #b91538; + cursor: pointer; + box-shadow: 0 0 0 0 rgba(#fff, 0.3); + z-index: 50; +} + +.cart-price { + position: absolute; + left: 110px; + bottom: 25px; + display: block; + width: 25px; + height: 25px; + font-size: 1.2rem; + font-weight: bold; + font-family: "Trebuchet MS", sans-serif; + text-transform: uppercase; + text-align: center; + line-height: 1.8rem; + color: rgb(90, 214, 245); + border: none; + /* border-radius: 50%; + background: #b91538; */ + cursor: pointer; + box-shadow: 0 0 0 0 rgba(#fff, 0.3); + z-index: 50; + } + +.st0 { + fill: #ffffff; +} diff --git a/src/components/cart/cartIcon.jsx b/src/components/cart/cartIcon.jsx new file mode 100644 index 0000000..bf3b51c --- /dev/null +++ b/src/components/cart/cartIcon.jsx @@ -0,0 +1,40 @@ +import React from "react"; +// import { carticon } from "../../assets"; +import "./cartIcon.css"; + +let ShoppingCartIcon = () => { + return ( + + + + + + + + + + ); +}; + +const CartIcon = ({ count, total }) => { + return ( +
+
+
+ + {count} + + + + ${total} + +
+
+
+ ); +}; + +export default CartIcon; diff --git a/src/components/cart/index.js b/src/components/cart/index.js new file mode 100644 index 0000000..5abb18e --- /dev/null +++ b/src/components/cart/index.js @@ -0,0 +1 @@ +export {default as CartIcon} from './cartIcon'; diff --git a/src/components/mainPage/landing.jsx b/src/components/mainPage/landing.jsx index e4b6d05..4522791 100644 --- a/src/components/mainPage/landing.jsx +++ b/src/components/mainPage/landing.jsx @@ -1,13 +1,28 @@ -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import "./home.css"; import { PayPal, Purchase, ShowCase, Home } from "."; import { AllProducts } from "../products"; import { Orders } from "../orders"; +import { CartIcon } from '../cart'; // component const Details = () => { const [cart, setCart] = useState([]); const [orderID, setOrderID] = useState(null); + const [total, setTotal] = useState(0); + + // refresh the cart logo and amount of the cart + useEffect(() => { + + let sub_total = cart.reduce((sum, it)=>{ + console.log(it.price); + return it.price+sum + },0); + + setTotal(sub_total); + + console.log("effect", total) + },[cart, total]); return ( <> @@ -15,8 +30,10 @@ const Details = () => { {/* you can try 600011 in orderID */} + + ); };