Components
Pixel Mosaic
An image loader that resolves from big pixels to sharp.
<PixelMosaic placeholder={photo.blurDataURL}>
<Image src={photo} alt="…" />
</PixelMosaic>Installation
npx shadcn@latest add https://ui.zjkm.tech/r/pixel-mosaic-tw.jsonimport { PixelMosaic } from "@/components/pixel-mosaic"Using JavaScript? Set tsx: false in components.json and the CLI converts it.
New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.
Usage
Pixel Mosaic wraps an <img> or next/image. While the photo loads it shows a shimmering mosaic of the placeholder (or a flat color), then sharpens it into the photo. Your image keeps its alt, size and loading behaviour.
import Image from "next/image";
import { PixelMosaic } from "@/components/pixel-mosaic";
import photo from "./photo.jpg";
export function Hero() {
return (
<PixelMosaic placeholder={photo.blurDataURL}>
<Image src={photo} alt="Harbour at dusk" />
</PixelMosaic>
);
}Installed the CSS variant? Import from @/components/pixel-mosaic-plain instead.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | The element that contains your <img> or next/image. | |
placeholder | string | Tiny image URL or data URL drawn as the loading mosaic. | |
color | string | "#a1a1aa" | Mosaic colour when there is no placeholder. |
cellSize | number | 24 | Starting cell size in CSS pixels. |
duration | number | 900 | Length of the reveal in milliseconds. |
className | string | Classes for the wrapper. |