Skip to content
TrademarkTrademark
Docs
Modules

MediaLibrary

Updated: November 30, 2026
View on GitHub

MediaLibrary is a full media library: a folder tree, a searchable tile grid with paging, drop to upload with progress, select one or several, rename, move (from the menu or by dragging onto a folder) and delete, with loading, empty and error states. It never fetches anything itself. Every read and write goes through an adapter, so the same library works on Vercel Blob, S3, R2, Supabase Storage or your own API. Import it from @once-ui-system/core/media.

The example below runs on createMemoryMediaAdapter(), which keeps everything in memory, so uploads last until the page reloads.

The adapter

An adapter is an object of async functions. Only list is required. Each control shows only when the adapter has the method behind it, so a read-only bucket gets a browser with no upload button, and an adapter without folders gets no folder tree.

Method
What it does
list(query)One page of assets for a folder and search, with a cursor for the next page.
upload(file, { folderId, onProgress })Stores a file and returns its asset.
remove(ids)Deletes assets.
move(ids, folderId)Moves assets to a folder (null is the top level).
rename(id, name)Renames an asset.
listFolders(), createFolder, renameFolder, removeFolderThe folder tree.

Writes are optimistic: the grid changes at once and rolls back with a danger toast when the adapter throws. Each asset has an id, a name, a src to render, a kind (image, video, audio or file) and optionally the url an app stores when it is picked.

Selection

selectionMode is none, single or multiple. Read the choice with onSelectionChange(ids, assets), or control it with selectedIds. accept limits which kinds can be selected, and onOpen runs when an asset is opened.

MediaPicker

MediaPicker is the "choose an image" dialog over the same library: it opens on open, and onPick gets the chosen assets.

Pass multiple to pick several. For a single upload field with no library behind it, use MediaUpload.

API reference

Type
Default
adapterrequired
Every read and write. Only list is required.
MediaLibraryAdapter—
accept
Kinds that can be selected: image, video, audio, file.
MediaKind[]—
selectionMode
none, single or multiple.
nonesinglemultiple
multiple
selectedIds
string[]—
defaultSelectedIds
string[][]
onSelectionChange
(ids: string[], assets: MediaAsset[]) => void—
onOpen
(asset: MediaAsset) => void—
openOnClick
booleanfalse
defaultFolderId
stringnull
null
onFolderChange
(folderId: string | null) => void—
readOnly
Hides every write, whatever the adapter has.
booleanfalse
columns
23456
4
refreshKey
Change it to list again, after a change made elsewhere.
stringnumber
—
labels
Every word the library shows, for another language.
Partial<MediaLibraryLabels>—
…and every FlexProps propinherited—
Type
Default
openrequired
Whether the dialog is open.
boolean—
onCloserequired
() => void—
onPickrequired
The chosen assets.
(assets: MediaAsset[]) => void—
adapterrequired
MediaLibraryAdapter—
multiple
Pick several instead of one.
booleanfalse
accept
MediaKind[]—
defaultFolderId
stringnull
null
readOnly
booleanfalse
columns
23456
4
height
numberCSSUnit
32rem
labels
Partial<MediaPickerLabels>—
libraryLabels
Partial<MediaLibraryLabels>—
stack
Open over another dialog.
boolean—
Edit this page on GitHub