Records as cards with a cover image.
- TierEnterpriseOwnerMCMaya ChenARR$184,000Health★★★★★
- TierGrowthOwnerOHOmar HaddadARR$62,000Health★★★★★
- TierEnterpriseOwnerLFLena FischerARR$241,000Health★★★★★
- TierStarterARR$4,800Health★★★★★
- TierGrowthOwnerMCMaya ChenARR$38,500Health★★★★★
Open a card to see its account.
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { Gallery } from "./ui/uicontext/components/kit/Gallery.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font } from "./ui/uicontext/components/tokens.stylex.ts"import { accountFields, accounts } from "./accounts.ts"// A CRM's accounts as cards. The view's `cover` is a file field; an account without a picture, or// with one that fails to load, shows its initial so the row still lines up.const styles = stylex.create({ stack: { display: "grid", gap: 12, inlineSize: "100%" }, note: { margin: 0, color: color.muted, fontSize: font.sm },})const Message = UiSchema.TaggedEnum({ RequestedOpenAccount: { item: Schema.String } })export const AccountGallery = Html.component({ name: "AccountGallery", model: Schema.Struct({ opened: Schema.NullOr(Schema.String) }), message: Message,}).make({ init: () => ({ opened: null }), update: { RequestedOpenAccount: ($, { item }) => $.evolve({ opened: item }) }, view: (h, { opened }) => h.div.attrs(sx(styles.stack)).children( Gallery(h, { props: { label: "Accounts", agentId: "gallery:accounts", records: accounts, fields: accountFields, view: { cover: "cover", hidden: ["website"] }, cardFields: 4, create: "New account", locale: "en-US", }, onEmit: { RequestedOpen: ({ item }) => Message.RequestedOpenAccount({ item }), RequestedCreate: () => undefined, RequestedEdit: () => undefined, RequestedAction: () => undefined, RequestedReorder: () => undefined, RequestedView: () => undefined, Selected: () => undefined, }, }), h.p .attrs({ role: "status", ...sx(styles.note) }) .children(opened === null ? "Open a card to see its account." : `Opened ${accounts.find((a) => a.id === opened)?.title ?? opened}`), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/galleryUsage
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.
- TierEnterpriseOwnerLFLena Fischer
- TierEnterpriseOwnerMCMaya Chen
- TierGrowthOwnerOHOmar Haddad
- TierGrowthOwnerMCMaya Chen
- TierStarter
import type { Html } from "@effect/ui/html"import { Gallery } from "./ui/uicontext/components/kit/Gallery.ts"import { accountFields, accounts } from "./accounts.ts"// Small cards with the whole image shown, as a logo wall would, and two fields each.export const LogoGallery = <M>(h: Html.H<M>) => Gallery(h, { key: "logos", props: { label: "Accounts by logo", agentId: "gallery:logos", records: accounts, fields: accountFields, view: { cover: "cover", sort: [{ key: "arr", direction: "desc" }] }, size: "small", fit: "contain", cardFields: 2, locale: "en-US", }, onEmit: { RequestedOpen: () => undefined, RequestedCreate: () => undefined, RequestedEdit: () => undefined, RequestedAction: () => undefined, RequestedReorder: () => undefined, RequestedView: () => undefined, Selected: () => undefined, }, })Empty
What the gallery says when no card is left to show.
No churned accounts
Accounts move here when their stage is Churned.
import type { Html } from "@effect/ui/html"import { Gallery } from "./ui/uicontext/components/kit/Gallery.ts"import { accountFields } from "./accounts.ts"// No records match: the gallery says so and what to try next.export const EmptyGallery = <M>(h: Html.H<M>) => Gallery(h, { key: "empty", props: { label: "Churned accounts", agentId: "gallery:empty", records: [], fields: accountFields, view: { cover: "cover" }, empty: { title: "No churned accounts", hint: "Accounts move here when their stage is Churned." }, }, onEmit: { RequestedOpen: () => undefined, RequestedCreate: () => undefined, RequestedEdit: () => undefined, RequestedAction: () => undefined, RequestedReorder: () => undefined, RequestedView: () => undefined, Selected: () => undefined, }, })API reference
Props
| Name | Type | Default | Description |
|---|---|---|---|
labelrequired | string | — | What these records are, for screen readers and agents: "Projects" |
recordsrequired | Item[] | — | The records to show as cards |
fieldsrequired | Property[] | — | The fields a card may show, in order; the title is the record's own |
view | ViewInput | — | How records show: cover is the image field, with filter, sort, hidden and order |
cardFields | number | 4 | How many fields a card shows at most; 4 by default |
size | "small" | "medium" | "large" | medium | How wide a card is: small fits more in a row, large shows bigger covers; medium by default |
fit | "cover" | "contain" | cover | Fill the cover box and crop ("cover", photos), or show the whole image ("contain", logos); cover by default |
create | string | — | A last card with this label ("New project"), emitting RequestedCreate |
loading | boolean | — | Shows placeholder cards while the records load |
empty | { title, hint } | — | What to say when no card is left to show, with an optional hint |
locale | string | — | The locale numbers and dates are formatted in; the browser's by default |
agentId | string | gallery:<label> | This gallery's id for agents, unique on the page; gallery:<label> by default |
Events
| Event | Payload | Description |
|---|---|---|
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
| Action | Description |
|---|---|
ActivatedRecord | Open a record by id (see page_query for every card) |
ClickedCreate | Start 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.