Skip to content

Commit 9a1c990

Browse files
authored
docs(search): add JSDoc header to search.jsx (#216) (#231)
## Description This PR adds JSDoc headers to the search.jsx component and its sub-components to improve code documentation and developer experience. ## Related Issue Fixes #216
1 parent fc9c0b0 commit 9a1c990

1 file changed

Lines changed: 57 additions & 11 deletions

File tree

src/components/islands/search.jsx

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/**
2+
* Search Component - Dictionary Search Interface with Keyboard Navigation
3+
*
4+
* @exports Search - Main search component with FlexSearch integration, modal state, and dictionary indexing
5+
* @exports SearchTrigger - Trigger button/input with responsive variants and keyboard shortcut hints
6+
* @exports SearchDialog - Modal search interface with input field, keyboard navigation, and live results
7+
* @exports SearchInfo - Default placeholder component when no input is provided
8+
* @exports SearchResult - Search results list with cursor navigation and jAI fallback
9+
*/
10+
111
import { buildWordPathname, buildWordSlug } from "../../lib/utils/index.js";
212
import Flexsearch from "flexsearch";
313
import { useEffect, useState } from "react";
@@ -19,8 +29,15 @@ const searchIndex = new Flexsearch.Document({
1929
});
2030

2131
/**
22-
* Search Component Island
23-
* @param {{ triggerSize: "sm" | "md", dictionary: MarkdownInstance<Record<string, any>>[] }} props
32+
* Main Search Component Island
33+
* Integrates FlexSearch indexing with dictionary entries,
34+
* controls modal state, and renders trigger + dialog.
35+
*
36+
* @component
37+
* @param {Object} props
38+
* @param {"sm" | "md"} props.triggerSize - Size of the search trigger
39+
* @param {MarkdownInstance<Record<string, any>>[]} props.dictionary - Words to index and search
40+
* @returns {JSX.Element}
2441
*/
2542
export default function Search({ triggerSize, dictionary }) {
2643
const isSearchOpen = useStore($isSearchOpen);
@@ -46,8 +63,15 @@ export default function Search({ triggerSize, dictionary }) {
4663
}
4764

4865
/**
49-
* Search Trigger
50-
* @param {{size: "sm" | "md"}} props
66+
* Search Trigger Component
67+
*
68+
* Responsive trigger button/input that opens the search dialog.
69+
* Displays keyboard shortcut hint (Ctrl+K or ⌘K).
70+
*
71+
* @component
72+
* @param {Object} props
73+
* @param {"sm" | "md"} [props.size="md"] - Trigger size variant
74+
* @returns {JSX.Element}
5175
*/
5276
function SearchTrigger({ size = "md" }) {
5377
const isSearchOpen = useStore($isSearchOpen);
@@ -153,9 +177,16 @@ function SearchTrigger({ size = "md" }) {
153177
}
154178

155179
/**
156-
* Search Dialog
157-
* @todo implement search term debouncing
158-
* @todo implement visual que buttons (↑ ↓ ↵) for keyboard navigation on search dialog component
180+
* Search Dialog Component
181+
*
182+
* Full-screen modal interface with search input,
183+
* FlexSearch results, AI fallback, and keyboard navigation.
184+
*
185+
* @component
186+
* @returns {JSX.Element}
187+
*
188+
* @todo Implement search term debouncing
189+
* @todo Implement visual que buttons (↑ ↓ ↵) for keyboard navigation on search dialog component
159190
*/
160191
function SearchDialog() {
161192
useLockBody();
@@ -279,8 +310,14 @@ function SearchDialog() {
279310
}
280311

281312
/**
282-
* Default Search Text Placeholder
283-
* @todo implement recent search term list
313+
* Search Info Component
314+
*
315+
* Placeholder text shown when no search term is entered.
316+
*
317+
* @component
318+
* @returns {JSX.Element}
319+
*
320+
* @todo Implement recent search term list
284321
*/
285322
const SearchInfo = () => (
286323
<p className="block w-full text-sm md:text-base px-2 py-1 md:px-4 md:py-2 text-slate-500 font-normal leading-6">
@@ -289,8 +326,17 @@ const SearchInfo = () => (
289326
);
290327

291328
/**
292-
* Search result
293-
* @param {{ result: Array<{ id: number, doc: { title: string, slug: string }, searchTerm: string }> }} props
329+
* Search Result Component
330+
*
331+
* Displays FlexSearch results or jAI fallback when no matches are found.
332+
* Supports cursor-based keyboard navigation.
333+
*
334+
* @component
335+
* @param {Object} props
336+
* @param {Array<{ id: number, doc: { title: string, slug: string } }>} props.result - Search results
337+
* @param {number} props.cursor - Current cursor index for keyboard navigation
338+
* @param {string} props.searchTerm - Current search input
339+
* @returns {JSX.Element}
294340
*/
295341
function SearchResult({ result = [], cursor, searchTerm }) {
296342
const router = useRouter();

0 commit comments

Comments
 (0)