From 0d22f1d5ac619cdfb5b3f2908ac64bcc2e272af7 Mon Sep 17 00:00:00 2001 From: Mikayla Dobson <93477693+innocuous-symmetry@users.noreply.github.com> Date: Sat, 8 Oct 2022 14:59:35 -0500 Subject: [PATCH] defining and integrating a small component library --- client/src/components/Auth/AuthForm.tsx | 22 ++++++++++--------- client/src/components/Home.tsx | 14 +++++++----- client/src/components/Product/AllProducts.tsx | 10 +++++---- client/src/components/Product/ProductCard.tsx | 8 ++++--- client/src/components/Product/ProductPage.tsx | 5 +++-- client/src/components/User/UserProfile.tsx | 12 +++++----- client/src/components/_ui/Button/Button.scss | 0 client/src/components/_ui/Button/Button.tsx | 13 +++++++++++ client/src/components/_ui/Card/Card.scss | 0 client/src/components/_ui/Card/Card.tsx | 11 ++++++++++ .../src/components/_ui/Gallery/Gallery.scss | 0 client/src/components/_ui/Gallery/Gallery.tsx | 13 +++++++++++ client/src/components/_ui/Page/Page.scss | 0 client/src/components/_ui/Page/Page.tsx | 11 ++++++++++ client/src/util/types.ts | 22 ++++++++++++++++++- 15 files changed, 110 insertions(+), 31 deletions(-) create mode 100644 client/src/components/_ui/Button/Button.scss create mode 100644 client/src/components/_ui/Button/Button.tsx create mode 100644 client/src/components/_ui/Card/Card.scss create mode 100644 client/src/components/_ui/Card/Card.tsx create mode 100644 client/src/components/_ui/Gallery/Gallery.scss create mode 100644 client/src/components/_ui/Gallery/Gallery.tsx create mode 100644 client/src/components/_ui/Page/Page.scss create mode 100644 client/src/components/_ui/Page/Page.tsx diff --git a/client/src/components/Auth/AuthForm.tsx b/client/src/components/Auth/AuthForm.tsx index ea859b9..8835c62 100644 --- a/client/src/components/Auth/AuthForm.tsx +++ b/client/src/components/Auth/AuthForm.tsx @@ -2,6 +2,8 @@ import { useSupabase } from "../../supabase/SupabaseContext"; import { FormInput, getSession, handleLogin, handleRegister } from "../../util/authHelpers"; import { AuthFormType } from "../../util/types"; import { useState } from "react"; +import Button from "../_ui/Button/Button"; +import Page from "../_ui/Page/Page"; const AuthForm: AuthFormType = ({ format }) => { const [input, setInput] = useState({ email: "", password: "" }); @@ -10,25 +12,25 @@ const AuthForm: AuthFormType = ({ format }) => { const formFunction = format == "login" ? () => handleLogin(supabase, input) : () => handleRegister(supabase, input); return ( -
+

{formText}

-
- - setInput({...input, email: e.target.value})} /> +
+ + setInput({...input, email: e.target.value})} />
-
- - setInput({...input, password: e.target.value})} /> +
+ + setInput({...input, password: e.target.value})} />
- - + +
-
+ ) } diff --git a/client/src/components/Home.tsx b/client/src/components/Home.tsx index 5e73153..aecdbb8 100644 --- a/client/src/components/Home.tsx +++ b/client/src/components/Home.tsx @@ -1,18 +1,20 @@ import { useNavigate } from "react-router-dom" +import Button from "./_ui/Button/Button"; +import Page from "./_ui/Page/Page"; export default function Home() { const navigate = useNavigate(); return ( -
+

The finest spice shop on the internet.

Or at the very least, what their website could look like.

-
- - - +
+ + +
-
+
) } \ No newline at end of file diff --git a/client/src/components/Product/AllProducts.tsx b/client/src/components/Product/AllProducts.tsx index 2d81f1a..319ece4 100644 --- a/client/src/components/Product/AllProducts.tsx +++ b/client/src/components/Product/AllProducts.tsx @@ -2,6 +2,8 @@ import { useEffect, useState } from "react" import { v4 } from "uuid"; import { getAllProducts } from "../../util/apiUtils"; import { ProductModel } from "../../util/types"; +import Gallery from "../_ui/Gallery/Gallery"; +import Page from "../_ui/Page/Page"; import ProductCard from "./ProductCard"; export default function AllProducts() { @@ -16,16 +18,16 @@ export default function AllProducts() { useEffect(() => { setView( -
+

All Products!

-
+ { productData && productData.map((data: ProductModel) => { return }) } -
-
+ + ) }, [productData, setProductData]); diff --git a/client/src/components/Product/ProductCard.tsx b/client/src/components/Product/ProductCard.tsx index 81fe447..ffd84f0 100644 --- a/client/src/components/Product/ProductCard.tsx +++ b/client/src/components/Product/ProductCard.tsx @@ -1,17 +1,19 @@ import { useNavigate } from "react-router-dom"; import { ProductCardType } from "../../util/types"; +import Button from "../_ui/Button/Button"; +import Card from "../_ui/Card/Card"; const ProductCard: ProductCardType = ({ data }) => { const navigate = useNavigate(); return ( -
+

{data.name}

{data.price}

{data.description}

- -
+ + ) } diff --git a/client/src/components/Product/ProductPage.tsx b/client/src/components/Product/ProductPage.tsx index 0465881..c4716a9 100644 --- a/client/src/components/Product/ProductPage.tsx +++ b/client/src/components/Product/ProductPage.tsx @@ -2,6 +2,7 @@ import { useEffect, useState } from "react"; import { useNavigate, useParams } from "react-router-dom" import { getByProductId } from "../../util/apiUtils"; import { ProductModel } from "../../util/types"; +import Page from "../_ui/Page/Page"; export default function ProductPage() { const [productData, setProductData] = useState(); @@ -17,12 +18,12 @@ export default function ProductPage() { if (!productData) return

Product not found.

return ( -
+

{productData.name}

{productData.price}

{productData.description}

-
+ ) } \ No newline at end of file diff --git a/client/src/components/User/UserProfile.tsx b/client/src/components/User/UserProfile.tsx index d778c1f..e24b73f 100644 --- a/client/src/components/User/UserProfile.tsx +++ b/client/src/components/User/UserProfile.tsx @@ -1,21 +1,23 @@ import { useNavigate } from "react-router-dom"; import { useSupabase } from "../../supabase/SupabaseContext" +import Button from "../_ui/Button/Button"; +import Page from "../_ui/Page/Page"; export default function UserProfile() { const supabase = useSupabase(); const navigate = useNavigate(); return ( -
+

User Profile!

Your email is {supabase?.auth.user()?.email || "not found"}

Options:

- - - + + +
-
+ ) } \ No newline at end of file diff --git a/client/src/components/_ui/Button/Button.scss b/client/src/components/_ui/Button/Button.scss new file mode 100644 index 0000000..e69de29 diff --git a/client/src/components/_ui/Button/Button.tsx b/client/src/components/_ui/Button/Button.tsx new file mode 100644 index 0000000..eec923e --- /dev/null +++ b/client/src/components/_ui/Button/Button.tsx @@ -0,0 +1,13 @@ +import { UIButtonType } from "../../../util/types" + +const Button: UIButtonType = ({ onClick, children = "Button", additionalClasses = "" }) => { + return ( + <> + + + ) +} + +export default Button; \ No newline at end of file diff --git a/client/src/components/_ui/Card/Card.scss b/client/src/components/_ui/Card/Card.scss new file mode 100644 index 0000000..e69de29 diff --git a/client/src/components/_ui/Card/Card.tsx b/client/src/components/_ui/Card/Card.tsx new file mode 100644 index 0000000..0382765 --- /dev/null +++ b/client/src/components/_ui/Card/Card.tsx @@ -0,0 +1,11 @@ +import { UICompWithChildren } from "../../../util/types" + +const Card: UICompWithChildren = ({ children, additionalClasses = "" }) => { + return ( +
+ { children } +
+ ) +} + +export default Card; \ No newline at end of file diff --git a/client/src/components/_ui/Gallery/Gallery.scss b/client/src/components/_ui/Gallery/Gallery.scss new file mode 100644 index 0000000..e69de29 diff --git a/client/src/components/_ui/Gallery/Gallery.tsx b/client/src/components/_ui/Gallery/Gallery.tsx new file mode 100644 index 0000000..cda3310 --- /dev/null +++ b/client/src/components/_ui/Gallery/Gallery.tsx @@ -0,0 +1,13 @@ +import { UIGalleryType } from "../../../util/types" + +const Gallery: UIGalleryType = ({ children, columns, additionalClasses = "" }) => { + const widthFromCols = Math.ceil(90 / columns); + + return ( +
+ { children } +
+ ) +} + +export default Gallery; \ No newline at end of file diff --git a/client/src/components/_ui/Page/Page.scss b/client/src/components/_ui/Page/Page.scss new file mode 100644 index 0000000..e69de29 diff --git a/client/src/components/_ui/Page/Page.tsx b/client/src/components/_ui/Page/Page.tsx new file mode 100644 index 0000000..8329449 --- /dev/null +++ b/client/src/components/_ui/Page/Page.tsx @@ -0,0 +1,11 @@ +import { UICompWithChildren } from "../../../util/types"; + +const Page: UICompWithChildren = ({ children, additionalClasses = "" }) => { + return ( +
+ { children } +
+ ) +} + +export default Page; \ No newline at end of file diff --git a/client/src/util/types.ts b/client/src/util/types.ts index 2d671d4..1c99676 100644 --- a/client/src/util/types.ts +++ b/client/src/util/types.ts @@ -1,8 +1,28 @@ -import { FC } from "react"; +import { FC, ReactNode } from "react"; // component types export type AuthFormType = FC<{ format: string }> export type ProductCardType = FC<{ data: ProductModel }> +export type UIButtonType = FC +export type UICompWithChildren = FC +export type UIGalleryType = FC + +// definitions for component params +interface UIParams { + additionalClasses?: string +} + +interface UIButtonParams extends UIParams { + onClick: (...params: any) => any + children?: string +} + +interface UICompChildrenParams extends UIParams { children: ReactNode } + +interface UIGalleryParams extends UIParams { + children: ReactNode + columns: number +} // data models