Skip to content

Media Library

The images and files of a content site in one place: find them, add them, write their alt text with an AI that proposes and the person decides, and see what a delete would break. It is also the picker a post editor opens for a cover image. Controlled: you pass the assets and the async handlers.

On this page
Used for
  • Content management
  • Blog and docs sites
  • Cover image picker
  • Alt text review
  • Asset cleanup

Examples

View

Search by description, tags and focal point

As a picker

On a phone

Installation

Installation is part of Pro

Pro components install from a licensed registry. The live preview stays open to everyone.

Props

assets
MediaAsset[]
Everything in the library. An asset has id, name, url, kind (image, video, audio, document), size in bytes and updatedAt, and optionally width, height, alt, usage, tags and focal.
mode
"manage" | "pick"
Default"manage"
manage opens a detail sheet on click. pick selects a tile and shows a Choose button, and Enter or a double click returns it.
onPick
(asset) => void
The person chose an asset in pick mode.
onUpload
(files: File[]) => void | Promise
Adds the Upload button. Called with the files that passed accept and maxSize. A rejection shows an error in the dialog.
accept / maxSize / onReject
string / number / (rejections) => void
Limits for the upload, with the same syntax as an input. onReject receives the refused files and the reason.
onDelete
(id) => void | Promise
Called after the confirm. A rejection keeps the asset and shows the error in the dialog.
onAltChange
(id, alt) => void | Promise
The person saved an alt text, typed or accepted from the AI draft.
onGenerateAlt
(asset, signal?) => Promise<string>
Returns an AI draft for the alt text. Without it the Write with AI button is hidden. signal aborts when the person asks again or moves on, and a late result is dropped.
onCopyUrl
(asset) => void | Promise
Replaces the default copy to the clipboard.
onSmartSearch
(query, signal) => Promise<{ id, reason? }[]>
Adds the Describe toggle: search by what is in the picture. Called 400ms after typing stops, best hit first; signal aborts when the person types on. Type and tag filters still apply.
onSuggestTags
(asset, signal?) => Promise<string[]>
Adds Suggest tags to the detail sheet. Suggestions are added one by one or all at once, never on their own.
onTagsChange
(id, tags) => void | Promise
Makes tags editable. A rejection puts the old tags back and shows the error.
onFocalChange
(id, { x, y }) => void | Promise
Adds the focal point editor with 16:9, 1:1 and social card previews. x and y are fractions from 0 to 1.
view / defaultView / onViewChange
"grid" | "list"
Default"grid"
The layout, controlled or not.
selectedId / onSelectedChange
string | null
The selected tile, controlled or not.
kinds
MediaKind[]
Limits the library to these kinds. MediaPicker takes kind for one.
loading
boolean
Defaultfalse
Shows skeleton tiles.
MediaPicker
open, onOpenChange, assets, kind, selectedId, onPick, onUpload
The same library in a dialog; it closes after onPick.

Alt text

  • The AI writes a draft; it never saves on its own. The person reads it, edits it and presses Accept, and Undo brings back what was there before.
  • The field warns about an empty text, one over 125 characters and one that starts with "image of", so the hint is the same whoever wrote the text.
  • Images with no alt text are counted and can be filtered, so a team can clean them up in one pass.

Keyboard and accessibility

  • The arrow keys, Home and End move through the tiles with one tab stop. Enter opens the asset, or picks it in pick mode.
  • Each tile is a button named with the file name, its kind and size, and says when it is selected.
  • The focal point is a button on the preview: arrow keys move it 2% (Shift 10%), Home centres it, and its position is read out in percent.
  • Upload results, copy and the alt text steps are announced in a polite status line; errors are alerts.

What it handles

  1. 01Shows every image, video, audio file and document as a grid or a list, with search, a type filter and a filter for images that still have no alt text.
  2. 02Uploads through File Drop with a size and type limit, and tells the person which files were refused and why.
  3. 03Opens a detail sheet with a preview, size, usage count, copy URL and delete. Delete says how many posts will break before it asks.
  4. 04Writes alt text with an AI: an async callback you supply returns a draft, the person edits it, accepts it or discards it, and can undo an accepted one. A slow or failed request never replaces what they typed.
  5. 05Finds a picture by what is in it: the person describes it (people around a table), your search service answers with ids and reasons, and a late answer for an older query is dropped.
  6. 06Keeps tags per asset as editable chips; an AI suggests more and the person adds the ones they want. Search and the Tag filter use them.

States

First render
Nothing. The grid paints as it is
none
Hover and selection
Tile border and background change colour
120ms, ease out
Open an asset
The detail sheet slides in from the right, a bottom sheet on a phone
180ms, ease out
Generate alt text
The button shows a spinner and the field stays editable until the draft arrives
none
Alt text fails
An error line with Retry; the text the person typed stays
none
Search by description
A spinner in the field; the results swap in place, the old ones dimmed while the next answer comes
120ms dim, ease out
Suggested tags arrive
The row of suggestions fades in
120ms, ease out, opacity only
Move the focal point
The marker and the three crops follow the pointer or the keys at once
none
Delete
A confirm dialog names the posts that use it; the tile leaves when the call succeeds
none
Reduced motion
Sheet and dialog appear at once
0ms

Works with

When to use

When to use

  • The place a content team keeps its images and files: search, upload, alt text and what a delete would break.
  • The picker a post editor opens to choose a cover image.

When not to use

Using with AI

Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:

  • Add the Knowns UI Media Library to my app and wire it to my own data.
  • I need the place a content team keeps its images and files: search, upload, alt text and what a delete would break. Set that up with the Knowns UI Media Library.
  • Which Media Library props do I need for a minimal setup? Show me a short example.

With the server connected, your assistant calls get_component({ name: "media-library" }) and search_docs({ query: "media library" }). Pro props, full examples and source come back once your license key is in the MCP config.

Need help?

Stuck on Media Library, or found something off? We read every message.