Blocks / File browser

File browser

A folder's files as rows or cards: click, ⇧ and ⌘ ranges, lasso, keys, right click, drag onto folders.

import { FileBrowser, useActions } from "@forgeron/ui";
/01 → Default
SelectedActions
ContractsLéa MartinNov 10
Dock plan.pdfSharedLéa Martin09:12
Tariffs 2027.xlsxStarredCamille RoyNov 12
Yard after the walk.jpgTom GarnierOct 2
import { FileBrowser, type DriveItem } from "@forgeron/ui";

const items: DriveItem[] = [
  {
    id: "f1",
    name: "Contracts",
    kind: "folder",
    modified: "2026-11-10 10:02",
    owner: "Léa Martin",
  },
  {
    id: "a",
    name: "Dock plan.pdf",
    size: 240_000,
    modified: "2026-11-18 09:12",
    owner: "Léa Martin",
    shared: true,
  },
  {
    id: "b",
    name: "Tariffs 2027.xlsx",
    size: 52_400,
    modified: "2026-11-12 16:40",
    owner: "Camille Roy",
    starred: true,
  },
  {
    id: "c",
    name: "Yard after the walk.jpg",
    size: 1_840_000,
    modified: "2026-10-02 08:15",
    owner: "Tom Garnier",
  },
];

export default function Default() {
  return (
    <div style={{ width: "100%", maxWidth: 640 }}>
      <FileBrowser
        items={items}
        today="2026-11-18"
        defaultSelected={["a"]}
        columns={["owner", "modified"]}
      />
    </div>
  );
}
/02 → Grid
Contracts
Photos of the yardStarred
Dock plan.pdf
Forklift safety.mp4
SharedGate B at night.jpg
Read-onlyInvoices 2025.zip
Kick-off 2027.pptx
Proposal Lyon Logistique.docx
Tariffs 2027.xlsx
import { Segmented, FileBrowser, type DriveItem } from "@forgeron/ui";
import { useState } from "react";

const items: DriveItem[] = [
  { id: "f1", name: "Contracts", kind: "folder" },
  { id: "f2", name: "Photos of the yard", kind: "folder", starred: true },
  { id: "a", name: "Dock plan.pdf", size: 240_000, modified: "2026-11-18 09:12" },
  { id: "b", name: "Tariffs 2027.xlsx", size: 52_400, modified: "2026-11-12 16:40" },
  { id: "c", name: "Proposal Lyon Logistique.docx", size: 88_000, modified: "2026-11-15 11:00" },
  { id: "d", name: "Kick-off 2027.pptx", size: 3_400_000, modified: "2026-11-03 14:20" },
  {
    id: "e",
    name: "Gate B at night.jpg",
    size: 1_840_000,
    modified: "2026-10-02 08:15",
    shared: true,
  },
  { id: "g", name: "Forklift safety.mp4", size: 48_000_000, modified: "2026-09-20 10:00" },
  {
    id: "h",
    name: "Invoices 2025.zip",
    size: 12_600_000,
    modified: "2026-01-04 09:00",
    locked: true,
  },
];

// Folders as tiles, files as cards with a drawing of their kind; the arrows move in two
// directions, a lasso from the empty space selects a block of cards.
export default function Grid() {
  const [layout, setLayout] = useState("grid");
  return (
    <div style={{ display: "grid", gap: 12, width: "100%" }}>
      <div>
        <Segmented
          label="Layout"
          options={[
            { value: "list", label: "List" },
            { value: "grid", label: "Grid" },
          ]}
          value={layout}
          onChange={setLayout}
        />
      </div>
      <FileBrowser items={items} layout={layout === "grid" ? "grid" : "list"} today="2026-11-18" />
    </div>
  );
}
/03 → Actions and moves
SelectedActions
ContractsLéa MartinNov 10—
SalesCamille RoyNov 14—
Dock plan.pdfLéa Martin09:12240 KB
Gate B at night.jpgTom GarnierOct 21.8 MB
Tariffs 2027.xlsxCamille RoyNov 1252 KB
// The actions of the selection declared once with useActions: the right click, the ⋯ of a row,
// the selection bar and the keys run the same code. Drag a file onto a folder, press F2 to
// rename, Delete to trash, double click a folder to go in.
import { Delete02Icon, Download01Icon, Edit02Icon, StarIcon, UserAdd01Icon } from "@forgeron/icons";
import {
  Breadcrumb,
  Button,
  FileBrowser,
  SelectionBar,
  useActions,
  type Action,
  type DriveItem,
} from "@forgeron/ui";
import { useState } from "react";

interface Node extends DriveItem {
  parent: string;
}

const START: Node[] = [
  {
    id: "f1",
    parent: "my",
    name: "Contracts",
    kind: "folder",
    modified: "2026-11-10 10:02",
    owner: "Léa Martin",
  },
  {
    id: "f2",
    parent: "my",
    name: "Sales",
    kind: "folder",
    modified: "2026-11-14 17:30",
    owner: "Camille Roy",
  },
  {
    id: "a",
    parent: "my",
    name: "Dock plan.pdf",
    size: 240_000,
    modified: "2026-11-18 09:12",
    owner: "Léa Martin",
  },
  {
    id: "b",
    parent: "my",
    name: "Tariffs 2027.xlsx",
    size: 52_400,
    modified: "2026-11-12 16:40",
    owner: "Camille Roy",
  },
  {
    id: "c",
    parent: "my",
    name: "Gate B at night.jpg",
    size: 1_840_000,
    modified: "2026-10-02 08:15",
    owner: "Tom Garnier",
  },
  {
    id: "d",
    parent: "f1",
    name: "Forklift lease.pdf",
    size: 410_000,
    modified: "2026-10-08 12:00",
    owner: "Léa Martin",
  },
];

