A tiny, dependency-light React search UI powered by MiniSearch and Tailwind CSS. Exported components provide an inline search box and a keyboard-accessible search dialog suitable for docs, apps, and component libraries.
- Lightweight client-side full-text search using
minisearch. - Ready-to-use components:
InlineSearchandSearchDialog - Fully typed with TypeScript and exportable types .
- Tailwind CSS for styling; build step generates a distributable
styles.css.
Install peer dependencies in your project (React >= 17) and then add this package as a dependency. Example using pnpm:
pnpm add -D @ozbart/react-mini-searchExample documents (each document must have an id and title):
const docs = [
{ id: 1, title: 'Getting Started', description: 'Intro docs', url: '/getting-started' },
{ id: 2, title: 'API', description: 'Reference docs', url: '/api' },
]
import { InlineSearch, SearchDialog } from 'react-mini-search'
// Inline
<InlineSearch
documents={docs}
fields={["title", "description"]}
storeFields={["title", "description", "url"]}
placeholder="Search docs..."
onResultClick={(res) => { if (res.url) window.location.href = res.url }}
/>
// Dialog (provides a / Ctrl/Cmd+K keyboard shortcut)
<SearchDialog
documents={docs}
fields={["title", "description"]}
storeFields={["title", "description", "url"]}
placeholder="Search documentation..."
onResultSelect={(res) => console.log('selected', res)}
/>Exports (from src/index.ts):
InlineSearch— Inline search component.SearchDialog— Modal search dialog with keyboard shortcut and selectable results.SearchTrigger— Small trigger component (bar/button) for opening the dialog.- Types:
Document,Result,UseSearchProps.
Types and important props (summary):
-
Document
id(string | number) — requiredtitle(string) — required- optional fields:
url,description,category,icon, and any metadata
-
UseSearchProps
documents: T[]— array of documentsfields: (keyof T)[]— fields to index/searchstoreFields: (keyof T)[]— fields to include in search resultssearchOptions?: MiniSearch.SearchOptions— pass-through to MiniSearch
-
SearchComponentProps (used by
InlineSearchandSearchDialog)placeholder?: stringonResultClick?: (result) => void—InlineSearchonResultSelect?: (result) => void—SearchDialogdebounceMs?: number— default 300minQueryLength?: number— default 2showClearButton?: booleanemptyStateMessage?: stringloadingMessage?: stringclassName?: string,resultClassName?: string,renderResult?: (result) => React.ReactNode
For full prop and type details see src/lib/type.ts.
Scripts are defined in package.json and expect pnpm:
pnpm build— build JS (viatsup) and CSS (tailwind) todist/.pnpm build:js— build JS only.pnpm build:css— build Tailwind CSS todist/styles.css.pnpm format— format with Biome.pnpm check— run biome checks.
Example local build:
pnpm install
pnpm buildThe package exposes dist/index.mjs and dist/index.d.ts. A styles.css build artifact is available at dist/styles.css and can be imported directly:
import 'react-mini-search/styles.css'- MiniSearch runs in the browser and keeps an in-memory index. It's great for small to medium-sized datasets. For very large datasets prefer a server-side search service.
- Ensure
fieldsandstoreFieldsare chosen to include searchable text and any metadata your render functions use. - The
SearchDialoglistens forCtrl/Cmd + Kto open. If you have another global shortcut, adapt or disable it.
Contributions are welcome. Open issues or PRs for bug fixes, small features, or documentation improvements.