-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathheader-actions.astro
More file actions
157 lines (147 loc) · 4.24 KB
/
header-actions.astro
File metadata and controls
157 lines (147 loc) · 4.24 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
---
import Button from "@ui/Button.astro";
import HeaderButton from "./header-button.astro";
import Search from "astro-pagefind/components/Search";
export interface Props {
mobile?: boolean;
}
const { mobile = false }: Props = Astro.props;
const IS_LIVE = false;
---
<div class="flex items-center justify-end gap-2 w-1/3">
<Search
id="search"
className="pagefind-ui"
uiOptions={{
showImages: false,
translations: {
zero_results: "Couldn't find [SEARCH_TERM]",
},
}}
/>
{
!mobile ? (
<>
<Button url="/tickets" icon="ticket">Register Now!</Button>
{IS_LIVE && <Button url="/live">Live</Button>}
</>
) : null
}
<label for="nav_toggle" class="flex xl:hidden">
<HeaderButton variant="menu">
{mobile ? "Close Menu" : "Menu"}
</HeaderButton>
</label>
</div>
<script>
document.addEventListener("DOMContentLoaded", function () {
const searchContainer = document.querySelector(".pagefind-ui");
const searchInput = searchContainer?.querySelector("input");
let selectedIndex = -1;
function updateSelection() {
const results = searchContainer?.querySelectorAll(".pagefind-ui__result");
if (!results) return;
results.forEach((result, index) => {
if (index === selectedIndex) {
result.classList.add("selected");
result.scrollIntoView({ block: "nearest", behavior: "smooth" });
} else {
result.classList.remove("selected");
}
});
}
document.addEventListener("keydown", function (event) {
if (!searchContainer || !searchInput) return;
const results = searchContainer.querySelectorAll(".pagefind-ui__result");
if (document.activeElement === searchInput) {
if (event.key === "ArrowDown") {
event.preventDefault();
selectedIndex = (selectedIndex + 1) % results.length;
updateSelection();
} else if (event.key === "ArrowUp") {
event.preventDefault();
selectedIndex = (selectedIndex - 1 + results.length) % results.length;
updateSelection();
} else if (event.key === "Enter" && selectedIndex >= 0) {
event.preventDefault();
results[selectedIndex].querySelector("a")?.click();
}
}
});
// Reset selection when the search query changes
searchInput?.addEventListener("input", function () {
selectedIndex = -1;
});
});
</script>
<style is:global>
.pagefind-ui__result.selected {
background-color: #f5f5f5;
background-image: linear-gradient(to right, #3684b6 7px, transparent 5px);
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
.pagefind-ui__drawer {
}
.pagefind-ui__message {
margin: 1em;
}
.pagefind-ui__result mark {
background: #f9eb5d;
background-image: linear-gradient(to right, #f9eb5d 10%, #fcf4a7 100%);
margin: 4px;
padding-right: 6px;
padding-left: 6px;
padding-top: 2px;
padding-bottom: 2px;
color: #000000;
font-family: monospace;
border-radius: 4px;
}
.pagefind-ui {
--pagefind-ui-scale: 1;
--pagefind-ui-primary: #141f36;
--pagefind-ui-text: black;
--pagefind-ui-border: #d8d8d8;
--pagefind-ui-border-width: 2px;
--pagefind-ui-border-radius: 0;
width:50%;
min-width: 10vw;
}
.pagefind-ui.yellow {
--pagefind-ui-background: #efc302;
}
.pagefind-ui.red {
--pagefind-ui-background: #ffb9bb;
width: 50%;
}
.pagefind-ui .pagefind-ui__drawer:not(.pagefind-ui__hidden) {
position: absolute;
left: auto;
right: 0;
margin-top: 0px;
width: 50vw;
z-index: 9999;
overflow-y: auto;
box-shadow:
0 10px 10px -5px rgba(0, 0, 0, 0.2),
0 2px 2px 0 rgba(0, 0, 0, 0.1);
border-bottom-right-radius: var(--pagefind-ui-border-radius);
border-bottom-left-radius: var(--pagefind-ui-border-radius);
background-color: var(--pagefind-ui-background);
}
.pagefind-ui__result {
padding: 0 2em 1em !important;
}
.pagefind-ui .pagefind-ui__result-link {
color: var(--pagefind-ui-primary);
}
.pagefind-ui .pagefind-ui__result-excerpt {
color: var(--pagefind-ui-text);
}
@media (max-width: 1280px) {
.pagefind-ui {
display: none;
}
}
</style>