Rows of records, grouped and sorted, that you edit in place.
- JJDown arrow↓
- Next record
- KKUp arrow↑
- Previous record
- Shift J⇧JShift K⇧K
- Extend the selection
- XX
- Select or unselect
- SpaceSpace
- Peek at the record; Escape closes it
- Return↵
- Open the record
- SS
- Change Status on the focused or selected records
- PP
- Change Priority on the focused or selected records
- AA
- Change Assignee on the focused or selected records
- EscapeEsc
- Clear the selection
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { Outcome } from "./ui/uicontext/components/domain/Outcome.ts"import { View, viewOf } from "./ui/uicontext/components/domain/Record.ts"import { List } from "./ui/uicontext/components/kit/List.ts"import { Item, Value } from "./ui/uicontext/components/kit/Property.ts"import { collectionKeymap, KeymapLegend } from "./ui/uicontext/components/kit/RecordKeys.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { applyEdit, issueFields, issues, issueShortcuts } from "./issues.ts"const styles = stylex.create({ stack: { display: "grid", gridTemplateColumns: "minmax(0, 1fr)", gap: 20 }, frame: { blockSize: 420, inlineSize: "100%" },})const Message = UiSchema.TaggedEnum({ RequestedEditIssue: { request: Schema.String, item: Schema.String, key: Schema.String, value: Value }, RequestedIssueAction: { action: Schema.String, items: Schema.Array(Schema.String) }, RequestedIssueView: { view: View },})export const IssueList = Html.component({ name: "IssueList", model: Schema.Struct({ records: Schema.Array(Item), outcomes: Schema.Array(Outcome), view: View }), message: Message,}).make({ init: () => ({ records: issues, outcomes: [], view: viewOf({ groupBy: "status", sort: [{ key: "priority", direction: "asc" }] }, "list") }), update: { RequestedEditIssue: ($, { request, item, key, value }) => $.evolve({ records: (records) => records.map((r) => (r.id === item ? applyEdit(r, key, value) : r)), outcomes: (outcomes) => [...outcomes.slice(-10), { _tag: "Accepted", request }], }), RequestedIssueAction: ($, { action, items }) => action === "archive" ? $.evolve({ records: (all) => all.filter((r) => !items.includes(r.id)) }) : $.model, RequestedIssueView: ($, { view }) => $.evolve({ view }), }, view: (h, { records, outcomes, view }) => h.div.attrs(sx(styles.stack)).children( h.div.attrs(sx(styles.frame)).children( List(h, { props: { label: "Issues", records, fields: issueFields, view, columns: [ { key: "priority", at: "start", compact: true }, { key: "status", at: "start", compact: true }, { key: "labels" }, { key: "impact" }, { key: "due" }, { key: "assignee", compact: true }, ], // j/k move, x selects, Space peeks, Enter opens; s, p and a open these pickers shortcuts: issueShortcuts, actions: [ { id: "archive", label: "Archive" }, { id: "trash", label: "Delete", tone: "danger", consequential: true }, ], empty: { title: "No issues", hint: "Issues you create show up here." }, outcomes, }, onEmit: { RequestedEdit: (edit) => Message.RequestedEditIssue(edit), RequestedAction: ({ action, items }) => Message.RequestedIssueAction({ action, items }), RequestedView: ({ view }) => Message.RequestedIssueView({ view }), RequestedOpen: () => undefined, RequestedReorder: () => undefined, RequestedCreate: () => undefined, Selected: () => undefined, }, }), ), KeymapLegend(h, collectionKeymap(issueShortcuts), "List keyboard shortcuts"), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/listUsage
import type { Outcome } from "./ui/uicontext/components/domain/Outcome.ts"import { type Item, type Property, Value } from "./ui/uicontext/components/domain/Record.ts"import { List } from "./ui/uicontext/components/kit/List.ts"const Message = UiSchema.TaggedEnum({ RequestedEditTask: { request: Schema.String, item: Schema.String, key: Schema.String, value: Value }, OpenedTask: { id: Schema.String },})export const TaskList = ( h: Html.H<typeof Message.Type>, tasks: ReadonlyArray<Item>, fields: ReadonlyArray<Property>, outcomes: ReadonlyArray<Outcome>,) => List(h, { props: { label: "Tasks", records: tasks, fields, view: { groupBy: "status" }, columns: [{ key: "status", at: "start", compact: true }, { key: "assignee", compact: true }], outcomes, }, onEmit: { RequestedEdit: (edit) => Message.RequestedEditTask(edit), RequestedOpen: ({ item }) => Message.OpenedTask({ id: item }), RequestedView: () => undefined, RequestedAction: () => undefined, RequestedReorder: () => undefined, RequestedCreate: () => undefined, Selected: () => undefined, }, })Examples
Ordered by hand
A flat list people put in order. Drag a row, or press Alt+Up and Alt+Down on it.
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { List } from "./ui/uicontext/components/kit/List.ts"import { Item } from "./ui/uicontext/components/kit/Property.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { issueFields, issues } from "./issues.ts"// A flat list in an order people set by hand: drag a row, or press Alt+Up and Alt+Down on it. Each// move asks with RequestedReorder; the app keeps the order.const styles = stylex.create({ frame: { blockSize: 320, inlineSize: "100%" },})const Message = UiSchema.TaggedEnum({ RequestedMove: { item: Schema.String, before: Schema.NullOr(Schema.String) },})const move = (records: ReadonlyArray<Item>, item: string, before: string | null): ReadonlyArray<Item> => { const moving = records.find((r) => r.id === item) if (moving === undefined) return records const rest = records.filter((r) => r.id !== item) const at = before === null ? rest.length : rest.findIndex((r) => r.id === before) return [...rest.slice(0, at), moving, ...rest.slice(at)]}export const PlannedList = Html.component({ name: "PlannedList", model: Schema.Struct({ records: Schema.Array(Item) }), message: Message,}).make({ init: () => ({ records: issues.filter((issue) => issue.values["status"] === "todo") }), update: { RequestedMove: ($, { item, before }) => $.evolve({ records: (records) => move(records, item, before) }), }, view: (h, { records }) => h.div.attrs(sx(styles.frame)).children( List(h, { props: { label: "Next up", records, fields: issueFields, columns: [{ key: "priority", at: "start", compact: true }, { key: "estimate" }, { key: "assignee", compact: true }], reorderable: true, selectable: false, }, onEmit: { RequestedReorder: ({ item, before }) => Message.RequestedMove({ item, before }), RequestedEdit: () => undefined, RequestedOpen: () => undefined, RequestedView: () => undefined, RequestedAction: () => undefined, RequestedCreate: () => undefined, Selected: () => undefined, }, }), ),})Empty
What a list says before it has records, with a button for the first one.
No issues yet
Issues for the mobile app show up here.
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { List } from "./ui/uicontext/components/kit/List.ts"import { Item } from "./ui/uicontext/components/kit/Property.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { issueFields } from "./issues.ts"// With no records, the list shows its empty state, and `empty.create` offers the first one.const styles = stylex.create({ frame: { blockSize: 280, inlineSize: "100%" },})const Message = UiSchema.TaggedEnum({ RequestedNewIssue: {} })export const EmptyList = Html.component({ name: "EmptyList", model: Schema.Struct({ records: Schema.Array(Item) }), message: Message,}).make({ init: () => ({ records: [] }), update: { RequestedNewIssue: ($) => $.evolve({ records: (records) => [ ...records, { id: `eng-${150 + records.length}`, prefix: `ENG-${150 + records.length}`, title: "Untitled issue", values: { status: "todo" } }, ], }), }, view: (h, { records }) => h.div.attrs(sx(styles.frame)).children( List(h, { props: { label: "Mobile app issues", records, fields: issueFields, columns: [{ key: "status", at: "start", compact: true }], empty: { title: "No issues yet", hint: "Issues for the mobile app show up here.", create: "New issue" }, }, onEmit: { RequestedCreate: () => Message.RequestedNewIssue(), RequestedEdit: () => undefined, RequestedOpen: () => undefined, RequestedView: () => undefined, RequestedAction: () => undefined, RequestedReorder: () => undefined, Selected: () => undefined, }, }), ),})API reference
Props
| Name | Type | Default | Description |
|---|---|---|---|
labelrequired | string | — | The list's accessible name: "Issues" |
agentId | string | list:<label> | This list's id for agents, unique on the page; list:<label> by default |
recordsrequired | Item[] | — | The records to show, in the order the app gives them |
fieldsrequired | Property[] | — | The fields the records share: their kinds, choices and formats |
view | ViewInput | — | How the records show: its filter, sort, groupBy, hidden and order |
columns | ListColumn[] | — | Where each shown field sits in a row; every shown field, after the title, by default |
shortcuts | FieldShortcut[] | — | Single keys that open a field's picker on the focused or selected rows: { key: "s", field: "status" } |
selectable | boolean | true | Shows a checkbox per row and the action bar; true by default |
actions | ItemAction[] | — | What the action bar offers for the selected rows |
reorderable | boolean | — | Rows can be moved with Alt+Arrow keys or dragged, for a manually ordered list |
create | string | — | Names a group header's + button ("New issue"), which emits RequestedCreate with the group; absent hides it |
loading | boolean | — | Show placeholder rows while the records load |
empty | { title, hint, create } | — | The empty state; create adds a button that emits RequestedCreate |
outcomes | Outcome[] | — | The app's answers to edit requests |
notice | string | null | — | A sentence about the last bulk action: "2 issues couldn't be archived: they're locked" |
rowHeight | number | 40 | A row's height in pixels until measured; 40 by default |
locale | string | — | For Intl formatting and sorting; the browser's language by default |
fresh | string[] | — | Records the app just added, tinted until it takes them off the list |
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 |
|---|---|
CommittedEdit | Set one field of one row. value: an option value (see the field's choices), a list of them, text, a number, an ISO date, true/false, or null to clear |
RequestedSelection | Select rows by id, replacing the selection ([] clears it) |
ClickedAction | Run one of the list's actions on the selected rows; destructive ones name the selection as the target |
ActivatedRow | Open a row, as Enter on it does |
ClickedPeek | Peek at a row: its fields in a side sheet, without leaving the list |
ToggledGroup | Collapse or expand a group by its value |
MovedRow | Move a row before another (or to the end with before: null) |
Accessibility
- A tree grid: arrows move between rows and cells, Enter edits or opens, Space or X selects, Shift extends the selection, Mod+A selects all.
- A locked cell, a refused edit or a note on a value shows its reason when the cell has focus or is tapped, and is read as the cell's description.