image-gallery
A photo gallery: a masonry grid in reading order and a lightbox with previous and next (arrow keys too). Photos come from items, or from src, a gallery.json that npx zubra-imager <photos> writes (sizes in AVIF, WebP and JPEG, alt text, placeholders). index is the open photo (-1 when closed) and is two-way.
Try it: events appear here (indexchange).
Source: image-gallery.zb, and its registry item.
Install
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/image-gallery.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/image-gallery.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/image-gallery.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/image-gallery.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/image-gallery.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/image-gallery.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/image-gallery.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/image-gallery.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/image-gallery.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/image-gallery.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/image-gallery.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/image-gallery.json
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/image-gallery.js"></script>The compiled install writes src/components/zubra/image-gallery.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.
Usage
<image-gallery label="Sample illustrations" src="gallery/gallery.json"></image-gallery>
<script type="module">
import './components/zubra/image-gallery.js';
const element = document.querySelector('image-gallery');
element.addEventListener('indexchange', (event) => console.log('indexchange', event.detail));
</script>import './components/zubra/image-gallery.js';
export function ImageGalleryExample() {
return (
<image-gallery
label="Sample illustrations"
src="gallery/gallery.json"
onindexchange={(event) => console.log('indexchange', event.detail)}
></image-gallery>
);
}<script setup>
import './components/zubra/image-gallery.js';
const onIndexchange = (event) => console.log('indexchange', event.detail);
</script>
<template>
<image-gallery
label="Sample illustrations"
src="gallery/gallery.json"
@indexchange="onIndexchange"
></image-gallery>
</template>
<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) --><script>
import './components/zubra/image-gallery.js';
</script>
<image-gallery
label="Sample illustrations"
src="gallery/gallery.json"
onindexchange={(event) => console.log('indexchange', event.detail)}
></image-gallery>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/image-gallery.js';
@Component({
selector: 'app-image-gallery-example',
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<image-gallery
label="Sample illustrations"
src="gallery/gallery.json"
(indexchange)="onIndexchange($event)"
></image-gallery>
`,
})
export class ImageGalleryExample {
onIndexchange(event: Event) {
console.log('indexchange', (event as CustomEvent).detail);
}
}API
| Property | Type | Default |
|---|---|---|
items | unknown[] | [] |
src | string | "" |
index | number | -1 |
label | string | "Photos" |
| Event | When |
|---|---|
indexchange | index changed; detail is the new value. |
Size
2.9 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 19.5 KB.