diff --git a/public/coffee-mug.png b/public/coffee-mug.png new file mode 100644 index 000000000..c19c2088d Binary files /dev/null and b/public/coffee-mug.png differ diff --git a/src/components-patten/assets/no-image.jpg b/src/components-patten/assets/no-image.jpg new file mode 100644 index 000000000..ae122b097 Binary files /dev/null and b/src/components-patten/assets/no-image.jpg differ diff --git a/src/components-patten/components/ProductButtons.tsx b/src/components-patten/components/ProductButtons.tsx new file mode 100644 index 000000000..e8efb097d --- /dev/null +++ b/src/components-patten/components/ProductButtons.tsx @@ -0,0 +1,19 @@ +import styles from "../styles/styles.module.css"; +import React, { createContext, ReactElement, useContext } from "react"; +import { ProductContext } from "./ProductCard"; + +export const ProductButtons = ({ className }: { className: string }) => { + const { increaseBy, counter } = useContext(ProductContext); + + return ( +
+ +
{counter}
+ +
+ ); +}; diff --git a/src/components-patten/components/ProductCard.tsx b/src/components-patten/components/ProductCard.tsx new file mode 100644 index 000000000..0f424e694 --- /dev/null +++ b/src/components-patten/components/ProductCard.tsx @@ -0,0 +1,23 @@ +import React, { createContext, ReactElement, useContext } from "react"; +import styles from "../styles/styles.module.css"; +import useProduct from "../hooks/useProduct"; +import { Props, ProductContextProps } from "../interfaces/interfaces"; +export const ProductContext = createContext({} as ProductContextProps); +const { Provider } = ProductContext; + +const ProductCard = ({ children, product, className }: Props) => { + const { counter, increaseBy } = useProduct(); + return ( + +
+ {children} + + {" "} + {product.title} + +
+
+ ); +}; + +export default ProductCard; diff --git a/src/components-patten/components/ProductImage.tsx b/src/components-patten/components/ProductImage.tsx new file mode 100644 index 000000000..7f0ba47b3 --- /dev/null +++ b/src/components-patten/components/ProductImage.tsx @@ -0,0 +1,22 @@ +import styles from "../styles/styles.module.css"; +import React, { createContext, ReactElement, useContext } from "react"; +import noImage from "../assets/no-image.jpg"; +import { ProductContext } from "./ProductCard"; + +export const ProductImage = ({ + img = "", + className, +}: { + img: string; + className?: string; +}) => { + const { product } = useContext(ProductContext); + let imgToShow = img ? img : product.img; + return ( + Coffee + ); +}; diff --git a/src/components-patten/hooks/useProduct.ts b/src/components-patten/hooks/useProduct.ts new file mode 100644 index 000000000..f3fdb1b9e --- /dev/null +++ b/src/components-patten/hooks/useProduct.ts @@ -0,0 +1,12 @@ +import React, { useState } from "react"; + +const useProduct = () => { + const [counter, setCounter] = useState(0); + + const increaseBy = (value: number) => { + setCounter((prev: number) => Math.max(prev + value, 0)); + }; + return { counter, increaseBy }; +}; + +export default useProduct; diff --git a/src/components-patten/interfaces/interfaces.ts b/src/components-patten/interfaces/interfaces.ts new file mode 100644 index 000000000..1ab362c82 --- /dev/null +++ b/src/components-patten/interfaces/interfaces.ts @@ -0,0 +1,19 @@ +import { ReactElement } from "react"; + +export interface Props { + product: Product; + children?: ReactElement | ReactElement[]; + className?: string; +} + +export interface Product { + id: string; + title: string; + img?: string; +} + +export interface ProductContextProps { + counter: number; + increaseBy: (value: number) => void; + product: Product; +} diff --git a/src/components-patten/pages/ShoppingPage.tsx b/src/components-patten/pages/ShoppingPage.tsx new file mode 100644 index 000000000..13777547b --- /dev/null +++ b/src/components-patten/pages/ShoppingPage.tsx @@ -0,0 +1,25 @@ +import { ProductButtons } from "../components/ProductButtons"; +import ProductCard from "../components/ProductCard"; +import { ProductImage } from "../components/ProductImage"; +import "../styles/custom-styles.css"; +const product = { + id: "2", + title: "jugaso ", + img: "./coffee-mug.png", +}; +const ShoppingPage = () => { + return ( +
+

Shopping Card

+
+
+ + + + +
+
+ ); +}; + +export default ShoppingPage; diff --git a/src/components-patten/styles/custom-styles.css b/src/components-patten/styles/custom-styles.css new file mode 100644 index 000000000..fc5c9f341 --- /dev/null +++ b/src/components-patten/styles/custom-styles.css @@ -0,0 +1,15 @@ +.bg-dark { + background-color: rgb(56, 56, 56); +} +.text-white { + color: white; +} +.custom-image { + border-radius: 20px; + padding: 10px; + width: calc(100% - 20px); +} + +.custom-buttons button { + color: red; +} diff --git a/src/components-patten/styles/styles.module.css b/src/components-patten/styles/styles.module.css new file mode 100644 index 000000000..48ab3f819 --- /dev/null +++ b/src/components-patten/styles/styles.module.css @@ -0,0 +1,62 @@ + + +.productCard { + background-color: white; + border-radius: 15px; + color: black; + padding-bottom: 5px; + width: 250px; + margin-right: 5px; + margin-top: 5px; +} + +.productImg { + border-radius: 15px 15px 0px 0px; + width: 100%; +} + +.productDescription { + margin: 10px; +} + +.buttonsContainer { + margin: 10px; + display: flex; + flex-direction: row; +} + +.buttonMinus { + cursor: pointer; + background-color: transparent; + border: 1px solid black; + border-radius: 5px 0px 0px 5px; + font-size: 20px; + width: 30px; +} + +.buttonMinus:hover { + background-color: rgba(0, 0, 0, 0.1); +} + +.countLabel { + border-bottom: 1px solid black; + border-top: 1px solid black; + font-size: 16px; + height: 25px; + padding-top: 5px; + text-align: center; + width: 30px; +} + +.buttonAdd { + cursor: pointer; + background-color: transparent; + border: 1px solid black; + border-radius: 0px 5px 5px 0px; + font-size: 20px; + width: 30px; +} + +.buttonAdd:hover { + background-color: rgba(0, 0, 0, 0.1); +} \ No newline at end of file diff --git a/src/routes/Navigation.tsx b/src/routes/Navigation.tsx index a9bfe83b0..f4d85fc41 100644 --- a/src/routes/Navigation.tsx +++ b/src/routes/Navigation.tsx @@ -1,45 +1,33 @@ -import { - BrowserRouter as Router, - Switch, - Route, - NavLink -} from 'react-router-dom'; +import { BrowserRouter, Routes, Route, NavLink } from "react-router-dom"; +import ShoppingPage from "../components-patten/pages/ShoppingPage"; -import logo from '../logo.svg'; +import logo from "../logo.svg"; export const Navigation = () => { return ( - +
- {/* A looks through its children s and - renders the first one that matches the current URL. */} - - -

About

-
- -

Users

-
- -

Home

-
-
+ + about
}> + Users}> + }> + -
+ ); -} \ No newline at end of file +};