@molecule/app-image-gallery-vue

Feature · image-gallery · App (browser) · v1.1.2 · Apache-2.0

Main image + thumbnail grid gallery with selection + optional upload

npm install @molecule/app-image-gallery-vue

npm · Source on GitHub

How it works

@molecule/app-image-gallery-vue is a ready-made image-gallery feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.

import { createApp, defineComponent, h, ref } from 'vue'
import { ImageGallery } from '@molecule/app-image-gallery-vue'

const images = [
  'https://example.com/photo-1.jpg',
  'https://example.com/photo-2.jpg',
  'https://example.com/photo-3.jpg',
]

const Gallery = defineComponent({
  setup() {
    const active = ref(0)
    // Uncontrolled — manages its own selected index;
    // pass `selectedIndex: active.value` and `onSelect: (i) => (active.value = i)`
    // to drive it from the caller instead.
    return () => h(ImageGallery, { images, maxThumbnails: 4 })
  },
})

createApp(Gallery).mount('#app')

Works with: @molecule/app-ui, @molecule/app-ui-vue, @molecule/app-vue

Reference

Vue image gallery.

Exports <ImageGallery> — main image + thumbnail grid with controlled-optional selection and "+N" overflow summarisation. It is the Vue counterpart of @molecule/app-image-gallery-react: same props and the same DOM for the same input.

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Quick Start

import { createApp, defineComponent, h, ref } from 'vue'
import { ImageGallery } from '@molecule/app-image-gallery-vue'

const images = [
  'https://example.com/photo-1.jpg',
  'https://example.com/photo-2.jpg',
  'https://example.com/photo-3.jpg',
]

const Gallery = defineComponent({
  setup() {
    const active = ref(0)
    // Uncontrolled — manages its own selected index;
    // pass `selectedIndex: active.value` and `onSelect: (i) => (active.value = i)`
    // to drive it from the caller instead.
    return () => h(ImageGallery, { images, maxThumbnails: 4 })
  },
})

createApp(Gallery).mount('#app')

Type

feature

Installation

npm install @molecule/app-image-gallery-vue @molecule/app-ui @molecule/app-ui-vue @molecule/app-vue vue

API

Interfaces

ImageGalleryProps

Props accepted by the ImageGallery component.

interface ImageGalleryProps {
  /** Image URLs in display order. */
  images: string[]
  /** Controlled selected index — caller owns state. */
  selectedIndex?: number
  /** Called when a thumbnail is clicked. */
  onSelect?: (index: number) => void
  /** Max thumbnails shown. Extra are summarised as "+N". */
  maxThumbnails?: number
  /**
   * Alt-text for screen readers. Applied per-image; falls back through i18n to
   * `'Image {{number}}'` (`imageGallery.alt.fallback`).
   */
  alts?: string[]
  /** Extra classes on the outer wrapper. */
  className?: string
}

Constants

ImageGallery

Main image + thumbnail grid gallery. Controlled-optional: when selectedIndex is omitted the component tracks its own selection.

Used for product images, property listings, portfolio galleries.

const ImageGallery: DefineComponent<
  ExtractPropTypes<{
    images: { type: PropType<string[]>; required: true }
    selectedIndex: NumberConstructor
    onSelect: PropType<(index: number) => void>
    maxThumbnails: { type: NumberConstructor; default: number }
    alts: PropType<string[]>
    className: StringConstructor
  }>,
  () => VNode | null,
  {},
  {},
  {},
  ComponentOptionsMixin,
  ComponentOptionsMixin,
  {},
  string,
  PublicProps,
  Readonly<
    ExtractPropTypes<{
      images: { type: PropType<string[]>; required: true }
      selectedIndex: NumberConstructor
      onSelect: PropType<(index: number) => void>
      maxThumbnails: { type: NumberConstructor; default: number }
      alts: PropType<string[]>
      className: StringConstructor
    }>
  > &
    Readonly<{}>,
  { maxThumbnails: number },
  {},
  {},
  {},
  string,
  ComponentProvideOptions,
  true,
  {},
  any
>
  • props — Component props (see ImageGalleryProps).

Returns: The image gallery component.

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-vue ^1.1.0
  • @molecule/app-vue ^3.5.0 || ^4.0.0
  • vue ^3.4.0

Runtime Dependencies

  • @molecule/app-ui

  • @molecule/app-ui-vue

  • @molecule/app-vue

  • vue

  • Renders nothing when images is empty — no empty-state UI.

  • maxThumbnails doubles as the thumbnail grid's column count. Any value is safe: it is snapped to the nearest column count the ClassMap grid actually supports (1-6 or 12), so a real grid-cols-* class is always emitted and extra thumbnails wrap onto additional rows instead of collapsing.

  • Default alt text falls back through i18n to "Image N" (imageGallery.alt.fallback, English defaultValue) — pass alts with per-image strings in apps that know them.

  • getClassMap() requires a bonded ClassMap (e.g. @molecule/app-ui-tailwind).

Translations

Translation strings are provided by @molecule/app-locales-image-gallery.