Project files
Documents and shared assets for the team.
| Name | Size | Modified | Actions for | |
|---|---|---|---|---|
| — | ||||
| — | ||||
| — | ||||
| 18.6 kB | ||||
| 2.4 kB | ||||
| 143 kB |
<script setup>
import { ref } from "vue";
import { FileBrowser } from "@dicehub/kappa/blocks/file-browser";
const selected = ref([]);
const items = [
{ id: "docs", name: "Documents", kind: "folder" },
{ id: "readme", name: "README.md", kind: "file", size: 2400 },
{ id: "notes", name: "notes.md", kind: "file", parentId: "docs", size: 800 },
];
const openedFile = ref("");
</script>
<template>
<FileBrowser
v-model="selected"
:items="items"
title="Project files"
root-label="Project"
@open="item => openedFile = item.name"
/>
<p v-if="openedFile">Opened: {{ openedFile }}</p>
</template>Installation
Import File Browser from the main package or its dedicated block entry. Import the shared styles and theme once.
import "@dicehub/kappa/styles/kappa.css";
import "@dicehub/kappa/styles/theme-kappa.css";
import { FileBrowser } from "@dicehub/kappa";
// Or: import { FileBrowser } from "@dicehub/kappa/blocks/file-browser";Cards and folders
Set view="grid" for file-explorer cards. Add showView to let people switch between cards and the compact list. Use v-model:view when the host must store the choice.
Project files
Documents and shared assets for the team.
Switch between grid and list views. Right-click any item for the same actions as its menu button.
<script setup>
import { ref } from "vue";
import { FileBrowser } from "@dicehub/kappa/blocks/file-browser";
const view = ref("grid");
const items = [
{ id: "docs", name: "Documents", kind: "folder" },
{ id: "images", name: "Images", kind: "folder" },
{ id: "readme", name: "README.md", kind: "file", size: 2400 },
];
</script>
<template>
<FileBrowser
v-model:view="view"
:items="items"
show-view
title="Project files"
/>
</template>Async loading
loadFolder(folderId, { signal }) returns direct children. It takes precedence over items and first runs after mount. The server renders a loading state. Return a fresh array after host mutations.
New requests abort old requests. Cancelled results are ignored even when the host ignores the signal. Errors show a retry action. The exposed refresh() method reloads the current folder. Breadcrumb navigation can cancel a pending folder load.
Project files
Documents and shared assets for the team.
<script setup>
import { FileBrowser } from "@dicehub/kappa/blocks/file-browser";
async function loadFolder(folderId, { signal }) {
const query = new URLSearchParams({ folder: folderId ?? "root" });
const response = await fetch(`/api/files?${query}`, { signal });
if (!response.ok) throw new Error("Files could not be loaded.");
return response.json(); // Direct child FileBrowserItem records.
}
</script>
<template>
<FileBrowser :load-folder="loadFolder" title="Project files" />
</template>Rename and new folders
Provide renameItem and createFolder to enable their controls. The host changes its data or remote storage. Callbacks receive the current folderId and an AbortSignal. Resolve on success or reject with a safe, user-facing Error message.
Names are trimmed. Empty names, path separators, control characters, dot segments, and exact duplicate names are rejected locally. Other rules belong to the host. Failed requests keep the dialog open. While saving, dismissal and duplicate submissions are disabled. Success refreshes the folder, closes the dialog, and returns focus to an enabled control.
Project files
Documents and shared assets for the team.
| Name | Size | Modified | Actions for | |
|---|---|---|---|---|
| — | ||||
| — | ||||
| — | ||||
| 18.6 kB | ||||
| 2.4 kB | ||||
| 143 kB |
This example rejects names that start with a dot. Use the action menu to rename a file, or create a folder.
<script setup>
import { ref } from "vue";
import { FileBrowser } from "@dicehub/kappa/blocks/file-browser";
const items = ref([
{ id: "notes", name: "notes.md", kind: "file", size: 800 },
]);
function renameItem(item, name) {
items.value = items.value.map(value => value.id === item.id ? { ...value, name } : value);
}
function createFolder(name, { folderId }) {
items.value.push({ id: crypto.randomUUID(), name, kind: "folder", parentId: folderId });
}
</script>
<template>
<FileBrowser :items="items" :rename-item="renameItem" :create-folder="createFolder" />
</template>Host actions
actions(item) returns menu entries with id, label, and optional disabled or destructive. runAction(id, item, context) performs the work. The host supplies any needed confirmation. Errors appear above the list; success refreshes the current folder.
Each item exposes the same actions through its menu button and the Kappa Context Menu. Right-click an item, or focus it and press Shift+F10. Right-click empty space to create a folder or refresh when those operations are available.
<FileBrowser
:items="items"
:actions="item => [{ id: 'details', label: 'Show details' }]"
:run-action="async (action, item, { signal }) => { await showDetails(item, signal); }"
@open="openFile"
>
<template #selection="{ items: selected, clear }">
<Button size="sm" @click="attachFiles(selected); clear()">Attach selected files</Button>
</template>
</FileBrowser>The actions slot adds header controls and receives folderId and refresh. The selection slot receives selected items and clear. The icon slot receives the row item. Host controls must respect permissions and pending work.
Accessibility
Kappa Breadcrumbs, Filter Bar, Table, Checkbox, Dropdown, Context Menu, and Dialog Layout provide the controls. Menus and dialogs follow Ark UI Menu and Ark UI Dialog. Dialog dismissal is blocked during saving.
Tab reaches file names, checkboxes, and menus. Enter or Space activates a file or folder. Navigation moves focus to a stable content region when focus was inside the browser. The table scroll area is also focusable. Loading, counts, and errors are announced. Small screens hide modified dates and keep the table inside a horizontal scroll area.
Translate labels and filterLabels, including actions(name), select(name), count(count), and selected(count). Theme tokens supply both modes. The block adds no motion.
API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
items | readonly FileBrowserItem[] | [] | Static tree; parentId identifies each item's parent. |
loadFolder | (folderId, { signal }) => Promise<items> | — | Load direct children after mount. Takes precedence over items. |
rootId / rootLabel | string | null / string | null / "Files" | Initial folder and breadcrumb label. Changing rootId resets navigation. |
title / description | string | "Files" / — | Heading and optional supporting text. |
modelValue / defaultValue | readonly string[] | [] | Controlled or initial selection IDs in the current folder. |
selectionMode | "none" | "single" | "multiple" | "multiple" | Checkbox selection behavior. |
view / defaultView | "list" | "grid" | — / "list" | Controlled or initial folder presentation. |
showView | boolean | false | Shows the list/grid switch in the filter bar. |
renameItem | (item, name, context) => void | Promise<void> | — | Enables Rename. Reject to show an error. |
createFolder | (name, context) => void | Promise<void> | — | Enables New folder. Reject to keep the dialog open. |
actions / runAction | (item) => actions / (action, item, context) => Promise<void> | void | — | Additional menu actions and their host callback. |
disabled | boolean | false | Disables built-in user controls. |
locale | string | "en" | Name collation, decimal file sizes, and UTC dates. |
labels / filterLabels | Partial<FileBrowserLabels> / Partial<FilterBarLabels> | English | Visible and accessible labels; count and item labels are functions. |
Events: update:modelValue(string[]), update:view("list" | "grid"), open(item), navigate(location[]), and complete({ operation, folderId, item?, action? }). Operations are rename, create, or action.
FileBrowser, FileBrowser.Root, and FileBrowserRoot expose the same block. FILE_BROWSER_DEFAULT_LABELS and all FileBrowser* data, prop, event, and slot interfaces are public exports. HTML attributes and listeners pass to the root section.
The root exposes data-slot="file-browser" and data-state="loading|error|ready|empty". --kappa-file-browser-max-height changes the default 28rem content height.
File Browser displays one complete folder listing. It does not provide uploads, previews, pagination, virtual scrolling, drag-and-drop, or storage access. Integrate these through host controls when required. Use bounded folder results for large data sets.