export default function ActionsAndMoves() {
  const [nodes, setNodes] = useState(START);
  const [folder, setFolder] = useState("my");
  const [selected, setSelected] = useState<string[]>([]);
  const [renaming, setRenaming] = useState<string | null>(null);
  const items = nodes.filter((n) => n.parent === folder);
  const patch = (ids: string[], change: (n: Node) => Partial<Node>) =>
    setNodes((all) => all.map((n) => (ids.includes(n.id) ? { ...n, ...change(n) } : n)));
  const trash = (ids: string[]) => {
    setNodes((all) => all.filter((n) => !ids.includes(n.id)));
    setSelected([]);
  };

  const one = selected.length === 1;
  const list: Action[] = [
    {
      id: "share",
      label: "Share",
      icon: UserAdd01Icon,
      disabled: !one,
      run: () => patch(selected, () => ({ shared: true })),
    },
    { id: "download", label: "Download", icon: Download01Icon },
    {
      id: "star",
      label: "Star",
      icon: StarIcon,
      run: () => patch(selected, (n) => ({ starred: !n.starred })),
    },
    {
      id: "rename",
      label: "Rename",
      icon: Edit02Icon,
      disabled: !one,
      run: () => setRenaming(selected[0] ?? null),
    },
    {
      id: "trash",
      label: "Move to trash",
      icon: Delete02Icon,
      danger: true,
      run: () => trash(selected),
    },
  ];
  const actions = useActions(list, { shortcuts: false });

  return (
    <div style={{ display: "grid", gap: 10, width: "100%" }}>
      <Breadcrumb
        items={
          folder === "my"
            ? [{ label: "My files" }]
            : [
                { label: "My files", href: "#" },
                { label: nodes.find((n) => n.id === folder)?.name ?? "" },
              ]
        }
      />
      {folder !== "my" ? (
        <Button variant="ghost" size="sm" onClick={() => setFolder("my")}>
          Back to My files
        </Button>
      ) : null}
      <div style={{ minHeight: 40 }}>
        {selected.length > 0 ? (
          <SelectionBar
            count={selected.length}
            onClear={() => setSelected([])}
            actions={list}
            iconOnly={["star", "trash"]}
          />
        ) : null}
      </div>
      <FileBrowser
        items={items}
        today="2026-11-18"
        selected={selected}
        onSelectedChange={setSelected}
        onOpen={(id) => {
          const n = nodes.find((x) => x.id === id);
          if (n?.kind === "folder") {
            setFolder(id);
            setSelected([]);
          }
        }}
        menu={() => actions.menu}
        onAction={(id) => actions.run(id)}
        onMove={(ids, to) => {
          patch(ids, () => ({ parent: to }));
          setSelected([]);
        }}
        onRename={(id, name) => patch([id], () => ({ name }))}
        renaming={renaming}
        onRenamingChange={setRenaming}
        onDelete={trash}
      />
    </div>
  );
}
API → Props
PropTypeDefaultDescription
items{ id, name, kind?, size?, modified?, owner?, starred?, shared?, locked?, thumbnail?, icon? }[]—kind: folder for a folder, else found from the name. modified: YYYY-MM-DD HH:mm. locked: no drag, no drop, no rename.
layout"list" | "grid""list"Dense rows with columns, or folder tiles and file cards with a thumbnail.
selected / defaultSelected / onSelectedChangestring[]—The selection. Click, ⇧ click, ⌘ click, a lasso from the empty space, ⇧ arrows, ⌘A, Escape.
onOpen(id) => void—A double click or Enter.
menu / onAction(ids) => ActionMenuEntry[]; (actionId, ids) => void—The actions of the selection, behind a right click, the ⋯ of a row and Shift+F10. Give useActions(…).menu.
onMove / canDrop(ids, folderId) => void; (folderId, ids) => boolean—Items dragged onto a folder. Without onMove, nothing drags.
onDropFiles(files, folderId | null) => void—Files from the computer, on a folder or on the list (null).
onRename / renaming / onRenamingChange(id, name) => void; string | null—A name edited in place: F2, or renaming set from a Rename action.
onDelete(ids) => void—Delete or Backspace.
sort / defaultSort / onSortChange{ key: "name" | "owner" | "modified" | "size", direction }name, ascendingFolders always come first. sortable={false} keeps the given order.
columns / columnLabels("owner" | "modified" | "size")[]; Partial<Record<key, string>>all threeThe columns after the name, and other headers: { owner: "Shared by" }.
today / formatDatestring; (value) => string—Today shows the time; this year leaves out the year.
lassobooleantrueThe rectangle selection.
emptyReactNode—Shown when there is no item.
classNamestring—Extra classes.