Zubra UI
Code for
GitHub

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

Compiled (any project)
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
One file, no dependencies (5.7 KB gzipped)
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
.zb source (to edit it with Zubra)
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
No build: a script tag, straight from this site
HTML
<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

index.html
<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>
Example.jsx
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>
  );
}
Example.vue
<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('-') } } }) -->
Example.svelte
<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>
example.component.ts
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

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
itemsunknown[][]
srcstring""
indexnumber-1
labelstring"Photos"
Events
EventWhen
indexchangeindex 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.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour