Asset Grid

A media library as a selectable grid, built on this kit’s Image so every tile gets a placeholder, a reserved box and a failure state. A broken asset stays in the grid — it is exactly the one someone came to find and replace.

src/components/ui/asset-grid.tsx

About

From the component's own source, where it was written.

A media library: images and files as a selectable grid.

The picker half of an asset store. Built on this kit's Image, so every tile gets the placeholder mask, the reserved box and the failure state for free — a grid of raw <img> tags is the fastest way to make a library page jump around while it loads.

**A broken asset stays in the grid.** An image whose URL has rotted is exactly the one someone needs to find and replace, and a library that hides failures makes it invisible while its reference is still live in production.

Selection is controlled and multi-capable, because the operations people actually perform here — delete these six, move these to another folder — are bulk ones.

Install

npx astralyx-ui add asset-grid

Usage

import { AssetGrid } from '@/components/ui/asset-grid'

<AssetGrid assets={assets} value={selected} onValueChange={setSelected} />

Composer

Change the props and the source below follows.

Props
tsx
<AssetGrid
  assets={assets}
  value={selected}
  onValueChange={setSelected}
  single={false}
/>

Examples

Picking assets, one of them broken

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

AssetGrid

Extends Omit<ComponentProps<'div'>, 'onSelect'>.

PropTypeDefaultDescription
assetsAsset[]requiredA library that hides failures makes a rotted URL invisible while its reference is still live in production.
valuestring[]—Controlled selection. Omit both for a read-only library; the tiles then call onOpen instead.
onValueChange(next: string[]) => void—Controlled selection. Omit both for a read-only library; the tiles then call onOpen instead.
singlebooleanfalseOne at a time.
onOpen(asset: Asset) => void——
minTilenumber150The grid is auto-fill, so tiles reflow to the container rather than to a fixed column count.
rationumber1The grid is auto-fill, so tiles reflow to the container rather than to a fixed column count.
emptyLabelstring'Nothing in this library yet.'—
format(bytes: number) => stringformatBytes—

Types

Asset

A media library: images and files as a selectable grid.

FieldTypeDescription
idstring—
src?stringImage URL, or a thumbnail for a non-image file.
namestring—
type?stringMIME type. Drives the fallback glyph when there is no thumbnail.
size?numberBytes.
modified?stringAlready formatted.
meta?ReactNodeShown on the tile — dimensions, a duration, a tag.