Move dialog
Move or copy to a folder picked in the tree; a double click confirms.
import { MoveDialog, MovePanel, folderLabel } from "@forgeron/ui";Now in My files
- My files
- Contracts
- Photos
- Sales
To My files › Contracts
import { Briefcase01Icon, Home01Icon } from "@forgeron/icons";
import { MovePanel, type FolderNode } from "@forgeron/ui";
const folders: FolderNode[] = [
{
id: "my",
name: "My files",
icon: Home01Icon,
children: [
{ id: "contracts", name: "Contracts", children: [] },
{ id: "photos", name: "Photos", children: [] },
],
},
{
id: "sales",
name: "Sales",
icon: Briefcase01Icon,
children: [{ id: "quotes", name: "Quotes", children: [] }],
},
];
export default function Panel() {
return (
<div style={{ width: "100%", maxWidth: 420 }}>
<MovePanel
folders={folders}
from="My files"
disabledIds={["my"]}
defaultValue="contracts"
onConfirm={() => {}}
onCancel={() => {}}
/>
</div>
);
}// Move or copy in a modal. The folder being moved and the one it is in cannot be picked; a double
// click on a folder confirms at once.
import { Briefcase01Icon, Home01Icon, TruckIcon } from "@forgeron/icons";
import { Button, folderLabel, MoveDialog, type FolderNode } from "@forgeron/ui";
import { useState } from "react";
const folders: FolderNode[] = [
{
id: "my",
name: "My files",
icon: Home01Icon,
children: [
{
id: "contracts",
name: "Contracts",
children: [{ id: "leases", name: "Leases", children: [] }],
},
{ id: "photos", name: "Photos", children: [] },
],
},
{
id: "sales",
name: "Sales",
icon: Briefcase01Icon,
children: [{ id: "quotes", name: "Quotes", children: [] }],
},
{ id: "ops", name: "Operations", icon: TruckIcon, children: [] },
];
export default function DialogExample() {
const [mode, setMode] = useState<"move" | "copy" | null>(null);
const [done, setDone] = useState("");
return (
<div style={{ display: "grid", gap: 8, justifyItems: "start" }}>
<div style={{ display: "flex", gap: 8 }}>
<Button onClick={() => setMode("move")}>Move “Contracts”</Button>
<Button onClick={() => setMode("copy")}>Copy “Contracts”</Button>
</div>
<span style={{ color: "var(--ink-dim)", font: "400 11px/16px var(--font-mono)" }}>
{done}
</span>
{mode ? (
<MoveDialog
mode={mode}
itemLabel="“Contracts”"
folders={folders}
from="My files"
disabledIds={mode === "move" ? ["contracts", "my"] : []}
onConfirm={(id) =>
setDone(`${mode === "move" ? "Moved" : "Copied"} to ${folderLabel(folders, id)}`)
}
onClose={() => setMode(null)}
/>
) : null}
</div>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
folders | FolderNode[] | — | The tree to pick from. |
mode | "move" | "copy" | "move" | The words of the title and the button. |
from | string | — | Where the items are now. |
disabledIds | string[] | — | Folders that cannot be picked: the items, and their folder for a move. |
value / defaultValue / onChange | string | null | — | The destination picked. |
onConfirm | (folderId) => void | — | Move here, Copy here. |
itemLabel / onClose | string; () => void | — | MoveDialog only: “Dock plan.pdf”, 3 items; Escape, Cancel. |
className | string | — | Extra classes. |