-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathBreadcrumbsItem.astro
126 lines (114 loc) · 2.17 KB
/
BreadcrumbsItem.astro
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
---
/**
* Breadcrumbs Item Component
*
* @description An individual breadcrumb item that can be a link or current page indicator
*/
interface Props {
/**
* URL for the breadcrumb link
*/
href?: string
/**
* Text label for the breadcrumb
*/
label: string
/**
* Whether this item represents the current page
*/
currentPage?: boolean
/**
* Whether this item has an icon
*/
hasIcon?: boolean
/**
* Additional classes to apply to the item
*/
class?: string
}
const {
href = '#',
label = 'Breadcrumb',
currentPage = false,
hasIcon = false,
class: classNames,
} = Astro.props
---
<li class:list={['item', classNames]}>
{
currentPage ? (
<span aria-current="page" class:list={[hasIcon ? 'has-icon' : '']}>
{hasIcon ? (
<>
<slot name="icon" />
<span class="sr-only">{label}</span>
</>
) : (
label
)}
</span>
) : (
<a href={href} class:list={[hasIcon ? 'has-icon' : '']}>
{hasIcon ? (
<>
<slot name="icon" />
<span class="sr-only">{label}</span>
</>
) : (
label
)}
</a>
)
}
<slot name="separator">
<span class="separator" aria-hidden="true">/</span>
</slot>
</li>
<style>
:where(.item) {
display: flex;
align-items: center;
gap: 0.5rem;
}
.item :global(.separator) {
display: flex;
align-items: center;
}
.item :global(.separator svg) {
margin-block-start: 3px;
}
.item :global(svg) {
inline-size: 1rem;
block-size: 1rem;
}
li.item:last-child :global(.separator) {
display: none;
}
:where(.has-icon) :global(svg) {
display: flex;
align-items: center;
}
a {
color: currentColor;
text-decoration: underline;
text-underline-offset: 4px;
}
a:hover,
a:focus-visible {
text-decoration: none;
}
span[aria-current='page'] {
font-weight: 500;
}
.sr-only {
position: absolute;
margin: -1px;
padding: 0;
inline-size: 1px;
block-size: 1px;
overflow: clip;
clip: rect(0, 0, 0, 0);
border: 0;
white-space: nowrap;
}
</style>