Components

File Attachment Panel

File Attachment Panel component.

Client Only

Installation

pnpm dlx @docyrus/cli add @docyrus/ui-file-attachment-panel
UI Primitives(6 components)
npx shadcn@latest add button dropdown-menu progress scroll-area separator skeleton

Usage

import { FileAttachmentPanel } from "@docyrus/ui/components/file-attachment-panel";
import type { FileAttachmentPanelProps } from "@docyrus/ui/components/file-attachment-panel";

const files: FileAttachmentPanelProps['files'] = [
  {
    id: "f-1",
    file_name: "design-review.png",
    file_type: "image/png",
    file_size: 120000,
    signed_url: "https://images.unsplash.com/photo-1581291518857-4e27b48ff24e?w=640&q=80",
    source: "local",
    file_data: null,
    created_on: new Date().toISOString(),
    record_id: "rec-1"
  }
];

function Demo() {
  return (
    <FileAttachmentPanel
      files={files}
      onUploadFile={(file) => Promise.resolve({
        ...files[0],
        id: crypto.randomUUID(),
        file_name: file.name,
        file_type: file.type,
        file_size: file.size,
        signed_url: URL.createObjectURL(file)
      })}
      onDeleteFile={(id) => console.log("delete", id)}
    />
  );
}

API Reference

PropTypeDefault
filesDocyrusFile[]—
titlestring"Attachments"
editablebooleantrue
isLoadingbooleanfalse
maxFileSizenumber50 * 1024 * 1024
acceptstring—
maxFilesnumber—
onUploadFile(file: File) => Promise<DocyrusFile>—
onDeleteFile(fileId: string) => void | Promise<void>—
onInsertExternalFiles(files: ExternalFilePayload[]) => void | Promise<void>—
onFileOpen(file: DocyrusFile) => void—
isDeletePendingbooleanfalse
classNamestring—
oneDriveConfigOneDrivePickerConfig—
googleDriveConfigGoogleDrivePickerConfig—

Components

ComponentDescription
FileAttachmentPanelPublic export
FileEmptyStateInternal — file-empty-state.tsx
FileGridInternal — file-grid.tsx
FileItemInternal — file-item.tsx
FileListInternal — file-list.tsx
FileSourceMenuInternal — file-source-menu.tsx
FileUploadProgressInternal — file-upload-progress.tsx
FileUploadZoneInternal — file-upload-zone.tsx
DocyrusIconInternal — docyrus-icon.tsx

Type Exports

TypeDescription
FileAttachmentPanelProps—
ViewMode—
DocyrusFile—
ExternalFilePayload—
OneDrivePickerConfigConfig for OneDrive integration
GoogleDrivePickerConfigConfig for Google Drive integration

Type Reference

ViewMode

"list" | "grid"

DocyrusFile

FieldType
idstring
file_namestring
file_typestring
file_sizenumber
signed_urlstring | null
source"local" | "microsoft_onedrive" | "google_drive"
file_dataRecord<string, unknown> | null
created_onstring
record_idstring | null

ExternalFilePayload

FieldType
source"microsoft_onedrive" | "google_drive"
file_namestring
file_typestring
signed_urlstring
file_dataRecord<string, unknown> | undefined
expire_innumber | undefined

OneDrivePickerConfig

FieldTypeDescription
clientIdstringMicrosoft OAuth2 Client ID
redirectUristring | undefinedOAuth2 redirect URI (defaults to window.location.origin)

GoogleDrivePickerConfig

FieldTypeDescription
clientIdstringGoogle OAuth2 Client ID
apiKeystringGoogle API key for the Picker API
appIdstring | undefinedGoogle Cloud project / app ID

On this page