# File Card

A composed attachment surface for file identity, metadata, actions, upload progress, and status.

File Card represents one file with its identity, metadata, upload state, and related actions. Compose rows into attachment lists or use tiles in upload trays and media browsers.

```tsx
import { DownloadSimpleIcon, TrashIcon } from "@phosphor-icons/react";
import { FileCard, IconButton, Stack } from "@zentara-co/zenos-ui";

function FileCardPreviewExample() {
  return (
    <Stack gap="3" className="w-full max-w-2xl">
      <FileCard>
        <FileCard.Icon type="pdf" />
        <FileCard.Content>
          <FileCard.Name>research-notes.pdf</FileCard.Name>
          <FileCard.Meta>PDF · 2.4 MB</FileCard.Meta>
        </FileCard.Content>
        <FileCard.Actions>
          <IconButton aria-label="Download research notes" size="sm" variant="ghost">
            <DownloadSimpleIcon />
          </IconButton>
          <IconButton aria-label="Remove research notes" size="sm" variant="ghost">
            <TrashIcon />
          </IconButton>
        </FileCard.Actions>
      </FileCard>

      <FileCard state="uploading">
        <FileCard.Icon type="presentation" />
        <FileCard.Content>
          <FileCard.Name>product-review.pptx</FileCard.Name>
          <FileCard.Progress value={68} />
        </FileCard.Content>
        <FileCard.Status />
      </FileCard>
    </Stack>
  );
}
```

## Import

```tsx
import { FileCard, fileTypeFromName } from "@zentara-co/zenos-ui";
```

## When to use

Use File Card when the file itself is the object a user needs to inspect, upload, open, download, retry, or remove. It is well suited to message attachments, form uploads, import queues, and lightweight file browsers.

Use [Thumbnail](/components/thumbnail/) when the media preview is the primary object and you only need preview or remove behavior. Use [File Tree](/components/file-tree/) for hierarchical navigation. Use a standard [Card](/components/card/) when the content is not specifically a file.

## Anatomy

Use either `FileCard.Icon` for a file-type illustration or `FileCard.Thumbnail` for visual media. `Content` groups the name, metadata, and optional progress bar; status and actions remain trailing siblings so the row stays easy to scan.

```tsx
<FileCard>
  <FileCard.Icon type="pdf" />
  <FileCard.Content>
    <FileCard.Name>research.pdf</FileCard.Name>
    <FileCard.Meta>PDF · 2.4 MB</FileCard.Meta>
  </FileCard.Content>
  <FileCard.Actions>{/* icon buttons */}</FileCard.Actions>
</FileCard>
```

## File illustration and thumbnail

`FileCard.Icon` provides a built-in document illustration for common file families. The [File Icons](/foundations/file-icons/) page lists every family, its tone, and the extensions `fileTypeFromName` recognizes. Derive the type from a filename with `fileTypeFromName(name)`, or set `type` explicitly when the MIME type is more reliable. Use `label` only when a product-specific extension needs a different short name.

Use `FileCard.Thumbnail` when the image itself helps someone recognize the file. Its `alt` prop is required: describe useful visual content, or use the filename when that is the clearest available label.

```tsx
import { TrashIcon } from "@phosphor-icons/react";
import { FileCard, IconButton, Stack } from "@zentara-co/zenos-ui";

function FileCardMediaExample() {
  return (
    <Stack gap="3" className="w-full max-w-2xl">
      <FileCard>
        <FileCard.Thumbnail
          src="https://images.unsplash.com/photo-1669604120699-eeba651ac235?auto=format&fit=crop&w=900&q=80"
          alt="Turquoise lake surrounded by mountains"
          className="size-16"
        />
        <FileCard.Content>
          <FileCard.Name>moraine-lake.jpg</FileCard.Name>
          <FileCard.Meta>4.8 MB · 2400 × 1600</FileCard.Meta>
        </FileCard.Content>
        <FileCard.Actions>
          <IconButton aria-label="Remove Moraine Lake photo" size="sm" variant="ghost">
            <TrashIcon />
          </IconButton>
        </FileCard.Actions>
      </FileCard>

      <FileCard>
        <FileCard.Thumbnail
          src="https://images.unsplash.com/photo-1518770660439-4636190af475?auto=format&fit=crop&w=900&q=80"
          alt="Close-up of a computer circuit board"
          className="size-16"
        />
        <FileCard.Content>
          <FileCard.Name>circuit-closeup.jpg</FileCard.Name>
          <FileCard.Meta>2.1 MB · 3000 × 2000</FileCard.Meta>
        </FileCard.Content>
        <FileCard.Actions>
          <IconButton aria-label="Remove circuit close-up photo" size="sm" variant="ghost">
            <TrashIcon />
          </IconButton>
        </FileCard.Actions>
      </FileCard>
    </Stack>
  );
}
```

