mirror of
https://github.com/vercel/commerce.git
synced 2025-07-04 04:01:21 +00:00
✨ feat: Breadcrumb Common
This commit is contained in:
parent
08cd011b5e
commit
185601f002
@ -0,0 +1,6 @@
|
||||
@import '../../../styles/utilities';
|
||||
|
||||
.breadcrumbCommon {
|
||||
@apply spacing-horizontal-left;
|
||||
color: var(--text-base);
|
||||
}
|
54
src/components/common/BreadcrumbCommon/BreadcrumbCommon.tsx
Normal file
54
src/components/common/BreadcrumbCommon/BreadcrumbCommon.tsx
Normal file
@ -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 (
|
||||
<section className={s.breadcrumbCommon}>
|
||||
<BreadcrumbItem text="Home" href="/" />
|
||||
{
|
||||
crumbs.map((crumb, i) => {
|
||||
if (crumb === "") {
|
||||
return
|
||||
}
|
||||
if (i === crumbs.length-1) {
|
||||
return (
|
||||
<BreadcrumbSeparator key={i}>
|
||||
<BreadcrumbItem text={`${paths[crumb]}`} href="#" />
|
||||
</BreadcrumbSeparator>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<BreadcrumbSeparator key={i}>
|
||||
<BreadcrumbItem text={`${paths[crumb]}`} href={`/${paths[crumb]}`} />
|
||||
</BreadcrumbSeparator>
|
||||
)
|
||||
})
|
||||
}
|
||||
</section>
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
export default BreadcrumbCommon
|
@ -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 (
|
||||
<Link href={`${href}`}>
|
||||
{text}
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
|
||||
export default BreadcrumbItem
|
@ -0,0 +1,15 @@
|
||||
import React from 'react'
|
||||
|
||||
interface BreadcrumbSeparatorProps {
|
||||
children: any;
|
||||
}
|
||||
|
||||
const BreadcrumbSeparator = ({ children }: BreadcrumbSeparatorProps) => {
|
||||
return (
|
||||
<span>
|
||||
/ {children}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
export default BreadcrumbSeparator
|
Loading…
x
Reference in New Issue
Block a user