Gallery

Records as cards with a cover image.

Installation

Usage

import { Gallery } from "./ui/uicontext/components/kit/Gallery.ts"import type { Item, Property } from "./ui/uicontext/components/kit/Property.ts"
const Message = UiSchema.TaggedEnum({ RequestedOpenProject: { id: Schema.String } })export const ProjectGallery = (h: Html.H<typeof Message.Type>, projects: ReadonlyArray<Item>, fields: ReadonlyArray<Property>) =>	Gallery(h, {		props: { label: "Projects", records: projects, fields, view: { cover: "cover" } },		onEmit: {			RequestedOpen: ({ item }) => Message.RequestedOpenProject({ id: item }),			RequestedCreate: () => undefined,			RequestedEdit: () => undefined,			RequestedAction: () => undefined,			RequestedReorder: () => undefined,			RequestedView: () => undefined,			Selected: () => undefined,		},	})

Examples

Small cards

size: "small" fits more in a row, fit: "contain" shows the whole image, and cardFields limits what a card says.

Empty

What the gallery says when no card is left to show.

API reference

Props

Gallery props
NameTypeDefaultDescription
labelrequiredstring—What these records are, for screen readers and agents: "Projects"
recordsrequiredItem[]—The records to show as cards
fieldsrequiredProperty[]—The fields a card may show, in order; the title is the record's own
viewViewInput—How records show: cover is the image field, with filter, sort, hidden and order
cardFieldsnumber4How many fields a card shows at most; 4 by default
size"small" | "medium" | "large"mediumHow wide a card is: small fits more in a row, large shows bigger covers; medium by default
fit"cover" | "contain"coverFill the cover box and crop ("cover", photos), or show the whole image ("contain", logos); cover by default
createstring—A last card with this label ("New project"), emitting RequestedCreate
loadingboolean—Shows placeholder cards while the records load
empty{ title, hint }—What to say when no card is left to show, with an optional hint
localestring—The locale numbers and dates are formatted in; the browser's by default
agentIdstringgallery:<label>This gallery's id for agents, unique on the page; gallery:<label> by default

Events

Gallery events
EventPayloadDescription
RequestedEdit{ request: string; item: string; key: string; value: Value }A value the person changed; answer through outcomes with the same request
RequestedOpen{ item: string }Open the record's page
RequestedCreate{ group?: string; title?: string; values?: Record<string, Value> }A new record, in the group it was added from ("" for the empty group)
RequestedAction{ action: string; items: string[] }One of the view's actions, on these records
RequestedReorder{ item: string; before: string | null }Move item before before, or last when it's null
RequestedView{ view: View }The person changed how the view shows records (its sort, grouping, widths); pass it back as view
Selected{ items: string[] }The selection changed

Agent actions

What agents can do with Gallery
ActionDescription
ActivatedRecordOpen a record by id (see page_query for every card)
ClickedCreateStart a new record

Accessibility

  • Cards are a labelled list; each card's title is a link or a button that opens the record.
  • Covers are decorative, and outside links say which field and record they belong to.
  • Agents read the cards and open one by id.

Source