Skip to Content

Media

Media frame for images and scenes with default, outline hairline, muted mat and placeholder variants and four corner radii. A direct img fills the frame and crops, and it renders as any element.

Installation

pnpm dlx shadcn@latest add @01orbital/media

Usage

import { Media } from "@/components/media/media"

const COPY = {
  image: "https://01orbital.dev/art/kit/layered-currents-553717.png",
  alt: "Layered currents, a painting of scattered blue and coral dots",
  matted: "https://01orbital.dev/art/kit/celestograph-61495-roan-6b.png",
  mattedAlt: "A celestograph plate, taupe marbling veined with rust",
  empty: "Image to come",
}

// Crop an image, mat another, hold a slot: the three jobs a frame does.
export default function MediaDemo() {
  return (
    <div className="grid w-full max-w-3xl gap-6 sm:grid-cols-3">
      <Media variant="outline" radius="lg" className="aspect-4/5">
        <img src={COPY.image} alt={COPY.alt} />
      </Media>
      <Media variant="muted" radius="lg" className="aspect-4/5">
        <img src={COPY.matted} alt={COPY.mattedAlt} className="rounded-sm" />
      </Media>
      <Media variant="placeholder" radius="lg" className="aspect-4/5">
        {COPY.empty}
      </Media>
    </div>
  )
}

This example installs with everything it uses:

pnpm dlx shadcn@latest add @01orbital/media-demo

Examples

Paper Mat Printmedia-paper-mat-print

Art print example showing Media: a square-cornered, wide paper mat framing a teal print.

pnpm dlx shadcn@latest add @01orbital/media-paper-mat-print

Bone Slab Covermedia-bone-slab-cover

Editorial cover example showing Media: a rounded frame containing bone-colored light slabs and a dark caption.

pnpm dlx shadcn@latest add @01orbital/media-bone-slab-cover

API reference

A frame for an image, video or artwork in a block: it clips what is inside and rounds the corners. A direct <img> child fills the frame and is cropped to it; the frame is relative, so absolutely positioned art places itself against it.

default is bare, outline adds a faint hairline ring, muted mats the piece with 8px of muted background inside the ring, and placeholder is a muted empty slot with small centered text. radius sets the corners: none, sm (the default), md or lg. Set a ratio with an aspect-* class, or pass render={<AspectRatio ratio={…} />}.

Prop

Type

It also accepts the props of the Base UI part it wraps, and the HTML attributes of the element it renders.

Dependencies

npm: @base-ui/react, class-variance-authority, cn. The CLI installs them for you.

Used in blocks

11 blocks are built with Media:

Last updated on