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

File Actions

A per-file actions menu - download, copy, rename, move and delete - driven by useFiles, with destination prompts and delete confirmation.

A ⋯ menu that routes every action through the useFiles() instance you pass in: download(), copy(), move() (rename is just a move that keeps the parent prefix) and delete(). Copy, rename and move open a small prompt for the destination key; delete confirms first.

"use client";

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

const Example = () => {
  const files = demoFiles;

  return (
    <div className="border-border flex w-full max-w-sm items-center justify-between gap-4 rounded-lg border p-3">
      <span className="truncate text-sm font-medium">photos/sunset.jpg</span>
      <FileActions files={files} fileKey="photos/sunset.jpg" />
    </div>
  );
};

export default Example;

Installation

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

Usage

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

import { FileActions } from "@/components/files-sdk/file-actions";

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

  return <FileActions files={files} fileKey={fileKey} onChanged={() => {}} />;
}

Drop it into a File Browser or File List row. onChanged fires after a successful copy/rename/move/delete so the parent can re-list. Rename edits only the basename and re-attaches the original prefix; Move takes a full destination key.

The default trigger is an icon button whose accessible name includes the key (“Actions for photos/sunset.jpg”), so a list of rows doesn’t read as a column of identical “Actions” buttons. If you pass children, they become the trigger’s content and its accessible name, so make them name the file too. The menu and dialogs are shadcn primitives and work from the keyboard.

Props

PropType
filesUseFilesResult

A `useFiles()` instance — every action runs through it.

TypeUseFilesResult
fileKeystring

The key the actions operate on.

Typestring
onChanged?() => void

Called after a successful copy/rename/move/delete so the parent can refresh.

Type() => void
children?ReactNode

Custom trigger content, rendered inside the trigger button. Defaults to a styled `⋯` icon whose screen-reader label is "Actions for" plus the key; custom content becomes the trigger's accessible name, so make it name the file.

TypeReactNode
className?string
Typestring

Last updated on

Was this page helpful?