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.
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.
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.
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 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.