# Thumbnail

A media preview with independent loading, uploading, and removal states.

A media preview with independent loading, uploading, and removal states.

```tsx
import { Stack, Thumbnail } from "@zentara-co/zenos-ui";

const thumbnailPhotos = {
  moraineLake: {
    src: "https://images.unsplash.com/photo-1669604120699-eeba651ac235?auto=format&fit=crop&w=1600&q=80",
    alt: "Turquoise Moraine Lake surrounded by evergreen forest and mountains",
    label: "moraine-lake.jpg",
  },
  lakeMatheson: {
    src: "https://images.unsplash.com/photo-1768160864911-90f7837453a2?auto=format&fit=crop&w=1600&q=80",
    alt: "Snow-capped Southern Alps reflected in Lake Matheson",
    label: "lake-matheson.jpg",
  },
  architecture: {
    src: "https://images.unsplash.com/photo-1761600577035-c9cb717c7059?auto=format&fit=crop&w=1600&q=80",
    alt: "Minimal modern building with strong geometric shadows",
    label: "architecture.jpg",
  },
} as const;

function ThumbnailExample() {
  return (
    <Stack direction="row" gap="3" align="center">
      {Object.values(thumbnailPhotos).map((photo) => (
        <Thumbnail key={photo.src} {...photo} />
      ))}
    </Stack>
  );
}
```

