@molecule/app-image-gallery-editor-react

Feature · image-gallery-editor · App (browser) · v5.1.1 · Apache-2.0

Hero drop zone + thumbnail slot grid

npm install @molecule/app-image-gallery-editor-react

npm · Source on GitHub

How it works

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

import { useState } from 'react'
import type { PickedFile } from '@molecule/app-filesystem'
import { ImageGalleryEditor } from '@molecule/app-image-gallery-editor-react'

function GalleryEditor({
  uploadImages,
}: {
  uploadImages: (files: readonly PickedFile[]) => Promise<(string | null)[]>
}) {
  const [slots, setSlots] = useState<(string | null)[]>(Array(4).fill(null))
  return (
    <ImageGalleryEditor
      slots={slots}
      onChange={setSlots}
      onPickFiles={uploadImages}
      header={<h3>Image Gallery</h3>}
      counter={`${slots.filter(Boolean).length} / 24 Photos`}
    />
  )
}

Works with: @molecule/app-filesystem, @molecule/app-icons, @molecule/app-logger, @molecule/app-react, @molecule/app-ui, @molecule/app-ui-react

Reference

@molecule/app-image-gallery-editor-react — hero drop zone + side grid of thumbnail slots. Click an empty slot or the drop zone to upload, or drop image files on the drop zone to fill the empty slots in order; click a filled slot to remove (confirmed via the shared ConfirmDialog from @molecule/app-ui-react). The drop zone and every slot are keyboard buttons: Enter and Space do what a click does.

Stateless about persistence — the consumer owns the slot array and handles uploads via onPickFiles. The editor owns the lifetime of default local previews.

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 { useState } from 'react'
import type { PickedFile } from '@molecule/app-filesystem'
import { ImageGalleryEditor } from '@molecule/app-image-gallery-editor-react'

function GalleryEditor({
  uploadImages,
}: {
  uploadImages: (files: readonly PickedFile[]) => Promise<(string | null)[]>
}) {
  const [slots, setSlots] = useState<(string | null)[]>(Array(4).fill(null))
  return (
    <ImageGalleryEditor
      slots={slots}
      onChange={setSlots}
      onPickFiles={uploadImages}
      header={<h3>Image Gallery</h3>}
      counter={`${slots.filter(Boolean).length} / 24 Photos`}
    />
  )
}

Type

feature

Installation

npm install @molecule/app-image-gallery-editor-react @molecule/app-filesystem @molecule/app-icons @molecule/app-logger @molecule/app-react @molecule/app-ui @molecule/app-ui-react base64-js react
npm install -D @types/react

API

Interfaces

ImageGalleryEditorProps

Props for ImageGalleryEditor.

interface ImageGalleryEditorProps {
  /** Ordered slots, `null` for empty. Length determines slot count. */
  slots: (string | null)[]
  onChange: (slots: (string | null)[]) => void
  /** Returns URLs for the ordered selection. Defaults to local previews owned by the editor. */
  onPickFiles?: (files: readonly PickedFile[]) => Promise<(string | null)[]> | (string | null)[]
  maxImages?: number
  /** Header heading + subtitle slot (renders left of the photo counter). */
  header?: ReactNode
  /** Photo-counter label (e.g. "3 / 24 Photos"). */
  counter?: ReactNode
  /** Drop-zone heading. Defaults through i18n (English "Drag and drop assets here"). */
  dropZoneTitle?: ReactNode
  /** Drop-zone hint. Defaults through i18n (English "or click to browse local files"). */
  dropZoneHint?: ReactNode
  /** Remove-confirmation message. Defaults through i18n (English "Remove this image?"). */
  confirmRemoveMessage?: string
  statusMessage?: ReactNode
  /**
   * Glyph rendered in empty slots — a typed `IconName` from the bonded
   * `@molecule/app-icons` set (an unknown name is a type error, not a blank).
   */
  emptySlotIcon?: IconName
}

Functions

ImageGalleryEditor(props)

Editable image gallery primitive.

function ImageGalleryEditor(props: ImageGalleryEditorProps): JSX.Element

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-filesystem ^1.1.0
  • @molecule/app-icons ^1.0.1
  • @molecule/app-logger ^1.1.0
  • @molecule/app-react ^4.13.0 || ^5.0.0
  • @molecule/app-ui ^1.14.0
  • @molecule/app-ui-react ^4.13.0
  • react ^18.0.0 || ^19.0.0

Runtime Dependencies

  • @molecule/app-filesystem

  • @molecule/app-icons

  • @molecule/app-logger

  • @molecule/app-react

  • @molecule/app-ui

  • @molecule/app-ui-react

  • base64-js

  • react

  • Styling is 100% ClassMap (getClassMap() / cm.*) — the editor renders correctly out of the box under any bonded styling library and needs NO per-app Tailwind @source scan of this package. (It previously hardcoded raw Tailwind + Material-3 utility classes that no scaffold @source-scans, so even the hidden file input never generated a rule and rendered visible; the file input is now hidden with an inline display:none.) The few style={...} values (grid-column span, aspect ratio, corner radius, the dashed drop-zone border, object-fit, dim opacity, display:none) are the documented ClassMap-can't-express cases and use real theme tokens.

  • Icons are real SVG glyphs from @molecule/app-ui-react's <Icon> (upload, trash, and the emptySlotIcon — a typed IconName) — NO Material Symbols font to load. Requires a bonded @molecule/app-icons set.

  • The filled-slot delete affordance is always visible (touch-friendly) rather than hover-revealed.

  • Its text (the drop-zone heading and hint, the remove confirmation, the slots' accessible names) flows through t() with English defaultValue fallbacks under the imageGalleryEditor.* keys, so the @molecule/app-locales-image-gallery-editor companion bond (or the host app's own locale) translates it. dropZoneTitle, dropZoneHint and confirmRemoveMessage override it per instance.

  • The device entry describes selecting a file in the picker. Browsers also display drop instructions.

  • A drop that carries a file other than an image is refused, as the picker (accept="image/*") would refuse it.

  • onPickFiles receives portable files. Use file.appendTo(formData, field) to upload each image and return the persisted URL, or null for an empty slot.

  • getClassMap() requires a bonded ClassMap for the layout primitives.

Translations

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