From 185601f002858a643c2beae4a60e516802d60c70 Mon Sep 17 00:00:00 2001 From: sonnguyenkieio Date: Mon, 30 Aug 2021 16:46:52 +0700 Subject: [PATCH] :sparkles: feat: Breadcrumb Common --- .../BreadcrumbCommon.module.scss | 6 +++ .../BreadcrumbCommon/BreadcrumbCommon.tsx | 54 +++++++++++++++++++ .../BreadcrumbItem/BreadcrumbItem.tsx | 17 ++++++ .../BreadcrumbSeparator.tsx | 15 ++++++ 4 files changed, 92 insertions(+) create mode 100644 src/components/common/BreadcrumbCommon/BreadcrumbCommon.module.scss create mode 100644 src/components/common/BreadcrumbCommon/BreadcrumbCommon.tsx create mode 100644 src/components/common/BreadcrumbCommon/components/BreadcrumbItem/BreadcrumbItem.tsx create mode 100644 src/components/common/BreadcrumbCommon/components/BreadcrumbSeparator/BreadcrumbSeparator.tsx diff --git a/src/components/common/BreadcrumbCommon/BreadcrumbCommon.module.scss b/src/components/common/BreadcrumbCommon/BreadcrumbCommon.module.scss new file mode 100644 index 000000000..6741f386c --- /dev/null +++ b/src/components/common/BreadcrumbCommon/BreadcrumbCommon.module.scss @@ -0,0 +1,6 @@ +@import '../../../styles/utilities'; + +.breadcrumbCommon { + @apply spacing-horizontal-left; + color: var(--text-base); +} \ No newline at end of file diff --git a/src/components/common/BreadcrumbCommon/BreadcrumbCommon.tsx b/src/components/common/BreadcrumbCommon/BreadcrumbCommon.tsx new file mode 100644 index 000000000..8b36f7e50 --- /dev/null +++ b/src/components/common/BreadcrumbCommon/BreadcrumbCommon.tsx @@ -0,0 +1,54 @@ +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 = () => { + + 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 router = useRouter(); + let crumbs = router.route.split('/'); + + return ( +
+ + { + crumbs.map((crumb, i) => { + if (crumb === "") { + 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 new file mode 100644 index 000000000..9a501c93f --- /dev/null +++ b/src/components/common/BreadcrumbCommon/components/BreadcrumbItem/BreadcrumbItem.tsx @@ -0,0 +1,17 @@ +import React from 'react' +import Link from 'next/link' + +interface BreadcrumbItemProps { + text: string; + href: string; +} + +const BreadcrumbItem = ({ text, href }: BreadcrumbItemProps) => { + return ( + + {text} + + ) +} + +export default BreadcrumbItem diff --git a/src/components/common/BreadcrumbCommon/components/BreadcrumbSeparator/BreadcrumbSeparator.tsx b/src/components/common/BreadcrumbCommon/components/BreadcrumbSeparator/BreadcrumbSeparator.tsx new file mode 100644 index 000000000..c877e60bc --- /dev/null +++ b/src/components/common/BreadcrumbCommon/components/BreadcrumbSeparator/BreadcrumbSeparator.tsx @@ -0,0 +1,15 @@ +import React from 'react' + +interface BreadcrumbSeparatorProps { + children: any; +} + +const BreadcrumbSeparator = ({ children }: BreadcrumbSeparatorProps) => { + return ( + +  / {children} + + ) +} + +export default BreadcrumbSeparator