### Derive a file type from its name

`fileTypeFromName` recognizes common document, spreadsheet, presentation, archive, image, video, audio, and source-code extensions. It normalizes letter case and returns `"default"` for an unknown or extensionless filename. Prefer a trusted MIME type when one is already available; filenames can be incomplete or misleading.

```tsx
import { FileCard, fileTypeFromName, Grid } from "@zentara-co/zenos-ui";

function FileCardFileTypesExample() {
  const files = [
    "research.pdf",
    "project-brief.docx",
    "forecast.xlsx",
    "launch-deck.pptx",
    "brand-assets.zip",
    "component.tsx",
  ];

  return (
    <Grid columns={{ base: 1, md: 2 }} gap="3" className="w-full max-w-3xl">
      {files.map((name) => (
        <FileCard key={name} density="compact" variant="outline">
          <FileCard.Icon type={fileTypeFromName(name)} />
          <FileCard.Content>
            <FileCard.Name>{name}</FileCard.Name>
            <FileCard.Meta className="capitalize">{fileTypeFromName(name)}</FileCard.Meta>
          </FileCard.Content>
        </FileCard>
      ))}
    </Grid>
  );
}
```

```tsx
const type = fileTypeFromName(file.name);

<FileCard.Icon type={type} label={file.extension.toUpperCase()} />;
```

## Content hierarchy

Keep `FileCard.Name` to the real filename, including its extension. It truncates visually in narrow rows, so preserve the complete name in the DOM and avoid shortening the underlying string.

Use one concise `FileCard.Meta` line for the information needed to distinguish the file: format, size, modified date, owner, or upload result. Put the most useful facts first and separate them consistently, for example `PDF · 2.4 MB`. Do not repeat the filename, progress percentage, or status text in the meta line.

## Upload states

Set `state` on the root so `FileCard.Progress` and `FileCard.Status` stay synchronized. Uploading shows activity, success confirms completion, and error applies a danger surface and progress color. Keep a failed upload in place so the user can identify it and retry or remove it.

`FileCard.Progress` renders its percentage by default. Set `hideValue` when `FileCard.Value` displays that number elsewhere in the row; do not announce the same percentage twice.

```tsx
import { FileCard, Stack } from "@zentara-co/zenos-ui";

function FileCardStatesExample() {
  return (
    <Stack gap="3" className="w-full max-w-2xl">
      <FileCard state="uploading">
        <FileCard.Icon type="video" />
        <FileCard.Content>
          <FileCard.Name>launch-film.mp4</FileCard.Name>
          <FileCard.Progress value={42} label="Uploading 12.6 of 30 MB" hideValue />
        </FileCard.Content>
        <FileCard.Value>42%</FileCard.Value>
        <FileCard.Status />
      </FileCard>

      <FileCard state="success">
        <FileCard.Icon type="spreadsheet" />
        <FileCard.Content>
          <FileCard.Name>forecast.xlsx</FileCard.Name>
          <FileCard.Meta>Upload complete · 940 KB</FileCard.Meta>
        </FileCard.Content>
        <FileCard.Status />
      </FileCard>

      <FileCard variant="white" state="error">
        <FileCard.Icon type="archive" />
        <FileCard.Content>
          <FileCard.Name>source-files.zip</FileCard.Name>
          <FileCard.Progress value={64} label="Upload failed" hideValue />
        </FileCard.Content>
        <FileCard.Status />
      </FileCard>
    </Stack>
  );
}
```

