Skip to content
caliper ui docs

Components

Search

A search field with a clear button and the right keyboard on phones.

Free
pnpm dlx shadcn@latest add @caliper/search

Directory

Halden · 6 people

  • Priya RamanAdmin
  • Rafael AbreuFinance
  • Kiara MurayamaOperations
  • Lena FischerDesign

Showing 4 of 6.

Installs components/ui/search.tsxDepends on @radix-ui/react-slot, lucide-reactMotion none in component source

When to use

Use it for

  • Filtering a list or directory as people type.
  • Pair it with a visible result count.

Skip it when

  • Global search across the app; use a command palette.

Installation

terminal
pnpm dlx shadcn@latest add @caliper/search

Adds its 4 files to components/ui/, each with its own stylesheet, and installs their packages. No account needed. The first part also adds Caliper UI’s tokens; import them once as in Installation.

Usage

This is the code behind the preview above.

example.tsx
import { useState, type ReactNode } from "react"
import { Avatar } from "@/components/ui/avatar"
import { Search } from "@/components/ui/search"
import { cn } from "@/components/ui/lib/cn"

function Panel({ title, context, media, action, className, children }: { title: string; context: string; media?: ReactNode; action?: ReactNode; className?: string; children?: ReactNode }) {
  return (
    <section className={cn("grid w-full max-w-md gap-5 rounded-overlay border border-border bg-background p-6 shadow-resting", className)}>
      <div className="flex items-center gap-3">
        {media}
        <div className="grid min-w-0 flex-1 gap-1">
          <p className="font-medium">{title}</p>
          <p className="text-sm text-muted-foreground">{context}</p>
        </div>
        {action}
      </div>
      {children}
    </section>
  );
}

const directory = [
  ["Priya Raman", "Admin"],
  ["Rafael Abreu", "Finance"],
  ["Kiara Murayama", "Operations"],
  ["Lena Fischer", "Design"],
  ["Elias Kim", "Engineering"],
  ["Noor Haddad", "Engineering"],
] as const;

export function DirectorySearch() {
  const [query, setQuery] = useState("");
  const found = directory.filter(([name, role]) => `${name} ${role}`.toLowerCase().includes(query.trim().toLowerCase()));
  return (
    <Panel title="Directory" context={`Halden · ${directory.length} people`} className="max-w-sm">
      <Search value={query} onChange={(event) => setQuery(event.currentTarget.value)} onClear={() => setQuery("")} placeholder="Name or role" aria-label="Search the directory" />
      <ul className="grid min-h-40 content-start gap-3">
        {found.slice(0, 4).map(([name, role]) => (
          <li key={name} className="flex items-center gap-3 text-sm">
            <Avatar name={name} alt="" className="size-7" />
            <span className="flex-1 font-medium">{name}</span>
            <span className="text-muted-foreground">{role}</span>
          </li>
        ))}
      </ul>
      <p role="status" className="text-sm text-muted-foreground">{query ? `${found.length} of ${directory.length} match “${query}”.` : `Showing 4 of ${directory.length}.`}</p>
    </Panel>
  );
}

API reference

Accessibility

It is built on native elements and keeps aria-hidden and aria-label in step with state.

No custom key handling; Tab and the native activation keys do the work.

Motion

It declares no animation in its component source. Any transition comes from its stylesheet, which uses the duration tokens that collapse to instant under prefers-reduced-motion.

All Identity & navigation examples