-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathBreadcrumbs.tsx
88 lines (79 loc) · 2.08 KB
/
Breadcrumbs.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/** @jsxImportSource @emotion/react */
'use client'
import { usePathname, useRouter } from 'next/navigation'
import Link from 'next/link'
import { Type } from './primitives/Type'
type Path = { title: string; href: string }
export function Breadcrumbs() {
const router = useRouter()
const pathname = usePathname()
// remove anchor and split path
const linkPath = new URL(pathname || '', 'https://keystonejs.com').pathname.split('/')
linkPath.shift()
const breadcrumbs = linkPath.map((path, i): Path => {
return { title: path.replace(/-/g, ' '), href: '/' + linkPath.slice(0, i + 1).join('/') }
})
if (breadcrumbs.length < 2) {
return null
}
return (
<nav
aria-label="breadcrumbs"
css={{
marginBottom: '1rem',
}}
>
<ul
css={{
margin: '0 !important',
padding: '0 !important',
fontSize: '0.75rem',
'& li': {
position: 'relative',
display: 'inline-block',
paddingLeft: '0 !important',
marginTop: 0,
},
'& li a': {
textDecoration: 'none',
},
'& li a:hover span, & li a:focus span': {
color: 'var(--link)',
},
'& li + li': {
marginLeft: '0.5em',
paddingLeft: '0.875em !important',
},
'&& li:before': {
position: 'absolute',
content: '"/"',
top: 0,
left: 0,
width: 'auto',
height: 'auto',
backgroundColor: 'transparent',
},
'& li:first-child:before': {
display: 'none',
},
}}
>
{breadcrumbs.map(({ title, href }) => (
<li key={href}>
<Link href={href}>
<Type
look="body12"
css={{
textTransform: 'uppercase',
color: 'var(--muted)',
}}
>
{title}
</Type>
</Link>
</li>
))}
</ul>
</nav>
)
}