From 8c7c57175d50dfc9a9fd10ef03cae700e3c89e33 Mon Sep 17 00:00:00 2001 From: sonnguyenkieio Date: Tue, 31 Aug 2021 10:44:11 +0700 Subject: [PATCH] :sparkles: feat: Breadcrumbs Common --- .../BreadcrumbCommon/BreadcrumbCommon.tsx | 37 +++++++------------ .../BreadcrumbItem/BreadcrumbItem.tsx | 4 +- .../BreadcrumbSeparator.tsx | 2 +- 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/components/common/BreadcrumbCommon/BreadcrumbCommon.tsx b/src/components/common/BreadcrumbCommon/BreadcrumbCommon.tsx index 8b36f7e50..615a26893 100644 --- a/src/components/common/BreadcrumbCommon/BreadcrumbCommon.tsx +++ b/src/components/common/BreadcrumbCommon/BreadcrumbCommon.tsx @@ -1,54 +1,43 @@ import React from 'react' import s from './BreadcrumbCommon.module.scss' -import { useRouter } from 'next/router' - import BreadcrumbItem from './components/BreadcrumbItem/BreadcrumbItem' import BreadcrumbSeparator from './components/BreadcrumbSeparator/BreadcrumbSeparator' -const BreadcrumbCommon = () => { +interface BreadcrumbCommonProps { + crumbs: { link:string, name:string }[]; + showHomePage?: boolean; +} - const paths: string | any = { - "/": "Home", - "fresh-product-today" : "Fresh Product Today", - "product-list": "Product List", - "recipes-list": "Recipes List", - "blogs": "Blog", - "account": "Account", - "delivery&policy": "Delivery & Policy", - "product-detail": "Product Detail", - "recipes-detail": "Recipes Detail", - "blog-detail": "Blog Detail" +const BreadcrumbCommon = ({ crumbs, showHomePage=true } : BreadcrumbCommonProps) => { + if (showHomePage) { + crumbs.unshift({link: "/", name: "Home"}); } - - const router = useRouter(); - let crumbs = router.route.split('/'); - return (
- { crumbs.map((crumb, i) => { - if (crumb === "") { - return + if (i === 0) { + return ( + + ) } if (i === crumbs.length-1) { return ( - + ) } return ( - + ) }) }
) - } export default BreadcrumbCommon diff --git a/src/components/common/BreadcrumbCommon/components/BreadcrumbItem/BreadcrumbItem.tsx b/src/components/common/BreadcrumbCommon/components/BreadcrumbItem/BreadcrumbItem.tsx index 9a501c93f..f807de555 100644 --- a/src/components/common/BreadcrumbCommon/components/BreadcrumbItem/BreadcrumbItem.tsx +++ b/src/components/common/BreadcrumbCommon/components/BreadcrumbItem/BreadcrumbItem.tsx @@ -8,8 +8,8 @@ interface BreadcrumbItemProps { const BreadcrumbItem = ({ text, href }: BreadcrumbItemProps) => { return ( - - {text} + + {text} ) } diff --git a/src/components/common/BreadcrumbCommon/components/BreadcrumbSeparator/BreadcrumbSeparator.tsx b/src/components/common/BreadcrumbCommon/components/BreadcrumbSeparator/BreadcrumbSeparator.tsx index c877e60bc..370c342d8 100644 --- a/src/components/common/BreadcrumbCommon/components/BreadcrumbSeparator/BreadcrumbSeparator.tsx +++ b/src/components/common/BreadcrumbCommon/components/BreadcrumbSeparator/BreadcrumbSeparator.tsx @@ -1,7 +1,7 @@ import React from 'react' interface BreadcrumbSeparatorProps { - children: any; + children?: React.ReactNode } const BreadcrumbSeparator = ({ children }: BreadcrumbSeparatorProps) => {