"use client"; import "./components/ui/tidal.css"; import { useId, useLayoutEffect, useMemo, useRef, useState } from "react"; import { TidalSearchResults, type TidalSearchResult, type TidalSearchResultGroup } from "./components/ui/search-results"; import "./components/ui/search-results.css"; const tidalExampleStyles = ".tidal-scope .search-results-demo,\n.tidal-scope .search-results-demo * {\n box-sizing: border-box;\n}\n\n.tidal-scope .search-results-demo {\n width: 100%;\n min-width: 0;\n container: search-results-demo / inline-size;\n}\n\n.tidal-scope .search-results-demo-frame {\n display: grid;\n min-width: 0;\n grid-template-columns: minmax(0, 1fr) minmax(250px, 0.38fr);\n gap: 14px;\n padding: 20px;\n border: 1px solid var(--t-border);\n border-radius: 22px;\n background: var(--t-subtle);\n color: var(--t-ink);\n}\n\n.tidal-scope .search-results-demo-detail {\n position: sticky;\n top: 14px;\n min-width: 0;\n min-height: 360px;\n align-self: start;\n padding: 24px;\n border: 1px solid var(--t-border);\n border-radius: 18px;\n background: var(--t-ink);\n color: var(--t-surface);\n scroll-margin-block: 18px;\n}\n\n.tidal-scope .search-results-demo-detail:focus-visible {\n outline: 2px solid var(--t-accent);\n outline-offset: 3px;\n}\n\n.tidal-scope .search-results-demo-detail > span {\n display: block;\n color: color-mix(in srgb, var(--t-surface) 62%, var(--t-ink));\n font-size: 11px;\n font-weight: 700;\n letter-spacing: 0.1em;\n line-height: 1.35;\n text-transform: uppercase;\n}\n\n.tidal-scope .search-results-demo-detail > strong {\n display: inline-block;\n margin-top: 24px;\n padding: 6px 8px;\n border: 1px solid color-mix(in srgb, var(--t-surface) 30%, var(--t-ink));\n border-radius: 7px;\n color: color-mix(in srgb, var(--t-surface) 74%, var(--t-ink));\n font-size: 11px;\n font-weight: 680;\n line-height: 1.25;\n overflow-wrap: anywhere;\n}\n\n.tidal-scope .search-results-demo-detail h3 {\n margin: 14px 0 0;\n font-size: clamp(25px, 4.5cqi, 38px);\n font-weight: 540;\n letter-spacing: -0.052em;\n line-height: 1.03;\n text-wrap: balance;\n overflow-wrap: anywhere;\n}\n\n.tidal-scope .search-results-demo-detail p {\n margin: 14px 0 0;\n color: color-mix(in srgb, var(--t-surface) 72%, var(--t-ink));\n font-size: 11px;\n line-height: 1.65;\n overflow-wrap: anywhere;\n}\n\n.tidal-scope .search-results-demo-detail dl {\n display: grid;\n gap: 1px;\n margin: 23px 0 0;\n overflow: hidden;\n border: 1px solid color-mix(in srgb, var(--t-surface) 22%, var(--t-ink));\n border-radius: 10px;\n background: color-mix(in srgb, var(--t-surface) 22%, var(--t-ink));\n}\n\n.tidal-scope .search-results-demo-detail dl > div {\n min-width: 0;\n padding: 10px 11px;\n background: var(--t-ink);\n}\n\n.tidal-scope .search-results-demo-detail dt {\n color: color-mix(in srgb, var(--t-surface) 58%, var(--t-ink));\n font-size: 11px;\n line-height: 1.35;\n}\n\n.tidal-scope .search-results-demo-detail dd {\n margin: 4px 0 0;\n font-size: 11px;\n line-height: 1.4;\n overflow-wrap: anywhere;\n}\n\n@container search-results-demo (max-width: 780px) {\n .tidal-scope .search-results-demo-frame {\n grid-template-columns: minmax(0, 1fr);\n padding: 10px;\n }\n\n .tidal-scope .search-results-demo-detail {\n position: static;\n min-height: 0;\n }\n}\n\n@container search-results-demo (max-width: 390px) {\n .tidal-scope .search-results-demo-frame {\n gap: 9px;\n padding: 7px;\n }\n\n .tidal-scope .search-results-demo-detail {\n padding: 20px 16px;\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n .tidal-scope .search-results-demo * {\n scroll-behavior: auto !important;\n }\n}"; type FilterId = "all" | "guides" | "components" | "references"; interface SampleResult { id: string; groupId: Exclude; groupLabel: string; title: string; description: string; typeLabel: string; meta: string; keywords: string; detail: string; actionKind: "link" | "button"; } const SAMPLE_RESULTS: readonly SampleResult[] = [ { id: "search-patterns", groupId: "guides", groupLabel: "Guides", title: "Search patterns for product teams", description: "Query language, empty states, and useful result summaries.", typeLabel: "Guide", meta: "8 min read", keywords: "query filters empty states product", detail: "Keep search scope, result counts, and recovery actions easy to find.", actionKind: "link", }, { id: "keyboard-guide", groupId: "guides", groupLabel: "Guides", title: "Keyboard review checklist", description: "Tab order, visible focus, and recovery after filtering.", typeLabel: "Guide", meta: "5 min read", keywords: "keyboard focus accessibility review", detail: "Check native controls and stable focus as search results change.", actionKind: "button", }, { id: "command-menu", groupId: "components", groupLabel: "Components", title: "Command menu", description: "A keyboard-friendly shortcut to actions and navigation.", typeLabel: "Component", meta: "Interactive", keywords: "command menu keyboard navigation", detail: "Find actions, recent pages, and shortcuts in one place.", actionKind: "link", }, { id: "filter-bar", groupId: "components", groupLabel: "Components", title: "Filter bar", description: "Selected filters and result counts in a compact toolbar.", typeLabel: "Component", meta: "Interactive", keywords: "filter chips counts selected state", detail: "Combine filters and remove them individually without losing context.", actionKind: "button", }, { id: "empty-state", groupId: "components", groupLabel: "Components", title: "Empty state section", description: "Helpful guidance when a search has no results.", typeLabel: "Component", meta: "Layout", keywords: "empty zero results recovery", detail: "Explain what happened and give people a clear next step.", actionKind: "link", }, { id: "query-syntax", groupId: "references", groupLabel: "References", title: "Query syntax", description: "Search by title, type, or status.", typeLabel: "Reference", meta: "12 terms", keywords: "syntax title type status reference", detail: "Use specific fields to narrow a search and find the right result.", actionKind: "button", }, { id: "result-schema", groupId: "references", groupLabel: "References", title: "Result record schema", description: "Titles, summaries, metadata, and destinations.", typeLabel: "Reference", meta: "Reference", keywords: "schema metadata destination typed data", detail: "A reference for the fields shown in each search result.", actionKind: "link", }, ]; const FILTERS: readonly { id: FilterId; label: string }[] = [ { id: "all", label: "All" }, { id: "guides", label: "Guides" }, { id: "components", label: "Components" }, { id: "references", label: "References" }, ]; export function SearchResultsDemo() { const generatedId = useId().replace(/:/g, ""); const detailId = `search-results-${generatedId}-detail`; const [query, setQuery] = useState(""); const [filterId, setFilterId] = useState("all"); const [selectedId, setSelectedId] = useState(SAMPLE_RESULTS[0].id); const [message, setMessage] = useState("Showing all results."); const inputRef = useRef(null); const resetFocusIntent = useRef(false); const normalizedQuery = query.trim().toLocaleLowerCase(); const queryMatches = useMemo( () => SAMPLE_RESULTS.filter((item) => `${item.title} ${item.description} ${item.keywords}` .toLocaleLowerCase() .includes(normalizedQuery), ), [normalizedQuery], ); const visible = useMemo( () => queryMatches.filter( (item) => filterId === "all" || item.groupId === filterId, ), [filterId, queryMatches], ); useLayoutEffect(() => { if (!resetFocusIntent.current) return; resetFocusIntent.current = false; inputRef.current?.focus({ preventScroll: true }); }, [filterId, query]); function selectResult(item: SampleResult) { setSelectedId(item.id); setMessage(`${item.title} opened.`); } const groups = useMemo(() => { return (["guides", "components", "references"] as const).flatMap( (groupId) => { const groupItems = visible.filter((item) => item.groupId === groupId); if (!groupItems.length) return []; const results: readonly TidalSearchResult[] = groupItems.map((item) => { const shared = { id: item.id, title: item.title, description: item.description, typeLabel: item.typeLabel, meta: item.meta, }; if (item.actionKind === "link") { return { ...shared, action: { kind: "link", accessibleLabel: `Open ${item.title}`, href: `#${detailId}`, onAction: () => selectResult(item), }, }; } return { ...shared, action: { kind: "button", accessibleLabel: `Preview ${item.title}`, onAction: () => selectResult(item), }, }; }); return [ { id: groupId, title: groupItems[0].groupLabel, accessibleLabel: `${groupItems.length} ${groupItems[0].groupLabel.toLocaleLowerCase()} results`, count: groupItems.length, results, }, ]; }, ); }, [detailId, visible]); const selected = SAMPLE_RESULTS.find((item) => item.id === selectedId) ?? SAMPLE_RESULTS[0]; const countFor = (id: FilterId) => queryMatches.filter((item) => id === "all" || item.groupId === id).length; return (
{ setQuery(value); setMessage( value ? `Searching for “${value}”.` : "Showing all results.", ); }, }} filters={FILTERS.map((filter) => ({ id: filter.id, label: filter.label, accessibleLabel: `Show ${filter.label.toLocaleLowerCase()} results, ${countFor(filter.id)}`, count: countFor(filter.id), }))} selectedFilterId={filterId} onFilterChange={(filter) => { setFilterId(filter.id as FilterId); setMessage( `Showing ${String(filter.label).toLocaleLowerCase()} results.`, ); }} groups={groups} resultCount={visible.length} resultCountLabel={(count, value) => value ? `${count} results for ${value}` : `${count} results` } emptyDescription="Try another search or reset the filters." emptyAction={{ label: "Reset search", accessibleLabel: "Reset search and focus the query field", onAction: () => { resetFocusIntent.current = true; setQuery(""); setFilterId("all"); setMessage("Search reset. Showing all results."); }, }} footer={ {message} Sample data. Changes stay in this preview. } />
Result detail {selected.typeLabel}

{selected.title}

{selected.detail}

Group
{selected.groupLabel}
Source
Library
); } export default function AgentExample() { return (
); }