11---
22import ButtonLink from " ../button-link/button-link.astro" ;
33import HeaderButton from " ./header-button.astro" ;
4+ import Search from " astro-pagefind/components/Search" ;
45
56export interface Props {
67 mobile? : boolean ;
@@ -12,6 +13,13 @@ const IS_LIVE = false;
1213---
1314
1415<div class =" ml-auto flex items-center space-x-4" >
16+ <Search id =" search" className =" pagefind-ui" uiOptions ={ {
17+
18+ showImages: false ,
19+ translations: {
20+ zero_results: " Couldn't find [SEARCH_TERM]"
21+ }
22+ }} />
1523 {
1624 ! mobile ? (
1725 <>
@@ -34,3 +42,120 @@ const IS_LIVE = false;
3442 </HeaderButton >
3543 </label >
3644</div >
45+ <script >
46+ document.addEventListener("DOMContentLoaded", function () {
47+ const searchContainer = document.querySelector(".pagefind-ui");
48+ const searchClear = document.querySelector(".pagefind-ui__search-clear");
49+ const searchInput = searchContainer?.querySelector("input");
50+ let selectedIndex = -1;
51+
52+ function updateSelection() {
53+ const results = searchContainer?.querySelectorAll(".pagefind-ui__result");
54+ if (!results) return;
55+
56+ results.forEach((result, index) => {
57+ if (index === selectedIndex) {
58+ result.classList.add("selected");
59+ result.scrollIntoView({ block: "nearest", behavior: "smooth" });
60+ } else {
61+ result.classList.remove("selected");
62+ }
63+ });
64+ }
65+
66+ document.addEventListener("keydown", function (event) {
67+ if (!searchContainer || !searchInput) return;
68+
69+ const results = searchContainer.querySelectorAll(".pagefind-ui__result");
70+ if (document.activeElement === searchInput) {
71+ if (event.key === "ArrowDown") {
72+ event.preventDefault();
73+ selectedIndex = (selectedIndex + 1) % results.length;
74+ updateSelection();
75+ } else if (event.key === "ArrowUp") {
76+ event.preventDefault();
77+ selectedIndex = (selectedIndex - 1 + results.length) % results.length;
78+ updateSelection();
79+ } else if (event.key === "Enter" && selectedIndex >= 0) {
80+ event.preventDefault();
81+ results[selectedIndex].querySelector("a")?.click();
82+ }
83+ }
84+ });
85+
86+ // Reset selection when the search query changes
87+ searchInput?.addEventListener("input", function () {
88+ selectedIndex = -1;
89+ });
90+
91+ });
92+ </script >
93+ <style is:global >
94+ .pagefind-ui__result.selected {
95+ background-color: #f5f5f5;
96+ background-image: linear-gradient(to right, #3684B6 7px, transparent 5px);
97+ -webkit-transform: translate3d(0, 0, 0);
98+ transform: translate3d(0, 0, 0);
99+ }
100+ .pagefind-ui__drawer {
101+ }
102+ .pagefind-ui__message {
103+ margin: 1em;
104+ }
105+ .pagefind-ui__result mark {
106+ background: #F9EB5D;
107+ background-image: linear-gradient(to right, #F9EB5D 10%, #FCF4A7 100%);
108+ margin: 4px;
109+ padding-right: 6px;
110+ padding-left: 6px;
111+ padding-top: 2px;
112+ padding-bottom: 2px;
113+ color: #000000;
114+ font-family: monospace;
115+ border-radius: 4px;
116+ }
117+ .pagefind-ui {
118+ --pagefind-ui-scale: 1;
119+ --pagefind-ui-primary: #141f36;
120+ --pagefind-ui-text: black;
121+ --pagefind-ui-border: #d8d8d8;
122+ --pagefind-ui-border-width: 2px;
123+ --pagefind-ui-border-radius: 0;
124+ width: 50%;
125+ }
126+ .pagefind-ui.yellow {
127+ --pagefind-ui-background: #efc302;
128+ }
129+ .pagefind-ui.red {
130+ --pagefind-ui-background: #ffb9bb;
131+ width: 50%;
132+ }
133+ .pagefind-ui .pagefind-ui__drawer:not(.pagefind-ui__hidden) {
134+ position: absolute;
135+ left: auto;
136+ right: 0;
137+ margin-top: 0px;
138+ width:50vw;
139+ z-index: 9999;
140+ overflow-y: auto;
141+ box-shadow: 0 10px 10px -5px rgba(0, 0, 0, 0.2), 0 2px 2px 0 rgba(0, 0, 0, 0.1);
142+ border-bottom-right-radius: var(--pagefind-ui-border-radius);
143+ border-bottom-left-radius: var(--pagefind-ui-border-radius);
144+ background-color: var(--pagefind-ui-background);
145+ }
146+ .pagefind-ui__result{
147+ padding: 0 2em 1em !important;
148+ }
149+ .pagefind-ui .pagefind-ui__result-link {
150+ color: var(--pagefind-ui-primary);
151+ }
152+ .pagefind-ui .pagefind-ui__result-excerpt {
153+ color: var(--pagefind-ui-text);
154+ }
155+ @media (max-width: 1280px) {
156+ .pagefind-ui {
157+ display:none;
158+ }
159+ }
160+
161+ </style >
0 commit comments