# Search Box (Lumen Halo): prompt.md (v1.0.0)

- id: `lumen-search-box` · version 1.0.0 · component · free
- category: Inputs
- build: Base UI (one set of files; its dependencies follow the build)
- install (this build): `npx shadcn@latest add https://beautiful-ui.dev/r/lumen-search-box.json`
- npm dependencies: none
- registry dependencies: utils, @beautiful-ui/lumen-input-group, https://beautiful-ui.dev/r/lumen-foundation.json
- docs: https://beautiful-ui.dev/components/lumen-search-box
- The install command carries everything this item needs (files, CSS, tokens, npm and registry dependencies). Prefer it to copying source by hand.

A search field that says what it found: the count of results sits in the field (a short run of cells while they load), Escape clears and then leaves, and the count is announced once it settles. The ⌘K shortcut is opt-in, so it never fights your command palette.

## Build it
- Stack: React 19 (`ref` is a plain prop), TypeScript, Tailwind CSS v4 utilities, a shadcn-initialised project with the `@/*` alias.
- Packages: none beyond React.
- Files: `components/ui/lumen/controls/search-box.tsx`.
- Registry dependencies, installed with it automatically: shadcn `utils` (cn), `lumen-input-group`, `lumen-foundation`.
- Builds: one set of files for both, but its dependencies come in Base UI and Radix builds. Install the one that matches the project (see Install): a free item's bare URL installs the Base UI build of it and its dependencies.
- Exports to keep: `SearchBox`, and every exported type.
- CSS: the install merges this item's rules (the registry `css` field) into your global stylesheet, in `@layer components`, and adds the lumen foundation (tokens, keyframes, motion levels) once. Nothing to import by hand.
- Re-running `add` (or `--overwrite`) re-applies those rules: put overrides in your own CSS, never in the installed rules.
- Tokens: retheme with the `--lumen-*` custom properties (`--lumen-accent`, `--lumen-accent-foreground`, `--lumen-accent-text`, `--lumen-bad`, `--lumen-bad-text`, `--lumen-chart-accent`, `--lumen-chart-accent-foreground`, `--lumen-chart-accent-text`, `--lumen-focus`, `--lumen-good`, `--lumen-good-text`, `--lumen-hairline`, `--lumen-ink`, `--lumen-muted-ink`, `--lumen-series-1`, `--lumen-series-2`, `--lumen-series-3`, `--lumen-series-4`, `--lumen-series-5`, `--lumen-series-6`, `--lumen-warn`, `--lumen-warn-text`); this item's CSS also reads `--lumen-font-mono`, `--lumen-radius-k`. Never add Tailwind colour classes inside the component.

```tsx
import { SearchBox } from "@/components/ui/lumen/controls/search-box";
```

## Parts

| Part | data-slot | What it is for |
|---|---|---|
| `SearchBox` | — | The field. |

## Sound
- Keep every `data-slot` and `data-sound` attribute: the sound layer reads them.
- Installing this item adds no audio. Nothing plays until the app mounts `GlassSoundProvider` once (install: `npx shadcn@latest add https://beautiful-ui.dev/r/glass-sound.json`, import from `@/components/beautiful-ui/glass-sound`); `GlassSoundToggle` is its mute control. Without a provider the audio engine never loads.