For a live upload, keep `value` between 0 and 100 and update the same mounted card instead of replacing it on every tick. Move to `state="success"` only after the server confirms completion. For an error, replace progress detail with an actionable reason when available and place retry or remove controls in `FileCard.Actions`.

## Layout, density, and variants

The default `layout="row"` is best for attachment lists and form uploads. Use `layout="tile"` when previews are the primary scanning cue. `density="compact"` reduces the card and media dimensions for dense trays; when omitted, density inherits from `DensityProvider`.

Choose `default` for most product surfaces, `outline` for flatter groups, `elevated` when the file needs stronger separation, and `ghost` when a surrounding container already provides the surface.

Use `variant="white"` for a white attachment surface in light mode and the default card background in dark mode. It uses `background-default` in light mode and `background-neutral-card` in dark mode, with names, metadata, icons, and status text following the active theme. Error-state styling takes precedence over this fill.

```tsx
import { FileCard, Grid } from "@zentara-co/zenos-ui";

function FileCardVariantsExample() {
  return (
    <Grid columns={{ base: 1, md: 2 }} gap="4" className="w-full max-w-3xl">
      {(["default", "outline", "elevated", "ghost", "white"] as const).map((variant) => (
        <FileCard key={variant} variant={variant}>
          <FileCard.Icon type="document" />
          <FileCard.Content>
            <FileCard.Name className="capitalize">{variant} surface</FileCard.Name>
            <FileCard.Meta>Document · 620 KB</FileCard.Meta>
          </FileCard.Content>
        </FileCard>
      ))}
    </Grid>
  );
}
```

## Interaction model

Keep the root non-interactive when it contains download, remove, overflow, or retry controls in `FileCard.Actions`. This preserves separate keyboard targets and clear action names.

When the whole card has exactly one destination, render it as a native link with `as="a"`, provide `href`, and set `interactive`. Do not nest buttons or links inside an interactive root.

```tsx
import { ArrowRightIcon, DownloadSimpleIcon, TrashIcon } from "@phosphor-icons/react";
import { FileCard, IconButton, Stack } from "@zentara-co/zenos-ui";

function FileCardInteractionExample() {
  return (
    <Stack gap="3" className="w-full max-w-2xl">
      <FileCard as="a" href="#accessibility" interactive>
        <FileCard.Icon type="pdf" />
        <FileCard.Content>
          <FileCard.Name>accessibility-audit.pdf</FileCard.Name>
          <FileCard.Meta>Open file · PDF · 1.8 MB</FileCard.Meta>
        </FileCard.Content>
        <ArrowRightIcon aria-hidden className="rtl:rotate-180" />
      </FileCard>

      <FileCard>
        <FileCard.Icon type="document" />
        <FileCard.Content>
          <FileCard.Name>meeting-notes.docx</FileCard.Name>
          <FileCard.Meta>DOCX · 340 KB</FileCard.Meta>
        </FileCard.Content>
        <FileCard.Actions>
          <IconButton aria-label="Download meeting notes" size="sm" variant="ghost">
            <DownloadSimpleIcon />
          </IconButton>
          <IconButton aria-label="Remove meeting notes" size="sm" variant="ghost">
            <TrashIcon />
          </IconButton>
        </FileCard.Actions>
      </FileCard>
    </Stack>
  );
}
```

### Actions

Prefer icon buttons for familiar, repeated actions in attachment lists. Give every icon-only action a file-specific accessible name such as “Download research notes” rather than “Download.” Keep destructive removal separate from opening the file, and confirm removal only when recovery is difficult or the effect extends beyond the current draft.

Avoid hiding essential actions only on hover. Touch, keyboard, zoomed, and reduced-pointer interfaces must retain a discoverable way to reach them.

## Responsive behavior

Rows should remain the default on narrow screens. Let the filename and metadata truncate while media, status, and actions keep their usable size. When a row cannot accommodate several trailing controls, move secondary actions into a labeled overflow menu rather than shrinking the touch targets.

