Search results
Faceted workspace search view with Docs/Files/People filter chips, live query matching and a split result preview pane.
pnpm dlx shadcn@latest add @haze/search-results---
import { FileCode2, FileText, Search, Users } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface SearchDoc {
id: string;
type: "Docs" | "People" | "Files";
title: string;
snippet: string;
updated: string;
preview: string;
}
interface Props {
id?: string;
initialQuery?: string;
results?: SearchDoc[];
class?: string;
}
const {
id = "haze-search-results",
initialQuery = "tokens",
results = [
{ id: "sr1", type: "Docs", title: "Color tokens and dark contrast", snippet: "All surfaces read semantic OKLCH tokens rather than raw palette classes.", updated: "2h ago", preview: "Haze UI defines 35 semantic tokens in tokens/haze.tokens.json and compiles them into src/styles/haze.css with verified WCAG 2.2 AA contrast ratios." },
{ id: "sr2", type: "Files", title: "tokens/haze.tokens.json", snippet: "Source of truth for background, card, popover, border border-frame and status tokens.", updated: "Yesterday", preview: "Defines 35 semantic surface, text, border border-frame and status tokens compiled into src/styles/haze.css." },
{ id: "sr3", type: "People", title: "Nina Patel · Design Systems", snippet: "Maintains semantic tokens, contrast checks and component specs.", updated: "Active", preview: "Owner of the token pipeline and WCAG contrast gate (148/148 pairs passing)." },
{ id: "sr4", type: "Docs", title: "Theming and custom brand accents", snippet: "Override --brand and --brand-border in your global CSS after importing haze.css.", updated: "3d ago", preview: "Swap --brand in :root to match your product accent while preserving accessible contrast on dark cards." },
],
class: className,
} = Astro.props;
const firstResult = results[0];
const facets = ["All", "Docs", "Files", "People"] as const;
---
<section aria-labelledby={`${id}-title`} data-haze-search-results class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}>
<div class="mx-auto max-w-5xl overflow-hidden rounded-2xl border border-border bg-card">
<header class="border-b border-border p-4 sm:p-5">
<h2 id={`${id}-title`} class="sr-only">Workspace search results</h2>
<div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
<div class="relative flex-1">
<Search class="pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-muted-foreground" aria-hidden="true" />
<label for={`${id}-q`} class="sr-only">Search workspace</label>
<input id={`${id}-q`} data-sr-input type="search" value={initialQuery} placeholder="Search docs, files, people…" class="h-10 w-full rounded-xl border border-frame-input bg-field pr-3 pl-9 text-sm text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden transition-[color,background-color,border-color,box-shadow] duration-150 hover:border-frame-foreground" />
</div>
<div role="group" aria-label="Filter by result type" class="flex flex-wrap gap-1">
{
facets.map((f, i) => (
<button
type="button"
data-sr-facet={f}
aria-pressed={i === 0 ? "true" : "false"}
class="inline-flex h-8 cursor-pointer items-center gap-1.5 rounded-lg border border-frame bg-field px-2.5 text-xs font-medium text-muted-foreground hover:text-foreground aria-pressed:border-border-strong aria-pressed:bg-accent aria-pressed:text-foreground focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75"
>
<span>{f}</span>
</button>
))
}
</div>
</div>
</header>
<div class="grid divide-y divide-border lg:grid-cols-[minmax(0,1.15fr)_minmax(0,0.85fr)] lg:divide-x lg:divide-y-0">
<div class="min-w-0 p-3 sm:p-4">
<ul role="list" class="grid gap-1.5">
{
results.map((r, i) => (
<li data-sr-row data-type={r.type} data-search={`${r.type} ${r.title} ${r.snippet}`.toLowerCase()}>
<button
type="button"
data-sr-pick={r.id}
data-sr-title={r.title}
data-sr-type={r.type}
data-sr-preview={r.preview}
aria-pressed={i === 0 ? "true" : "false"}
class="flex w-full cursor-pointer items-start gap-3 rounded-xl border border-transparent p-3 text-left transition-colors duration-150 hover:bg-accent aria-pressed:border-border-strong aria-pressed:bg-background/70 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring active:scale-[0.97] active:duration-75"
>
<span class="mt-0.5 grid size-7 shrink-0 place-items-center rounded-lg border border-frame bg-field text-muted-foreground" aria-hidden="true">
{r.type === "Docs" ? <FileText class="size-3.5" /> : r.type === "Files" ? <FileCode2 class="size-3.5 text-muted-foreground" /> : <Users class="size-3.5" />}
</span>
<span class="min-w-0 flex-1">
<span class="flex items-center justify-between gap-2">
<span class="truncate text-sm/5 font-medium text-foreground">{r.title}</span>
<span class="shrink-0 text-[0.6875rem] text-muted-foreground">{r.updated}</span>
</span>
<span class="mt-0.5 block line-clamp-2 text-xs/5 text-muted-foreground">{r.snippet}</span>
</span>
</button>
</li>
))
}
</ul>
</div>
<aside aria-label="Result preview" class="min-w-0 bg-muted/40 p-5">
<span data-sr-p-type hidden={!firstResult} class="rounded-md border border-border bg-card px-2 py-0.5 text-[0.6875rem] font-medium text-muted-foreground">{firstResult?.type}</span>
<h3 data-sr-p-title class={cn("text-base/6 font-semibold text-foreground", firstResult && "mt-3")}>{firstResult?.title ?? "No results available"}</h3>
<p data-sr-p-body hidden={!firstResult} class="mt-2 text-sm/6 text-pretty text-muted-foreground">{firstResult?.preview}</p>
<p data-sr-status role="status" class="mt-4 min-h-4 text-xs/4 text-muted-foreground">Showing {results.length} {results.length === 1 ? "result" : "results"}</p>
</aside>
</div>
</div>
</section>
<script>
function initSearchResults() {
document.querySelectorAll<HTMLElement>("[data-haze-search-results]").forEach((root) => {
if (root.hasAttribute("data-enhanced")) return;
root.setAttribute("data-enhanced", "");
const input = root.querySelector<HTMLInputElement>("[data-sr-input]");
const pType = root.querySelector<HTMLElement>("[data-sr-p-type]");
const pTitle = root.querySelector<HTMLElement>("[data-sr-p-title]");
const pBody = root.querySelector<HTMLElement>("[data-sr-p-body]");
const status = root.querySelector<HTMLElement>("[data-sr-status]");
let facet = "All";
const filter = () => {
const q = (input?.value ?? "").trim().toLowerCase();
let shown = 0;
root.querySelectorAll<HTMLElement>("[data-sr-row]").forEach((row) => {
const okFacet = facet === "All" || row.dataset.type === facet;
const okText = !q || (row.dataset.search ?? "").includes(q);
row.hidden = !(okFacet && okText);
if (okFacet && okText) shown++;
});
if (status) status.textContent = `Showing ${shown} result${shown === 1 ? "" : "s"}`;
};
input?.addEventListener("input", filter);
root.querySelectorAll<HTMLButtonElement>("[data-sr-facet]").forEach((btn) => {
btn.addEventListener("click", () => {
facet = btn.dataset.srFacet ?? "All";
root.querySelectorAll<HTMLButtonElement>("[data-sr-facet]").forEach((b) => b.setAttribute("aria-pressed", String(b === btn)));
filter();
});
});
root.querySelectorAll<HTMLButtonElement>("[data-sr-pick]").forEach((btn) => {
btn.addEventListener("click", () => {
root.querySelectorAll<HTMLButtonElement>("[data-sr-pick]").forEach((b) => b.setAttribute("aria-pressed", String(b === btn)));
if (pType) pType.textContent = btn.dataset.srType ?? "";
if (pTitle) pTitle.textContent = btn.dataset.srTitle ?? "";
if (pBody) pBody.textContent = btn.dataset.srPreview ?? "";
});
});
});
}
initSearchResults();
document.addEventListener("astro:page-load", initSearchResults);
</script>When to use
- Building a dedicated workspace search page with type facets and an inline preview pane
- Letting users inspect matched docs, files and people without leaving the results list
When not to use
- You want a modal quick-jump dialog rather than a full results page; use command-palette
Installation
Add the Haze registry to components.json once, then install Search results with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/search-resultsnpx shadcn@latest add @haze/search-resultsyarn dlx shadcn@latest add @haze/search-resultsbunx --bun shadcn@latest add @haze/search-resultsFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | "haze-search-results" | Unique prefix for search label and heading IDs. |
| initialQuery | string | "tokens" | Initial search query value. |
| results | SearchDoc[] | 4 mixed results | Searchable docs, files and people with preview copy. |
| class | string | – | Extra classes on the outer section. |
Keyboard interactions
- Tab
- Move across the search field, facet chips and result rows
- EnterSpace
- Filter by facet or load a result into the preview pane
Accessibility
- Facet buttons and result rows expose aria-pressed and update the labelled preview aside in place.
- Live match counts announce via a polite role="status" message.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI block "Search results" with `npx shadcn@latest add @haze/search-results`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import SearchResults from "@/components/haze/blocks/search-results.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/blocks/search-results.md
Customize with real content
Adapt the Haze search-results block for our product. Replace the demo values of these props with our real content: id, initialQuery, results, class. Keep the layout, the heading level rules and these accessibility details: Facet buttons and result rows expose aria-pressed and update the labelled preview aside in place. Live match counts announce via a polite role="status" message. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using search-results, check it fits: use it when building a dedicated workspace search page with type facets and an inline preview pane; letting users inspect matched docs, files and people without leaving the results list. Avoid it when you want a modal quick-jump dialog rather than a full results page; use command-palette. Alternatives: @haze/command-palette, @haze/ai-search-bar.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.