## Match the original
- Read `components/ui/lumen/controls/search-box.tsx` as the reference implementation before changing or recreating anything, and match it: sizes, colours per theme, motion timings, copy and behaviour.
- If you deviate (a prop you can't honour, a style you changed, a dependency you swapped), say so in your reply, part by part.
- Keep the accessibility contract, the keyboard map and the motion levels listed below.

## Use it when
- search field, search input, filter list, search box, find, clear search, result count, Lumen
- Filtering a list, table or page as people type
- A search page's main field

### Not when
- Searching the whole app from anywhere: use Command Palette or Global Search

## Mistakes
- Pass resultCount from the filtered list, not the whole list

## Usage

```tsx
"use client";

import * as React from "react";
import { SearchBox } from "@/components/ui/lumen/controls/search-box";

export function People({ people }: { people: { name: string }[] }) {
  const [q, setQ] = React.useState("");
  const found = people.filter((p) => p.name.toLowerCase().includes(q.toLowerCase()));
  return <SearchBox value={q} onValueChange={setQ} resultCount={found.length} placeholder="Search people" />;
}
```

## Props

| Prop | Type | Default | What it does |
|---|---|---|---|
| `value / defaultValue / onValueChange` | `string` |  | Controlled or not. |
| `resultCount` | `number` |  | How many results the query found: shown in the field, announced once it settles. |
| `loading` | `boolean` | `false` | A run of cells replaces the count while results load. |
| `onSubmit` | `(query: string) => void` |  | Enter. |
| `shortcut` | `boolean` | `false` | Focus with ⌘K / Ctrl K and show the hint. |
| `resultLabel` | `(count) => string` | `"n results"` | The spoken words, for other languages. |
| `...input props` | `input attributes` |  | placeholder, name, disabled, aria-label (default "Search") and so on. |

Full docs: https://beautiful-ui.dev/components/lumen-search-box

## Customising
- Colours: set the `--lumen-*` tokens on `:root`, or on a container with the `lumen-scope` class to retheme one area. Add the `lumen-inherit` class to follow your shadcn palette instead (`--chart-N`, `--destructive`).
- Dark mode follows the `.dark` class on an ancestor (the shadcn and next-themes convention).
- Update later by re-running the install with `--overwrite` (review the diff if you edited it). Changelog: https://beautiful-ui.dev/r/changelog.json

## Keyboard

| Keys | Action |
|---|---|
| Escape | Clear; again to leave |
| Enter | onSubmit |
| ⌘K / Ctrl K | Focus (when shortcut is on) |

## Motion inventory

| Interaction | What moves |
|---|---|
| Results | The count ticks in from above when it changes; four cells scan while loading |

## Accessibility contract (preserve when editing)
- A <search> landmark with a labelled search input
- The count is announced after typing settles, not on every key
- Escape clears, then leaves the field

## Install

Base UI project (a base-* style in components.json):

```bash
npx shadcn@latest add https://beautiful-ui.dev/r/lumen-search-box.json
```

Radix project (a radix-*, new-york or default style):

```bash
npx shadcn@latest add https://beautiful-ui.dev/r/radix-nova/lumen-search-box.json
```

Or add the `@beautiful-ui` registry to components.json and run `npx shadcn@latest add @beautiful-ui/lumen-search-box`: the CLI picks the build from your style.

## Credits
- Built on shadcn/ui (https://ui.shadcn.com)

## Source (Base UI build)

### components/ui/lumen/controls/search-box.tsx

```tsx
"use client";
// Generated from src/registry/core/controls/search-box.tsx by scripts/gen-systems.ts. Edit the core file, not this one.

import * as React from "react";
import { cn } from "@/lib/utils";
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from "@/components/ui/lumen/input-group";

/*
 * Search Box: a search field that says what it found. Type and the trailing cell shows the count of
 * results you pass (a short run of cells while they load); Escape clears, a second Escape leaves.
 * The count is announced once it settles, not on every keystroke. The ⌘K / Ctrl K shortcut is opt-in,
 * so it never fights your command palette.
 *
 *   <SearchBox value={q} onValueChange={setQ} resultCount={rows.length} loading={isFetching} />
 */

const subscribe = () => () => {};
const isMac = () => /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent);

function SearchIcon() {
  return (
    <svg aria-hidden viewBox="0 0 16 16" className={`lumen-search-box-icon`}>
      <circle cx="7" cy="7" r="4.5" />
      <path d="M10.4 10.4L13.5 13.5" />
    </svg>
  );
}

function SearchBox({
  value: valueProp,
  defaultValue,
  onValueChange,
  onSubmit,
  resultCount,
  resultLabel = (n: number) => (n === 1 ? "1 result" : `${n} results`),
  loading = false,
  shortcut = false,
  placeholder = "Search",
  disabled,
  className,
  inputClassName,
  onKeyDown,
  onChange,
  readOnly,
  "aria-describedby": describedBy,
  "aria-label": ariaLabel = "Search",
  ref,
  ...props
}: Omit<React.ComponentProps<"input">, "value" | "defaultValue" | "type" | "onSubmit" | "size"> & {
  value?: string | undefined;
  defaultValue?: string | undefined;
  onValueChange?: ((value: string) => void) | undefined;
  /** Enter: called with the query. */
  onSubmit?: ((query: string) => void) | undefined;
  /** How many results the current query found. Shown in the field and announced once it settles. */
  resultCount?: number | undefined;
  /** The words for a count, for other languages. Default "1 result" / "n results". */
  resultLabel?: (count: number) => string;
  /** Results are loading: a run of cells replaces the count. */
  loading?: boolean | undefined;
  /** Focus with ⌘K / Ctrl K and show the hint. Off by default. */
  shortcut?: boolean | undefined;
  /** Classes for the input itself (className goes on the field). */
  inputClassName?: string | undefined;
}) {
  const [own, setOwn] = React.useState(defaultValue ?? "");
  const value = valueProp ?? own;
  const input = React.useRef<HTMLInputElement | null>(null);
  // The caller's ref and ours, both kept; a React 19 callback ref's cleanup is passed back.
  const setInput = React.useCallback(
    (node: HTMLInputElement | null) => {
      input.current = node;
      if (typeof ref === "function") return ref(node) ?? undefined;
      if (ref) ref.current = node;
      return undefined;
    },
    [ref],
  );
  const mac = React.useSyncExternalStore(subscribe, isMac, () => false);
  const statusId = React.useId();

  const setValue = (next: string) => {
    if (valueProp === undefined) setOwn(next);
    onValueChange?.(next);
  };

  // The announcement waits for typing and loading to settle (600ms), so a reader hears one count.
  const [announced, setAnnounced] = React.useState("");
  React.useEffect(() => {
    if (loading || resultCount === undefined || !value) return;
    const t = setTimeout(() => setAnnounced(resultLabel(resultCount)), 600);
    return () => clearTimeout(t);
  }, [loading, resultCount, value, resultLabel]);

  React.useEffect(() => {
    if (!shortcut || disabled) return;
    const onKey = (e: KeyboardEvent) => {
      if (e.defaultPrevented || e.key.toLowerCase() !== "k" || !(e.metaKey || e.ctrlKey)) return;
      e.preventDefault();
      input.current?.focus();
      input.current?.select();
    };
    window.addEventListener("keydown", onKey);
    return () => window.removeEventListener("keydown", onKey);
  }, [shortcut, disabled]);

  const has = value.length > 0;
  const showCount = has && !loading && resultCount !== undefined;

  return (
    <search data-slot="search-box" data-loading={loading || undefined} className={cn(`lumen-search-box`, className)}>
      <InputGroup>
        <InputGroupAddon>
          <SearchIcon />
        </InputGroupAddon>
        <InputGroupInput
          {...props}
          ref={setInput}
          type="search"
          value={value}
          placeholder={placeholder}
          disabled={disabled}
          aria-label={ariaLabel}
          aria-describedby={[describedBy, resultCount !== undefined ? statusId : null].filter(Boolean).join(" ") || undefined}
          aria-busy={loading || undefined}
          aria-keyshortcuts={shortcut ? (mac ? "Meta+K" : "Control+K") : undefined}
          autoComplete="off"
          spellCheck={false}
          className={cn(`lumen-search-box-input`, inputClassName)}
          readOnly={readOnly}
          onChange={(e) => {
            onChange?.(e);
            setValue(e.target.value);
          }}
          onKeyDown={(e) => {
            onKeyDown?.(e);
            // While an input method composes, Enter and Escape belong to it.
            if (e.defaultPrevented || e.nativeEvent.isComposing || e.keyCode === 229) return;
            if (e.key === "Escape") {
              e.preventDefault();
              if (has && !readOnly && !disabled) setValue("");
              else e.currentTarget.blur();
            } else if (e.key === "Enter") onSubmit?.(value);
          }}
        />
        <InputGroupAddon align="inline-end">
          {loading && has ? (
            <span aria-hidden className={`lumen-search-box-scan`}>
              <i />
              <i />
              <i />
              <i />
            </span>
          ) : showCount ? (
            <span key={resultCount} aria-hidden className={`lumen-search-box-count`} data-zero={resultCount === 0 || undefined}>
              {resultCount}
            </span>
          ) : !has && shortcut ? (
            <kbd aria-hidden className={`lumen-search-box-kbd`}>
              {mac ? "⌘" : "Ctrl"} K
            </kbd>
          ) : null}
          {has && !readOnly && !disabled && (
            <InputGroupButton
              size="icon-xs"
              aria-label="Clear search"
              className={`lumen-search-box-clear`}
              onClick={() => {
                setValue("");
                input.current?.focus();
              }}
            >
              <svg aria-hidden viewBox="0 0 16 16">
                <path d="M4.5 4.5l7 7M11.5 4.5l-7 7" />
              </svg>
            </InputGroupButton>
          )}
        </InputGroupAddon>
      </InputGroup>
      <span id={statusId} role="status" className={`lumen-sr`}>
        {has ? announced : ""}
      </span>
    </search>
  );
}

export { SearchBox };
```

### CSS (the registry `css` / `cssVars`, merged into the global stylesheet by the shadcn CLI)

```css
@layer components {
  .lumen-search-box {
    display: block;
    width: 100%;
    min-width: 0;
  }
  .lumen-search-box-icon {
    width: 15px;
    height: 15px;
    fill: none;
    stroke: var(--gc-sec);
    stroke-width: 1.6;
    stroke-linecap: round;
  }
  .lumen-search-box-input::-webkit-search-cancel-button {
    appearance: none;
  }
  .lumen-search-box-count {
    display: inline-flex;
    align-items: center;
    height: 20px;
    padding: 0 6px;
    border-radius: calc(6px * var(--lumen-radius-k, 1));
    background: color-mix(in srgb,var(--gc-ink) 7%,transparent);
    font: 500 11px/1 var(--lumen-font-mono, var(--font-mono, var(--font-geist-mono, 'Geist Mono'))), ui-monospace, monospace;
    font-variant-numeric: tabular-nums;
    color: var(--gc-ink);
    animation: lumen-search-tick calc(.32s * var(--gcp-k)) cubic-bezier(.2,.8,.2,1) both;
  }
  .lumen-search-box-count[data-zero] {
    color: var(--gc-sec);
  }
  @keyframes lumen-search-tick {
    from {
      opacity: 0;
      transform: translateY(-5px);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }
  .lumen-search-box-scan {
    display: inline-flex;
    gap: 2px;
    padding: 0 4px;
  }
  .lumen-search-box-scan>i {
    width: 4px;
    height: 8px;
    border-radius: calc(1px * var(--lumen-radius-k, 1));
    background: var(--gc-cellOff);
    animation: lumen-search-scan 1s ease-in-out infinite;
  }
  .lumen-search-box-scan>i:nth-child(2) {
    animation-delay: .12s;
  }
  .lumen-search-box-scan>i:nth-child(3) {
    animation-delay: .24s;
  }
  .lumen-search-box-scan>i:nth-child(4) {
    animation-delay: .36s;
  }
  @keyframes lumen-search-scan {
    0%,100% {
      background: var(--gc-cellOff);
    }
    35% {
      background: var(--gc-ink);
    }
  }
  .lumen-search-box-kbd {
    display: inline-flex;
    align-items: center;
    height: 20px;
    padding: 0 6px;
    border-radius: calc(6px * var(--lumen-radius-k, 1));
    box-shadow: inset 0 0 0 1px var(--gc-hair);
    font: 500 10.5px/1 var(--lumen-font-mono, var(--font-mono, var(--font-geist-mono, 'Geist Mono'))), ui-monospace, monospace;
    color: var(--gc-sec);
  }
  .lumen-search-box-clear svg {
    width: 12px;
    height: 12px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
  }
  @media (prefers-reduced-motion:reduce) {
    .lumen-search-box-count {
      animation: none;
    }
    .lumen-search-box-scan>i {
      animation: none;
      background: var(--gc-sec);
    }
  }
}
```

The lumen foundation (the tokens listed above, keyframes and motion levels) installs once with the first component; its CSS is public at https://beautiful-ui.dev/r/lumen-foundation.json.
