# Galleria

A main image with a strip of thumbnails, captions and an optional full-screen viewer.

- Package: [@vigdx/ui](https://www.npmjs.com/package/@vigdx/ui)
- Selectors: `vig-galleria`, `ng-template[vigGalleriaItem]`, `ng-template[vigGalleriaThumbnail]`, `ng-template[vigGalleriaCaption]`
- Source: [libs/ui/src/lib/organisms/galleria/galleria.ts](https://github.com/bakyurekk/vigdx/blob/main/libs/ui/src/lib/organisms/galleria/galleria.ts)

```typescript title="Import"
import { Galleria, GalleriaItem, GalleriaThumbnail, GalleriaCaption } from '@vigdx/ui/galleria';
```

## Basic, full screen

`items` are `GalleriaImage`s (`src`, `alt`, optional `thumbnailSrc`, `previewSrc`, `srcset`, `width`, `height`, `caption`) or your own objects extending it. `[(activeIndex)]` is two-way: it is an item index (a carousel's `page` counts pages of slides instead). `fullscreen` adds a button that opens the same viewer as `vig-image`, where the arrow keys step through the images.

```typescript title="galleria-basic.ts"
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { Galleria } from '@vigdx/ui/galleria';

import { PHOTOS } from '../../image/demos/photos';

@Component({
  selector: 'app-galleria-basic',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Galleria],
  template: `
    <vig-galleria [items]="photos" [(activeIndex)]="active" fullscreen class="max-w-xl" />
    <p class="text-sm text-muted-foreground">Active index: {{ active() }}</p>
  `,
})
export class GalleriaBasicDemo {
  protected readonly photos = PHOTOS;
  protected readonly active = signal(0);
}
```

## Templates and circular

`vigGalleriaCaption`, `vigGalleriaThumbnail` and `vigGalleriaItem` (the main image) receive the item typed from `…Of`. `circular` wraps previous and next around. The stage shape is the `--aspect-galleria` token (4 / 3).

```typescript title="galleria-templates.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Galleria, GalleriaCaption, GalleriaThumbnail } from '@vigdx/ui/galleria';

import { PHOTOS } from '../../image/demos/photos';

@Component({
  selector: 'app-galleria-templates',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Galleria, GalleriaCaption, GalleriaThumbnail],
  template: `
    <vig-galleria [items]="photos" circular class="max-w-xl">
      <ng-template vigGalleriaCaption [vigGalleriaCaptionOf]="photos" let-photo>
        <strong>{{ photo.caption }}</strong>
        <span class="text-muted-foreground"> · {{ photo.region }}</span>
      </ng-template>
      <ng-template vigGalleriaThumbnail [vigGalleriaThumbnailOf]="photos" let-photo>
        <img
          [src]="photo.src"
          [alt]="photo.alt"
          width="72"
          height="72"
          loading="lazy"
          decoding="async"
          class="size-full object-cover grayscale"
        />
      </ng-template>
    </vig-galleria>
  `,
})
export class GalleriaTemplatesDemo {
  protected readonly photos = PHOTOS;
}
```

## Styling hooks

Internal elements carry a stable `data-part` and the component's `data-scope`; both are public API, so removing one is a breaking change. Select a part by both, e.g. `[data-scope="galleria"][data-part="root"] { … }`: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through `aria-*` and, where listed, a `data-state`; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other `data-*` attributes listed below (such as `data-opening` while an overlay animates) are API too. See [Customizing](https://vigdx.com/docs/theming.md#customizing).

Scope: `[data-scope="galleria"]`

| Part | Element | data-state |
| --- | --- | --- |
| `root` | The host, a named `role="region"`. |   |
| `stage` | The main image area (`aspect-galleria`), the tab panel of the thumbnails. |   |
| `image` | The main `<img>` (without a `vigGalleriaItem` template). |   |
| `previous` | Previous image button over the stage. |   |
| `next` | Next image button over the stage. |   |
| `fullscreen` | With `fullscreen`: opens the viewer. |   |
| `caption` | The row with the caption and counter. |   |
| `counter` | The position, e.g. "3 of 8". |   |
| `status` | Visually hidden polite status announcing a new image (inside the viewer while open). |   |
| `thumbnails` | The `role="tablist"` strip, scrolling with snap. |   |
| `thumbnail` | One thumbnail tab; the selected one has a border (Highlight in forced colors), focus an outline. | `active, inactive` |
| `viewer` | The full-screen native modal `<dialog>`; its `::backdrop` is `--color-backdrop-strong`. | `open, closed` |
| `viewer-toolbar` | The row of viewer controls. |   |
| `viewer-zoom-level` | The visible zoom percentage (hidden from screen readers). |   |
| `viewer-status` | Visually hidden polite status with the zoom level, debounced for wheel and pinch. |   |
| `viewer-zoom-out` | Zoom out button (`aria-disabled` when fitted). |   |
| `viewer-zoom-in` | Zoom in button (`aria-disabled` at 400%). |   |
| `viewer-rotate` | Rotate a quarter turn clockwise (R; Shift+R back). |   |
| `viewer-reset` | Back to fitted and upright (0). |   |
| `viewer-close` | Close button; takes focus when the viewer opens. |   |
| `viewer-stage` | The area around the image: pinch, wheel and drag; a press on it closes. | `fitted, zoomed` |
| `viewer-image` | The image, transformed by zoom, rotation and panning. |   |
| `viewer-caption` | The caption under the image (hidden when empty). |   |
| `viewer-previous` | Previous image button in the viewer. |   |
| `viewer-next` | Next image button in the viewer. |   |

| Attribute | Meaning |
| --- | --- |
| `data-opening` | On the overlay element (panel or `<dialog>`) while its entrance transition plays; removed once it settles (2s at most). Style the entrance with `data-opening:` utilities. |
| `data-closing` | On the overlay element while its exit transition plays, before it closes; removed once it settles (2s at most). Style the closed look with `data-closing:` utilities. |

## Accessibility

- The thumbnails are an APG tab list with automatic activation, and the main image is its tab panel: one tab stop, ← → (mirrored in right-to-left pages), Home and End move and show; each tab is named by its image's `alt`.
- The selected thumbnail has a border (Highlight in forced colors) and focus an outline (CanvasText there), so both show at once; inactive ones are only dimmed as decoration. Thumbnails load lazily and scroll in their own strip with scroll snap.
- A polite status announces the position and alt text ("3 of 8: Crater lake") once quick steps come to rest, from inside the viewer while it is open. With a single image the stage is a named group rather than a tab panel.
- Previous and next buttons step through the images; when one becomes disabled while focused, focus moves to the other. The full-screen viewer follows the [image viewer](https://vigdx.com/components/image.md)'s keyboard and focus rules, with the arrow keys stepping through images while not zoomed.

## API

### Galleria

Selector: `vig-galleria` · Kind: component

A main image with a strip of thumbnails. The thumbnails are an APG tab list with automatic activation (arrow keys mirrored in RTL, Home, End; one tab stop) controlling the main image, its tab panel; previous/next buttons step through the images. `fullscreen` opens the active image in the same viewer as `vig-image` (zoom, rotate, arrow keys between images).

`items` are `GalleriaImage`s, or your own objects extending it; the `vigGalleriaItem`, `vigGalleriaThumbnail` and `vigGalleriaCaption` templates receive them typed.

**Example :**

```html
<vig-galleria [items]="photos" [(activeIndex)]="current" fullscreen />
```

While the fullscreen viewer plays its entrance or exit transition, its `<dialog>` carries `data-opening` or `data-closing` (stable hooks for styling and for waiting in tests; see the theming guide). data-opening data-closing

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `activeIndex` (model) | `number` | `0` | Two-way: the zero-based position of the image shown (an item index, unlike a carousel's `page`, which counts pages of several slides). |
| `circular` | `boolean` | `false` | Previous on the first image goes to the last, and next on the last to the first. |
| `fullscreen` | `boolean` | `false` | Offers the full-screen viewer (button on the image). |
| `items` | `readonly T[]` | `[]` | The images, in order. |
| `labels` | `Partial<GalleriaLabels>` | — | Texts (i18n) over the locale defaults. |
| `open` (model) | `boolean` | `false` | Two-way: whether the full-screen viewer is open. |
| `thumbnails` | `boolean` | `true` | Shows the thumbnail strip. Default `true`. |

#### Outputs

| Name | Payload | Description |
| --- | --- | --- |
| `activeIndexChange` | `number` | Two-way: the zero-based position of the image shown (an item index, unlike a carousel's `page`, which counts pages of several slides). |
| `openChange` | `boolean` | Two-way: whether the full-screen viewer is open. |

#### Methods

| Signature | Description |
| --- | --- |
| `step(direction: -1 \| 1): void` | Shows the previous (-1) or next (1) image, wrapping when `circular`. |

### GalleriaItem

Selector: `ng-template[vigGalleriaItem]` · Kind: directive

Replaces the main image (e.g. a `<picture>` or a video poster). Bind the items to `vigGalleriaItemOf` to type `let-item`.

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `vigGalleriaItemOf` | `readonly T[] \| null \| undefined` | `undefined` | Type-only: the galleria's items, so `let-item` is typed. Not read at runtime. |

### GalleriaThumbnail

Selector: `ng-template[vigGalleriaThumbnail]` · Kind: directive

Replaces the content of each thumbnail tab. Bind the items to `vigGalleriaThumbnailOf`.

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `vigGalleriaThumbnailOf` | `readonly T[] \| null \| undefined` | `undefined` | Type-only: the galleria's items, so `let-item` is typed. Not read at runtime. |

### GalleriaCaption

Selector: `ng-template[vigGalleriaCaption]` · Kind: directive

The caption of the active item, under the main image and in the full-screen viewer. Bind the items to `vigGalleriaCaptionOf`.

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `vigGalleriaCaptionOf` | `readonly T[] \| null \| undefined` | `undefined` | Type-only: the galleria's items, so `let-item` is typed. Not read at runtime. |