The examples use photographs from Unsplash by [ConfinedRiley](https://unsplash.com/photos/a-lake-surrounded-by-mountains-mIj8Cn3oNDg), [Tim G](https://unsplash.com/photos/snow-capped-mountains-reflected-in-a-calm-lake-BrFSOHMGuak), and [Sebastian Schuster](https://unsplash.com/photos/modern-building-exterior-with-strong-geometric-shadows-A-13PmQkP1o).

## Import

```tsx
import { Lightbox, Thumbnail } from "@zentara-co/zenos-ui";
```

## Size and aspect ratio

Thumbnail defaults to a 64px square. It intentionally has no named size or ratio prop; use `className` to match the application context. The image always covers the available frame.

```tsx
import { Stack, Thumbnail } from "@zentara-co/zenos-ui";

const thumbnailPhotos = {
  moraineLake: {
    src: "https://images.unsplash.com/photo-1669604120699-eeba651ac235?auto=format&fit=crop&w=1600&q=80",
    alt: "Turquoise Moraine Lake surrounded by evergreen forest and mountains",
    label: "moraine-lake.jpg",
  },
  lakeMatheson: {
    src: "https://images.unsplash.com/photo-1768160864911-90f7837453a2?auto=format&fit=crop&w=1600&q=80",
    alt: "Snow-capped Southern Alps reflected in Lake Matheson",
    label: "lake-matheson.jpg",
  },
  architecture: {
    src: "https://images.unsplash.com/photo-1761600577035-c9cb717c7059?auto=format&fit=crop&w=1600&q=80",
    alt: "Minimal modern building with strong geometric shadows",
    label: "architecture.jpg",
  },
} as const;

function ThumbnailSizingExample() {
  return (
    <Stack direction="row" gap="4" align="end" wrap="wrap">
      <Thumbnail {...thumbnailPhotos.moraineLake} className="size-10" />
      <Thumbnail {...thumbnailPhotos.moraineLake} />
      <Thumbnail {...thumbnailPhotos.moraineLake} className="size-24" />
      <Thumbnail {...thumbnailPhotos.moraineLake} className="h-24 w-40" />
    </Stack>
  );
}
```

## Custom styling

Use `className` to customize the frame, dimensions, shape, and surface. Scope styles to the stable `data-slot` attributes when an application needs to refine the image, preview action, loading state, upload overlay, or remove control without replacing Thumbnail behavior.

```tsx
import { Thumbnail } from "@zentara-co/zenos-ui";

const thumbnailPhotos = {
  moraineLake: {
    src: "https://images.unsplash.com/photo-1669604120699-eeba651ac235?auto=format&fit=crop&w=1600&q=80",
    alt: "Turquoise Moraine Lake surrounded by evergreen forest and mountains",
    label: "moraine-lake.jpg",
  },
  lakeMatheson: {
    src: "https://images.unsplash.com/photo-1768160864911-90f7837453a2?auto=format&fit=crop&w=1600&q=80",
    alt: "Snow-capped Southern Alps reflected in Lake Matheson",
    label: "lake-matheson.jpg",
  },
  architecture: {
    src: "https://images.unsplash.com/photo-1761600577035-c9cb717c7059?auto=format&fit=crop&w=1600&q=80",
    alt: "Minimal modern building with strong geometric shadows",
    label: "architecture.jpg",
  },
} as const;

function ThumbnailCustomStylingExample() {
  return (
    <Thumbnail
      {...thumbnailPhotos.moraineLake}
      className="h-32 w-52 rounded-xl border-2 border-border-accent-teal-default bg-background-accent-teal-subtlest-default p-1 shadow-raised [&_[data-slot=thumbnail-action]]:rounded-lg [&_[data-slot=thumbnail-image]]:saturate-75 [&_[data-slot=thumbnail-remove]]:-end-3 [&_[data-slot=thumbnail-remove]]:-top-3 [&_[data-slot=thumbnail-remove]]:bg-background-accent-teal-bolder-default [&_[data-slot=thumbnail-remove]]:text-text-contrary"
      onClick={() => undefined}
      onRemove={() => undefined}
      showRemoveOn="always"
    />
  );
}
```

## Loading, uploading, and fallback

Loading replaces the preview with a Skeleton while source data is pending. Uploading preserves the available image and overlays a Loader. They are separate states: do not use upload progress to represent an image that has not loaded yet. Missing or failed sources use the image placeholder.

```tsx
import { Stack, Text, Thumbnail } from "@zentara-co/zenos-ui";

const thumbnailPhotos = {
  moraineLake: {
    src: "https://images.unsplash.com/photo-1669604120699-eeba651ac235?auto=format&fit=crop&w=1600&q=80",
    alt: "Turquoise Moraine Lake surrounded by evergreen forest and mountains",
    label: "moraine-lake.jpg",
  },
  lakeMatheson: {
    src: "https://images.unsplash.com/photo-1768160864911-90f7837453a2?auto=format&fit=crop&w=1600&q=80",
    alt: "Snow-capped Southern Alps reflected in Lake Matheson",
    label: "lake-matheson.jpg",
  },
  architecture: {
    src: "https://images.unsplash.com/photo-1761600577035-c9cb717c7059?auto=format&fit=crop&w=1600&q=80",
    alt: "Minimal modern building with strong geometric shadows",
    label: "architecture.jpg",
  },
} as const;

function ThumbnailStatesExample() {
  return (
    <Stack direction="row" gap="5" align="start" wrap="wrap">
      <Stack gap="2" align="center">
        <Thumbnail isLoading label="Loading preview" />
        <Text size="s" color="subtle">
          Loading
        </Text>
      </Stack>
      <Stack gap="2" align="center">
        <Thumbnail {...thumbnailPhotos.lakeMatheson} isUploading />
        <Text size="s" color="subtle">
          Uploading
        </Text>
      </Stack>
      <Stack gap="2" align="center">
        <Thumbnail label="No preview available" />
        <Text size="s" color="subtle">
          Placeholder
        </Text>
      </Stack>
      <Stack gap="2" align="center">
        <Thumbnail
          {...thumbnailPhotos.architecture}
          disabled
          onClick={() => undefined}
          onRemove={() => undefined}
          showRemoveOn="always"
        />
        <Text size="s" color="subtle">
          Disabled
        </Text>
      </Stack>
    </Stack>
  );
}
```

## Lightbox preview

Use each thumbnail's `onClick` to set the active gallery index and open Lightbox. Keep `index` and
`onIndexChange` controlled so selecting a thumbnail and navigating inside Lightbox stay in sync.

```tsx
import { Lightbox, Stack, Thumbnail } from "@zentara-co/zenos-ui";
import { useState } from "react";

const thumbnailPhotos = {
  moraineLake: {
    src: "https://images.unsplash.com/photo-1669604120699-eeba651ac235?auto=format&fit=crop&w=1600&q=80",
    alt: "Turquoise Moraine Lake surrounded by evergreen forest and mountains",
    label: "moraine-lake.jpg",
  },
  lakeMatheson: {
    src: "https://images.unsplash.com/photo-1768160864911-90f7837453a2?auto=format&fit=crop&w=1600&q=80",
    alt: "Snow-capped Southern Alps reflected in Lake Matheson",
    label: "lake-matheson.jpg",
  },
  architecture: {
    src: "https://images.unsplash.com/photo-1761600577035-c9cb717c7059?auto=format&fit=crop&w=1600&q=80",
    alt: "Minimal modern building with strong geometric shadows",
    label: "architecture.jpg",
  },
} as const;

const thumbnailLightboxMedia = [
  { ...thumbnailPhotos.moraineLake, caption: "Moraine Lake, Banff" },
  { ...thumbnailPhotos.lakeMatheson, caption: "Lake Matheson, New Zealand" },
  { ...thumbnailPhotos.architecture, caption: "Geometric architecture" },
];

function ThumbnailLightboxExample() {
  const [open, setOpen] = useState(false);
  const [index, setIndex] = useState(0);

  return (
    <>
      <Stack direction="row" gap="3" wrap="wrap">
        {thumbnailLightboxMedia.map((item, itemIndex) => (
          <Thumbnail
            key={item.src}
            src={item.src}
            alt={item.alt}
            label={item.caption}
            className="h-24 w-36"
            onClick={() => {
              setIndex(itemIndex);
              setOpen(true);
            }}
          />
        ))}
      </Stack>
      <Lightbox
        open={open}
        onOpenChange={setOpen}
        media={thumbnailLightboxMedia}
        index={index}
        onIndexChange={setIndex}
      />
    </>
  );
}
```

## Preview and removal

`onClick` turns the image into a preview button. `onRemove` adds a separate overlaid remove button and stops its click from opening the preview. Thumbnail does not own a viewer; compose it with Lightbox or another application destination.

```tsx
import { Lightbox, Stack, Text, Thumbnail } from "@zentara-co/zenos-ui";
import { useState } from "react";

const thumbnailPhotos = {
  moraineLake: {
    src: "https://images.unsplash.com/photo-1669604120699-eeba651ac235?auto=format&fit=crop&w=1600&q=80",
    alt: "Turquoise Moraine Lake surrounded by evergreen forest and mountains",
    label: "moraine-lake.jpg",
  },
  lakeMatheson: {
    src: "https://images.unsplash.com/photo-1768160864911-90f7837453a2?auto=format&fit=crop&w=1600&q=80",
    alt: "Snow-capped Southern Alps reflected in Lake Matheson",
    label: "lake-matheson.jpg",
  },
  architecture: {
    src: "https://images.unsplash.com/photo-1761600577035-c9cb717c7059?auto=format&fit=crop&w=1600&q=80",
    alt: "Minimal modern building with strong geometric shadows",
    label: "architecture.jpg",
  },
} as const;

function ThumbnailActionsExample() {
  const [files, setFiles] = useState(() => Object.values(thumbnailPhotos));
  const [active, setActive] = useState<(typeof files)[number] | null>(null);

  return (
    <>
      <Stack gap="3" align="start">
        <Stack direction="row" gap="4" wrap="wrap">
          {files.map((file) => (
            <Thumbnail
              key={file.label}
              {...file}
              onClick={() => setActive(file)}
              onRemove={() => setFiles((current) => current.filter((item) => item !== file))}
            />
          ))}
        </Stack>
        <Text size="s" color="subtle" aria-live="polite">
          {files.length ? `${files.length} files attached.` : "No files attached."}
        </Text>
      </Stack>
      {active && (
        <Lightbox
          open
          media={{ src: active.src, alt: active.alt, caption: active.label }}
          onOpenChange={(open) => !open && setActive(null)}
        />
      )}
    </>
  );
}
```

## Remove visibility

Hover visibility keeps dense attachment grids quiet while still revealing the button on keyboard focus and coarse pointers. Use `always` when removal is the primary task or hidden controls would be difficult to discover.

```tsx
import { Stack, Text, Thumbnail } from "@zentara-co/zenos-ui";

const thumbnailPhotos = {
  moraineLake: {
    src: "https://images.unsplash.com/photo-1669604120699-eeba651ac235?auto=format&fit=crop&w=1600&q=80",
    alt: "Turquoise Moraine Lake surrounded by evergreen forest and mountains",
    label: "moraine-lake.jpg",
  },
  lakeMatheson: {
    src: "https://images.unsplash.com/photo-1768160864911-90f7837453a2?auto=format&fit=crop&w=1600&q=80",
    alt: "Snow-capped Southern Alps reflected in Lake Matheson",
    label: "lake-matheson.jpg",
  },
  architecture: {
    src: "https://images.unsplash.com/photo-1761600577035-c9cb717c7059?auto=format&fit=crop&w=1600&q=80",
    alt: "Minimal modern building with strong geometric shadows",
    label: "architecture.jpg",
  },
} as const;

function ThumbnailRemoveVisibilityExample() {
  return (
    <Stack direction="row" gap="6" align="start">
      <Stack gap="2" align="center">
        <Thumbnail
          {...thumbnailPhotos.moraineLake}
          onRemove={() => undefined}
          showRemoveOn="hover"
        />
        <Text size="s" color="subtle">
          Hover
        </Text>
      </Stack>
      <Stack gap="2" align="center">
        <Thumbnail
          {...thumbnailPhotos.lakeMatheson}
          onRemove={() => undefined}
          showRemoveOn="always"
        />
        <Text size="s" color="subtle">
          Always
        </Text>
      </Stack>
    </Stack>
  );
}
```

## Variants

loaded, isLoading, isUploading, disabled, remove: hover, remove: always

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| src / alt | string | — | Image source and alternative text. |
| label | string | — | Accessible file name, group label, and native hover title. |
| isLoading | boolean | false | Replaces preview with a skeleton. |
| isUploading | boolean | false | Shows upload progress over preview. |
| disabled | boolean | false | Disables preview and remove interactions. |
| onClick | MouseEventHandler<HTMLButtonElement> | — | Makes the preview actionable and handles activation. |
| onRemove | MouseEventHandler<HTMLButtonElement> | — | Shows and handles the independent remove control. |
| showRemoveOn | always \| hover | hover | Controls persistent or interaction-revealed removal. |
| native props | React.HTMLAttributes<HTMLDivElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

Use `alt` to describe meaningful image content. Omit it for decorative media; Thumbnail then hides the image from assistive technology. When the preview is actionable, `label`, then `alt`, supplies the button name. A remove action is named “Remove” plus the file label. Loading is decorative; uploading includes a named Loader but applications should announce completion separately when it matters. Disabled preview and remove controls retain native disabled behavior.

Source: https://zenos-ui.pages.dev/components/thumbnail/