FileExplorer
Browse files and folders. The open folder shows as cards (grid) or a table (list) with breadcrumbs, a name filter, folders first, sizes and item counts; the tree layout shows every folder at once with the keyboard behaviour of Tree. A click opens a folder, and calls onSelect for a file. nodes are { id, name, type: 'file' | 'folder', size?, modified?, children?, itemCount? }. Switch layouts with view / defaultView / onViewChange, and limit them with views.
Click a folder to open it, a file to select it.
Folders loaded on demand. path / defaultPath hold the open folder as the ids from the root; onPathChange(path, folder) fires when the user opens a folder or uses the breadcrumbs, which is where you fetch a folder's children (set itemCount on a folder that is not loaded yet, and loading while you wait). onRefresh adds a reload button. Here a click on a file shows it in a full screen Modal with CodeDisplay; readableSize, languageOf, sortNodes and describeNode are exported.
Props
nodes{ id, name, type: 'file' | 'folder', size?, modified?, children?, itemCount? }[]The entries at the root; folders hold their own
children.onSelect(file) => voidCalled when a file is clicked.
selectedstringId of the highlighted file.
view'grid' | 'list' | 'tree'Layout (controlled).
defaultView'grid' | 'list' | 'tree'Default:'grid'Initial layout.
onViewChange(view) => voidCalled when the layout switch is used.
views('grid' | 'list' | 'tree')[]Default:all threeLayouts the user can switch between.
pathstring[]Open folder as folder ids from the root (controlled).
defaultPathstring[]Default:[]Initial open folder.
onPathChange(path, folder?) => voidCalled when a folder is opened or a breadcrumb is used.
onRefresh() => voidAdds a reload button.
loadingbooleanDefault:falseEntries are loading: they cannot be opened.
defaultExpandedstring[]Initially expanded folder ids (tree view).
expandedstring[]Expanded folder ids (tree view, controlled).
onExpandedChange(keys: string[]) => voidCalled when tree expansion changes.
toolbarEndReactNodePlaced after the layout switch.
emptyTextstringDefault:'This folder is empty.'Shown in an empty folder.
labelstringDefault:'Files'Accessible name of the explorer.
classNamestringDefault:''Extra classes for the root element.
| Prop | Type | Default | Description |
|---|---|---|---|
nodes | { id, name, type: 'file' | 'folder', size?, modified?, children?, itemCount? }[] | – | The entries at the root; folders hold their own children. |
onSelect | (file) => void | – | Called when a file is clicked. |
selected | string | – | Id of the highlighted file. |
view | 'grid' | 'list' | 'tree' | – | Layout (controlled). |
defaultView | 'grid' | 'list' | 'tree' | 'grid' | Initial layout. |
onViewChange | (view) => void | – | Called when the layout switch is used. |
views | ('grid' | 'list' | 'tree')[] | all three | Layouts the user can switch between. |
path | string[] | – | Open folder as folder ids from the root (controlled). |
defaultPath | string[] | [] | Initial open folder. |
onPathChange | (path, folder?) => void | – | Called when a folder is opened or a breadcrumb is used. |
onRefresh | () => void | – | Adds a reload button. |
loading | boolean | false | Entries are loading: they cannot be opened. |
defaultExpanded | string[] | – | Initially expanded folder ids (tree view). |
expanded | string[] | – | Expanded folder ids (tree view, controlled). |
onExpandedChange | (keys: string[]) => void | – | Called when tree expansion changes. |
toolbarEnd | ReactNode | – | Placed after the layout switch. |
emptyText | string | 'This folder is empty.' | Shown in an empty folder. |
label | string | 'Files' | Accessible name of the explorer. |
className | string | '' | Extra classes for the root element. |