Componente
Gallery
Uma galeria de mídia com uma faixa de miniaturas sincronizada. Vincule um array de itens, renderize cada slide e miniatura via templates, e escolha navegadores, indicadores, posição das miniaturas, loop e autoplay.
Galeria básica
Oak leaves · 1/4
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { HbGalleryImports } from '@herbst/ui';
interface Plate {
title: string;
src: string;
}
function plate(title: string, from: string, to: string): Plate {
const src =
'data:image/svg+xml,' +
encodeURIComponent(
"<svg xmlns='http://www.w3.org/2000/svg' width='640' height='400'>" +
`<defs><linearGradient id='g' x1='0' y1='0' x2='1' y2='1'><stop offset='0' stop-color='${from}'/><stop offset='1' stop-color='${to}'/></linearGradient></defs>` +
"<rect width='640' height='400' fill='url(#g)'/>" +
`<text x='32' y='368' font-family='Georgia, serif' font-size='28' fill='#F5F1E6'>${title}</text></svg>`,
);
return { title, src };
}
@Component({
selector: 'hb-demo-gallery-basic',
imports: [HbGalleryImports],
template: `
<div class="flex w-full max-w-lg flex-col gap-2">
<hb-gallery class="w-full" [hbItems]="items" (hbSelect)="current.set($event)">
<ng-template hbGalleryItem let-item let-index="index">
<img [src]="item.src" [alt]="item.title" class="aspect-[16/10] w-full object-cover" />
</ng-template>
<ng-template hbGalleryThumb let-item>
<img [src]="item.src" [alt]="item.title" class="aspect-square size-full object-cover" />
</ng-template>
</hb-gallery>
<p class="font-mono text-[12px] text-muted-foreground">
{{ items[current()].title }} · {{ current() + 1 }}/{{ items.length }}
</p>
</div>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class HbDemoGalleryBasicComponent {
protected readonly current = signal(0);
protected readonly items: Plate[] = [
plate('Oak leaves', '#A64B2A', '#6B7A55'),
plate('Foggy morning', '#6B7A55', '#3E4C3A'),
plate('Forest path', '#B98A3E', '#A64B2A'),
plate('Chestnuts', '#3E4C3A', '#6B7A55'),
];
}
Posição das miniaturas e indicadores
Autoplay, loop e apenas indicadores
Referência de API
hb-gallery — content
| Propriedade | Descrição | Tipo | Padrão |
|---|---|---|---|
| [hbItems] | O array de itens renderizados como slides e miniaturas. | unknown[] | [] |
| ng-template[hbGalleryItem] | Template de cada slide. Contexto: $implicit = item, index. | template | — |
| ng-template[hbGalleryThumb] | Template de cada miniatura. Contexto: $implicit = item, index. | template | — |
| (hbSelect) | Emite o índice do slide ativo sempre que a seleção muda. | number | — |
hb-gallery — chrome
| Propriedade | Descrição | Tipo | Padrão |
|---|---|---|---|
| [hbShowThumbnails] | Mostra a faixa de miniaturas sincronizada. | boolean | true |
| [hbThumbnailsPosition] | Onde a faixa de miniaturas fica em relação ao viewport principal. | 'top' | 'bottom' | 'left' | 'right' | 'bottom' |
| [hbShowItemNavigators] | Mostra os botões de seta anterior/próximo sobre o viewport principal. | boolean | true |
| [hbShowIndicators] | Mostra os indicadores de ponto sobre o viewport principal. | boolean | false |
hb-gallery — behaviour & sizing
| Propriedade | Descrição | Tipo | Padrão |
|---|---|---|---|
| [hbLoop] | Retorna do último slide de volta ao primeiro. | boolean | false |
| [hbAutoplay] / [hbDelay] | Avança os slides automaticamente, com o atraso em milissegundos. O autoplay pausa ao passar o mouse. | boolean / number | false / 4000 |
| [hbThumbSize] | Largura da miniatura em pixels para faixas horizontais (top/bottom). | number | 72 |
| [hbThumbWidth] / [hbThumbViewport] | Largura da faixa e altura do viewport em pixels para faixas verticais (left/right). | number | 88 / 320 |