A record's preview beside the list, board or grid it came from, opened with Space.
Focus a row and press Space, or hover one and press the eye.
- 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 { 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 { color, font } from "./ui/uicontext/components/tokens.stylex.ts"import { applyEdit, issueFields, issues, issueShortcuts } from "./issues.ts"// Peek is built into List, Board and Data Grid: Space on a focused row, or the eye on a hovered row,// opens the issue in a side sheet with every field. j and k step to the next and previous issue// without closing it, Mod+Enter opens its page (RequestedOpen), and Escape closes it and puts focus// back on the row it came from. Edits made in the sheet are the view's usual RequestedEdit.const styles = stylex.create({ stack: { display: "grid", gridTemplateColumns: "minmax(0, 1fr)", gap: 20 }, frame: { blockSize: 360, inlineSize: "100%" }, status: { margin: 0, color: color.muted, fontSize: font.sm },})const Message = UiSchema.TaggedEnum({ RequestedEditIssue: { request: Schema.String, item: Schema.String, key: Schema.String, value: Value }, RequestedOpenIssue: { item: Schema.String },})export const PeekIssues = Html.component({ name: "PeekIssues", model: Schema.Struct({ records: Schema.Array(Item), outcomes: Schema.Array(Outcome), opened: Schema.NullOr(Schema.String) }), message: Message,}).make({ init: () => ({ records: issues, outcomes: [], opened: null }), update: { RequestedEditIssue: ($, { request, item, key, value }) => $.evolve({ records: (records) => records.map((r) => (r.id === item ? applyEdit(r, key, value) : r)), outcomes: (o) => [...o.slice(-10), { _tag: "Accepted", request }], }), RequestedOpenIssue: ($, { item }) => $.evolve({ opened: $.model.records.find((r) => r.id === item)?.prefix ?? item }), }, view: (h, { records, outcomes, opened }) => h.div.attrs(sx(styles.stack)).children( h.div.attrs(sx(styles.frame)).children( List(h, { props: { label: "Backlog", records, fields: issueFields, view: { sort: [{ key: "priority", direction: "asc" }] }, columns: [ { key: "priority", at: "start", compact: true }, { key: "status", at: "start", compact: true }, { key: "customer" }, { key: "estimate" }, { key: "assignee", compact: true }, ], shortcuts: issueShortcuts, outcomes, }, onEmit: { RequestedEdit: (edit) => Message.RequestedEditIssue(edit), RequestedOpen: ({ item }) => Message.RequestedOpenIssue({ item }), RequestedAction: () => undefined, RequestedReorder: () => undefined, RequestedCreate: () => undefined, RequestedView: () => undefined, Selected: () => undefined, }, }), ), h.p .attrs({ role: "status", ...sx(styles.status) }) .children(opened === null ? "Focus a row and press Space, or hover one and press the eye." : `Requested: open ${opened}`), KeymapLegend(h, collectionKeymap(issueShortcuts), "Peek keyboard shortcuts"), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/peekUsage
import type { Item, Property } from "./ui/uicontext/components/domain/Record.ts"import { Peek } from "./ui/uicontext/components/kit/Peek.ts"const Message = UiSchema.TaggedEnum({ ClosedPeek: {}, SteppedPeek: { by: Schema.Literals([1, -1]) },})export const TaskPeek = (h: Html.H<typeof Message.Type>, tasks: ReadonlyArray<Item>, fields: ReadonlyArray<Property>, peeking: number | null) => Peek(h, { record: peeking === null ? undefined : tasks[peeking], fields, position: { index: peeking ?? 0, count: tasks.length }, onClose: Message.ClosedPeek(), onStep: (by) => Message.SteppedPeek({ by }), })Examples
On its own
Peek beside a plain list. The app holds which record is open and steps through them.
- Sign-in link expires before the email arrives
- Keyboard shortcuts for triage
- Export drops the last row of a filtered view
- Draft release notes for 2.4
- Bulk move issues between teams
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { Button } from "./ui/uicontext/components/Button.ts"import { Peek } from "./ui/uicontext/components/kit/Peek.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, radius, space } from "./ui/uicontext/components/tokens.stylex.ts"import { issueFields, issues } from "./issues.ts"// Peek on its own, beside a view that isn't a record view: a short list of the issues due this// week. The app holds which one is open; j and k (or the arrows) step through them.const due = issues.filter((issue) => issue.values["status"] !== "done" && issue.values["due"] != null).slice(0, 5)const styles = stylex.create({ list: { display: "grid", gap: space.xs, margin: 0, padding: 0, listStyle: "none", inlineSize: "min(100%, 420px)" }, item: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: space.md, paddingBlock: space.sm, paddingInline: space.md, borderWidth: 1, borderStyle: "solid", borderColor: color.line, borderRadius: radius.md, fontSize: font.sm, }, title: { minInlineSize: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" },})const Message = UiSchema.TaggedEnum({ ClickedPeek: { index: Schema.Number }, ClosedPeek: {}, SteppedPeek: { by: Schema.Literals([1, -1]) },})export const DueThisWeek = Html.component({ name: "DueThisWeek", model: Schema.Struct({ peeking: Schema.NullOr(Schema.Number) }), message: Message,}).make({ init: () => ({ peeking: null }), update: { ClickedPeek: ($, { index }) => $.evolve({ peeking: index }), ClosedPeek: ($) => $.evolve({ peeking: null }), SteppedPeek: ($, { by }) => $.evolve({ peeking: (at) => (at === null ? null : Math.min(due.length - 1, Math.max(0, at + by))) }), }, view: (h, { peeking }) => h.div.children( h.ul.attrs({ "aria-label": "Due this week", ...sx(styles.list) }).children( due.map((issue, index) => h.li.key(issue.id).attrs(sx(styles.item)).children( h.span.attrs(sx(styles.title)).children(issue.title), Button(h, { size: "sm", emphasis: "ghost" }) .attrs({ "aria-label": `Peek at ${issue.prefix ?? issue.title}` }) .on("click", Message.ClickedPeek({ index })) .children("Peek"), ), ), ), Peek(h, { record: peeking === null ? undefined : due[peeking], fields: issueFields, position: { index: peeking ?? 0, count: due.length }, onClose: Message.ClosedPeek(), onStep: (by) => Message.SteppedPeek({ by }), }), ),})In a board
Focus a card and press Space to peek; j and k move between cards without closing it.
j and k move between cards, x selects, Space peeks, Enter opens. Mod+Left or Right moves the card to the next column.
Todo
4In Progress
3In Review
3Done
2import { 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 { viewOf } from "./ui/uicontext/components/domain/Record.ts"import { Board } from "./ui/uicontext/components/kit/Board.ts"import { Item, Value } from "./ui/uicontext/components/kit/Property.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { applyEdit, issueFields, issues } from "./issues.ts"// The board opens Peek itself: focus a card and press Space. j and k step through the cards in// board order, and edits in the sheet are the board's usual RequestedEdit.const styles = stylex.create({ frame: { blockSize: 400, inlineSize: "100%" },})const Message = UiSchema.TaggedEnum({ RequestedEditIssue: { request: Schema.String, item: Schema.String, key: Schema.String, value: Value },})export const PeekBoard = Html.component({ name: "PeekBoard", model: Schema.Struct({ records: Schema.Array(Item), outcomes: Schema.Array(Outcome) }), message: Message,}).make({ init: () => ({ records: issues, outcomes: [] }), update: { RequestedEditIssue: ($, { request, item, key, value }) => $.evolve({ records: (records) => records.map((r) => (r.id === item ? applyEdit(r, key, value) : r)), outcomes: (o) => [...o.slice(-10), { _tag: "Accepted", request }], }), }, view: (h, { records, outcomes }) => h.div.attrs(sx(styles.frame)).children( Board(h, { props: { label: "Issues", records, fields: issueFields, view: viewOf({ groupBy: "status" }, "board"), card: [{ key: "assignee", at: "corner" }, { key: "priority", compact: true }], selectable: false, outcomes, }, onEmit: { RequestedEdit: (edit) => Message.RequestedEditIssue(edit), RequestedView: () => undefined, RequestedReorder: () => undefined, RequestedCreate: () => undefined, RequestedOpen: () => undefined, RequestedAction: () => undefined, Selected: () => undefined, }, }), ),})API reference
Options
| Name | Type | Description |
|---|---|---|
recordrequired | Item | The record to show; nothing shows while it's undefined |
fieldsrequired | Property[] | The fields to show, in order, as labels and values |
shown | (record: Item, key: string) => Value | Values to show in place of the record's own, such as an edit still waiting on the app |
position | { readonly index: number; readonly count: number } | "3 of 40", so the person knows where j and k lead |
locale | string | The locale numbers and dates are formatted in; the browser's by default |
onCloserequired | Message | The message sent when the person closes the preview, with Escape or the close button |
onOpen | Message | Open the record's page; absent hides the button |
onStep | (by: 1 | -1) => Message | Move to the next (1) or previous (-1) record |
Accessibility
- A modal dialog named by the record, opened with Space on a focused row or card; Escape closes it and focus goes back to the row.
- J and K or Up and Down move to the next or previous record, and the position is announced. Mod+Enter opens the record's page.