For tile collections, let the parent grid decide the column count. File Card owns its internal tile layout, not the width of the collection.

## Custom styling

Every part exposes a stable `data-slot`, and `className` merges last. Prefer semantic surface, border, text, and icon tokens so customization remains legible in light and dark themes.

```tsx
import { DownloadSimpleIcon } from "@phosphor-icons/react";
import { FileCard, IconButton } from "@zentara-co/zenos-ui";

function FileCardCustomExample() {
  return (
    <FileCard className="w-full max-w-2xl border-border-accent-purple-default bg-background-accent-purple-subtlest-default shadow-none">
      <FileCard.Icon
        type="code"
        className="rounded-xl bg-background-neutral-card ring-1 ring-border-accent-purple-default"
      />
      <FileCard.Content>
        <FileCard.Name className="text-text-accent-purple-bolder">tokens.json</FileCard.Name>
        <FileCard.Meta>JSON · Updated just now</FileCard.Meta>
      </FileCard.Content>
      <FileCard.Actions>
        <IconButton
          aria-label="Download token file"
          size="sm"
          className="text-text-accent-purple-bolder hover:bg-background-accent-purple-subtlest-hover"
        >
          <DownloadSimpleIcon />
        </IconButton>
      </FileCard.Actions>
    </FileCard>
  );
}
```

## Variants

default, outline, elevated, ghost, white

## Anatomy

```text
FileCard.Root
FileCard.Icon
FileCard.Thumbnail
FileCard.Content
FileCard.Name
FileCard.Meta
FileCard.Value
FileCard.Actions
FileCard.Progress
FileCard.Status
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| variant | default \| outline \| elevated \| ghost \| white | default | Surface treatment for the file attachment. |
| layout | row \| tile | row | Horizontal attachment row or vertical media tile. |
| state | idle \| uploading \| success \| error | idle | Upload lifecycle consumed by Progress and Status. |
| density | comfortable \| compact | comfortable | Controls spacing and media size. Inherits from DensityProvider when omitted. |
| interactive | boolean | false | Adds focus, hover, and pointer affordances for an interactive root. |
| as | ElementType | div | Renders the root as a semantic element such as an anchor or button. |
| Icon.type | default \| pdf \| document \| spreadsheet \| presentation \| archive \| image \| video \| audio \| code | default | File family controlling the built-in illustration label and semantic tint. |
| Icon.label | string | — | Overrides the short extension label in the built-in illustration. |
| Thumbnail.alt | string | — | Required alternative text for an image thumbnail. |
| Progress.value | number | — | Upload percentage, clamped visually between 0 and 100. |
| Progress.label / hideValue | ReactNode / boolean | Uploading / false | Progress caption and control for the internal percentage label. |
| Status.status | idle \| uploading \| success \| error | — | Overrides the nearest root state. Idle renders nothing. |
| native props | React.HTMLAttributes<HTMLElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

Use a real button or link for each action and give icon-only controls a specific accessible name such as “Download research notes.” `FileCard.Status` includes polite status text for the current lifecycle state, while `FileCard.Progress` exposes native progressbar semantics and the current numeric value.

The built-in file illustration is decorative because the filename carries the identity. Image thumbnails require useful alternative text. Avoid making a card interactive when its content already contains controls, and keep visible focus on whole-card links or buttons.

## Review checklist

Before shipping a File Card experience, verify:

- [ ] The complete filename and extension remain available to users.
- [ ] Metadata is concise and does not repeat the filename or progress value.
- [ ] The illustration type comes from a trusted MIME type or a safely derived extension.
- [ ] Meaningful thumbnails have accurate alternative text.
- [ ] Upload progress has one visible percentage and a useful label.
- [ ] Success appears only after the upload is confirmed.
- [ ] Failed files remain identifiable and offer an appropriate retry or removal path.
- [ ] Whole-card interaction uses a native link or button and contains no nested controls.
- [ ] Separate icon actions have file-specific accessible names.
- [ ] Keyboard focus remains visible in light and dark themes.
- [ ] Narrow layouts preserve readable content and usable action targets.

Source: https://zenos-ui.pages.dev/components/file-card/