From da19ce8f01d66a6b7fc9f00cb3a42c5cf060119d Mon Sep 17 00:00:00 2001 From: Amy Date: Sat, 21 Aug 2021 02:31:40 -0400 Subject: [PATCH] Refactor shapes background pipeline --- components/ShapesBackground.tsx | 82 +++++++++++++++++++-------------- pages/_app.tsx | 17 ++++--- pages/index.tsx | 8 ++++ 3 files changed, 66 insertions(+), 41 deletions(-) diff --git a/components/ShapesBackground.tsx b/components/ShapesBackground.tsx index c8bc1269..c8fbc7b8 100644 --- a/components/ShapesBackground.tsx +++ b/components/ShapesBackground.tsx @@ -1,31 +1,36 @@ -import { useRouter } from "next/router"; -import React from "react"; +import React, { CSSProperties, useEffect, useState } from "react"; import { Image } from "./Image"; import styles from "./ShapesBackground.module.css"; -export function ShapesBackground(props: { children: React.ReactNode }) { - const router = useRouter(); +interface Props { + getConfig?: GetShapesConfig; +} + +export function ShapesBackground({ getConfig }: Props) { + const [config, setConfig] = useState({}); + + useEffect(() => { + setConfig(getConfig?.() ?? {}); + }, [getConfig]); return ( - <> -
- {routeList.find((el) => router.pathname === el.route)?.shapes() ?? null} -
- {props.children} - +
+ {Object.entries(config).map(([type, instances]) => + instances.map((attributes, idx) => ( + + )) + )} +
); } -const routeList = [ - { - route: "/", - shapes: HomeShapes, - }, -]; - -type ShapeType = +export type ShapeType = | "asterisk" | "circle" | "cross" @@ -36,26 +41,33 @@ type ShapeType = | "triangle" | "waves"; -function Shape(props: { shape: ShapeType; className: string }) { +export type ShapesConfig = { + [key in ShapeType]?: CSSProperties[]; +}; + +export type GetShapesConfig = () => ShapesConfig; + +function Shape(props: { type: ShapeType; style: CSSProperties }) { return ( ); } -function HomeShapes() { - return ( - <> - - - - - - - - - - ); -} +// function HomeShapes() { +// return ( +// <> +// +// +// +// +// +// +// +// +// +// ); +// } diff --git a/pages/_app.tsx b/pages/_app.tsx index c023a528..47009547 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -7,7 +7,10 @@ import { DefaultLayout } from "@/components/DefaultLayout"; import { Footer } from "@/components/Footer"; import { Link } from "@/components/Link"; import { Navbar } from "@/components/Navbar"; -import { ShapesBackground } from "@/components/ShapesBackground"; +import { + GetShapesConfig, + ShapesBackground, +} from "@/components/ShapesBackground"; import { ThemeProvider } from "@/components/Theme"; import styles from "./_app.module.css"; @@ -25,11 +28,12 @@ export default function App({ Component, pageProps }: AppProps): JSX.Element { {/* Wrapping content with a div to allow for a display: block parent */}
- - - - - + + + +