diff --git a/src/components/Card.tsx b/src/components/Card.tsx index 26c742f..f017172 100644 --- a/src/components/Card.tsx +++ b/src/components/Card.tsx @@ -1,28 +1,49 @@ +import { PropsWithChildren, ReactNode } from 'react'; + +export const CardImage = (props: { image: string }) => ( +
+ +
+); + +export const CardHeader = ( + props: PropsWithChildren<{ header?: ReactNode }> +) => ( +

+ {props.header ?? props.children} +

+); + +export const CardDescription = ( + props: PropsWithChildren<{ description?: ReactNode; title?: string }> +) => ( +

+ {props.description ?? props.children} +

+); + export const Card = (props: { - header: string; - image: string; - brands: string; - isActive?: boolean; + header?: string; + image?: string; + description?: string; + active?: boolean; }) => (
-
- -
-

- {props.header} -

-

- {props.brands} -

+ {props.image && } + {props.header && } + {props.description && }
); + +Card.CardHeader = CardHeader; +Card.CardDescription = CardDescription; +Card.CardImage = CardImage; + +export default Card; diff --git a/src/components/CloseButton.tsx b/src/components/CloseButton.tsx new file mode 100644 index 0000000..7e5f292 --- /dev/null +++ b/src/components/CloseButton.tsx @@ -0,0 +1,35 @@ +import { PropsWithChildren } from 'react'; + +export const CloseSVG = () => ( + +); + +export const CloseButton = ( + props: PropsWithChildren<{ + onClick: () => void; + }> +) => ( + +); diff --git a/src/components/Container.tsx b/src/components/Container.tsx index 5fbe904..87d3934 100644 --- a/src/components/Container.tsx +++ b/src/components/Container.tsx @@ -1,7 +1,35 @@ import { PropsWithChildren } from 'react'; +import { CloseButton } from './CloseButton'; -export const Container = (props: PropsWithChildren) => ( +export const GridContainer = (props: PropsWithChildren) => (
{props.children}
); + +export const Header = (props: PropsWithChildren) => ( +

+ {props.children} +

+); + +export const FlexContainer = ({ + header, + onClose, + children, +}: PropsWithChildren<{ + header?: string; + onClose?: () => void; +}>) => ( +
+
+
{header}
+ {onClose && } +
+ {children} +
+); diff --git a/src/components/Pagination.tsx b/src/components/Pagination.tsx index db7441e..e4a5585 100644 --- a/src/components/Pagination.tsx +++ b/src/components/Pagination.tsx @@ -62,6 +62,7 @@ export const Pagination = ({ totalPages }: { totalPages: number }) => {
  • - - {navigation.state === 'loading' ? ( - - Searching ... - - ) : ( - - )} - - )} - - + navigator(`/products?${searchParams.toString()}`)} + > + {isLoading && !product && 'Loading...'} + {!isLoading && !product && 'Data is not available'} + {!isLoading && product && } + ); }; diff --git a/src/pages/Products/components/ProductsContainer.tsx b/src/pages/Products/components/ProductsContainer.tsx index 1382a66..552a2ef 100644 --- a/src/pages/Products/components/ProductsContainer.tsx +++ b/src/pages/Products/components/ProductsContainer.tsx @@ -1,5 +1,5 @@ import { Link, useSearchParams, useParams } from 'react-router-dom'; -import { Card, Container } from '../../../components'; +import { Card, GridContainer } from '../../../components'; import { Product } from '../types'; export const ProductsContainer = (props: { @@ -17,31 +17,25 @@ export const ProductsContainer = (props: { return
    {props.error}
    ; } + const getNextUrl = (productId: string) => { + return `${ + productId === id ? `/products` : `/products/${productId}` + }?${searchParams.toString()}`; + }; + return ( - + {!props.data.length &&
    No results
    } - {props.data.map((product) => - String(product.id) !== id ? ( - - - - ) : ( + {props.data.map((product) => ( + - ) - )} -
    + + ))} + ); };