Skip to content
Files SDK
Esc
↑↓navigate↵open⌘Jpreview
On this page

File Search

A search box that lists matching keys with substring, glob, regex and exact match modes plus a case-sensitivity toggle - driven by useFiles.

Runs search() and lists the matches. Switch between substring, glob, regex and exact matching and toggle case sensitivity; a failed search (an invalid regex, a gateway error) is shown inline, and a search still in flight is aborted when the component unmounts.

"use client";

import { useState } from "react";

import { demoFiles } from "@/lib/demo-files";
import { FileSearch } from "@/registry/files-sdk/file-search/file-search";

const Example = () => {
  const files = demoFiles;
  const [selected, setSelected] = useState<string>();

  return (
    <div className="flex flex-col gap-3">
      <FileSearch files={files} onSelect={(file) => setSelected(file.key)} />
      {selected && (
        <p className="text-muted-foreground text-xs">Selected: {selected}</p>
      )}
    </div>
  );
};

export default Example;

Installation

npx shadcn@latest add https://files-sdk.dev/r/file-search.json

Usage

import { useFiles } from "files-sdk/react";

import { FileSearch } from "@/components/files-sdk/file-search";

export function Search() {
  const files = useFiles({ endpoint: "/api/files" });

  return (
    <FileSearch
      files={files}
      prefix="docs/"
      defaultMatch="glob"
      onSelect={(file) => console.log(file.key)}
    />
  );
}

Matching runs over keys, not contents — the same four modes search() exposes. Scope a search with prefix to keep it cheap on large buckets, and maxResults caps how many matches are collected per run.

Props

PropType
filesUseFilesResult

A `useFiles()` instance — matches are found through `search()`.

TypeUseFilesResult
prefix?string

Limit the search to keys under this prefix.

Typestring
defaultMatch?SearchMatch

Match mode shown first. Default `"substring"`.

TypeSearchMatch
maxResults?number

Cap on results collected per search. Default `100`.

Typenumber
onSelect?(file: StoredFile) => void

Called when a result row is clicked.

Type(file: StoredFile) => void
className?string
Typestring

Was this page helpful?