# Media Gallery
A media gallery displays a group of thumbnails in a gallery format, allowing users to preview and select different media.

## Overview
Media galleries are ideal for showcasing multiple images or other media related to a single product or topic. They provide an interactive way to browse through content with thumbnail previews that update the primary display when selected.

<daff-docs-example-viewer example="basic-media-gallery"></daff-docs-example-viewer>

## Best practices

**When to use**
- Showcasing multiple related images for a product or topic
- Providing an interactive way to browse through visual content

**When not to use**
- You only have one image (use the [image](/libs/design/image/README.md) component instead)
- The images are unrelated to each other

## Usage

Import `DAFF_MEDIA_GALLERY_COMPONENTS` into your component:

```ts
import { DAFF_MEDIA_GALLERY_COMPONENTS } from '@daffodil/design/media-gallery';

@Component({
  selector: 'custom-component',
  templateUrl: './custom-component.component.html',
  imports: [
    DAFF_MEDIA_GALLERY_COMPONENTS,
  ],
})
export class CustomComponent {}
```

> **Deprecation notice:**
> 
> `DaffMediaGalleryModule` is deprecated. Use the standalone component imports instead.

## Anatomy
A media gallery is composed of a container and one or more thumbnails:

```html
<daff-media-gallery>
  <ng-template daffThumbnail thumbnailSrc="/thumbnail-path.jpg" label="Your description">
    <daff-image src="/image-path.jpg" alt="Your description" width="500" height="500"></daff-image>
  </ng-template>
</daff-media-gallery>
```

- **`<daff-media-gallery>`**: The wrapper component that contains all thumbnails and manages the display area.
- **`[daffThumbnail]`**: A **structural directive** that defines both the preview image and the content to display when selected. Thumbnails can contain any content type, not just images.

### Thumbnail configuration
- `thumbnailSrc` is used for the preview image rendered in the thumbnail strip.
- The content inside the template is shown as the primary view when selected.
- Include the full content for each thumbnail inside the template, even if it appears to duplicate the thumbnail image, since this is what renders in the main display area when selected.
- Always provide an accessible `label` for a thumbnail.
- The first thumbnail is selected by default.

> Never use `[daffThumbnail]` as a standalone element. It must be placed within a `<daff-media-gallery>`.

## Features

### Video thumbnails
Set the `isVideo` property on a thumbnail to display a video icon on its preview, signaling that the content opens a video.

<daff-docs-example-viewer example="media-gallery-with-video"></daff-docs-example-viewer>

### Iterating thumbnails
Use a control-flow block such as `@for` to generate thumbnails from a collection of media.

<daff-docs-example-viewer example="iterated-media-gallery"></daff-docs-example-viewer>

### Skeleton screen
Set the `skeleton` property to `true` to display a placeholder skeleton screen that helps reduce load-time frustration.

<daff-docs-example-viewer example="skeleton-media-gallery"></daff-docs-example-viewer>

### Aspect ratio
Use a consistent aspect ratio across all content to avoid layout shifts. Mismatched content sizes can cause the primary content area to shift as different thumbnails are selected.

Thumbnails are rendered in a square by default, so a 1:1 ratio is recommended, but not required since thumbnails are automatically centered horizontally and vertically.

<daff-docs-example-viewer example="mismatched-sizes-media-gallery"></daff-docs-example-viewer>

## Accessibility

### Built-in behavior
- Each thumbnail is rendered as a button with an autogenerated `aria-controls` value that matches the `id` of the content container displayed when the thumbnail is selected.
- These `id` values are autogenerated but can be overridden by providing a custom id to the `<daff-media-gallery>` element.

### Developer responsibilities
- Always provide an accessible label for each thumbnail using the `label` attribute.
