Rows a phone user swipes to act on, such as archive or mark read, with the same actions as buttons.
- 2.7 kB JS 3.5 kB CSS gzipped
- No serious axe issues
- Server-rendered, hydrates
- 44px touch targets
- Right-to-left
- Unread: Priya RamanPricing page copy is ready for review9:41
- Unread: BillingYour November invoice is $1,240.008:02
- Kenji WatanabeRe: offline mode, sync conflictsYesterday
- StatusResolved: elevated API errors in eu-west-1Mon
- Ada OkaforQ1 planning doc, comments welcomeSun
Swipe a row on a phone, or hover it for its buttons.
import { UiSchema } from "effect/ui"import { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { SwipeItem, SwipeList } from "./ui/uicontext/components/SwipeList.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ wrap: { display: "grid", gap: space.sm, inlineSize: "min(100%, 26rem)" }, note: { margin: 0, fontSize: font.sm, color: color.muted },})const Message = UiSchema.TaggedEnum({ Acted: { id: Schema.String, action: Schema.String } })const start: ReadonlyArray<SwipeItem> = [ { id: "1", title: "Priya Raman", description: "Pricing page copy is ready for review", meta: "9:41", unread: true }, { id: "2", title: "Billing", description: "Your November invoice is $1,240.00", meta: "8:02", unread: true }, { id: "3", title: "Kenji Watanabe", description: "Re: offline mode, sync conflicts", meta: "Yesterday" }, { id: "4", title: "Status", description: "Resolved: elevated API errors in eu-west-1", meta: "Mon" }, { id: "5", title: "Ada Okafor", description: "Q1 planning doc, comments welcome", meta: "Sun" },]// a phone inbox: swipe left to archive, right to mark read or unreadexport const Inbox = Html.component({ name: "Inbox", model: Schema.Struct({ items: Schema.Array(SwipeItem), last: Schema.String }), message: Message,}).make({ init: () => ({ items: start, last: "" }), update: { Acted: ($, { id, action }) => { const title = $.model.items.find((i) => i.id === id)?.title ?? "" return action === "archive" ? $.evolve({ items: (items) => items.filter((i) => i.id !== id), last: `Archived ${title}.` }) : $.evolve({ items: (items) => items.map((i) => (i.id === id ? { ...i, unread: i.unread !== true } : i)), last: `Marked ${title} ${$.model.items.find((i) => i.id === id)?.unread === true ? "read" : "unread"}.` }) }, }, view: (h, model) => h.div.attrs(sx(styles.wrap)).children( SwipeList(h, { key: "inbox", props: { label: "Inbox", items: model.items, left: { id: "archive", label: "Archive", tone: "success", removes: true }, right: { id: "read", label: "Read", tone: "info" }, empty: "Inbox zero.", }, onEmit: { Acted: ({ id, action }) => Message.Acted({ id, action }) }, }), h.p.attrs({ role: "status", ...sx(styles.note) }).children(model.last === "" ? "Swipe a row on a phone, or hover it for its buttons." : model.last), ),})When to use
Rows a phone user swipes to act on, such as archive or mark read, with the same actions as buttons. Use Record List instead when people use a mouse and keyboard more than a phone.
Usage
import { SwipeList } from "./ui/uicontext/components/SwipeList.ts"const Message = UiSchema.TaggedEnum({ Deleted: { id: Schema.String } })export const Tasks = (h: Html.H<typeof Message.Type>, tasks: ReadonlyArray<{ readonly id: string; readonly title: string }>) => SwipeList(h, { key: "tasks", props: { label: "Tasks", items: tasks, left: { id: "delete", label: "Delete", tone: "danger", removes: true } }, onEmit: { Acted: ({ id }) => Message.Deleted({ id }) }, })Examples
Resolve or snooze
An action with removes slides the row away for good; one without slides back once the app updates the row.
- Unread: p95 latency over 400 mscheckout-api · eu-west-12m
- Unread: Disk 91% fullpostgres-primary14m
- Queue backlog over 10,000email-worker1h
import { UiSchema } from "effect/ui"import { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { SwipeItem, SwipeList } from "./ui/uicontext/components/SwipeList.ts"import { sx } from "./ui/uicontext/components/Sx.ts"const styles = stylex.create({ wrap: { inlineSize: "min(100%, 26rem)" } })const Message = UiSchema.TaggedEnum({ Acted: { id: Schema.String, action: Schema.String } })// on-call alerts: swipe left to resolve, right to snooze an hourexport const OnCallAlerts = Html.component({ name: "OnCallAlerts", model: Schema.Struct({ items: Schema.Array(SwipeItem) }), message: Message,}).make({ init: () => ({ items: [ { id: "a1", title: "p95 latency over 400 ms", description: "checkout-api · eu-west-1", meta: "2m", unread: true }, { id: "a2", title: "Disk 91% full", description: "postgres-primary", meta: "14m", unread: true }, { id: "a3", title: "Queue backlog over 10,000", description: "email-worker", meta: "1h" }, ], }), update: { Acted: ($, { id, action }) => action === "resolve" ? $.evolve({ items: (items) => items.filter((i) => i.id !== id) }) : $.evolve({ items: (items) => items.map((i) => (i.id === id ? { ...i, meta: "Snoozed 1h", unread: false } : i)) }), }, view: (h, model) => h.div.attrs(sx(styles.wrap)).children( SwipeList(h, { key: "alerts", props: { label: "Alerts", items: model.items, left: { id: "resolve", label: "Resolve", tone: "success", removes: true }, right: { id: "snooze", label: "Snooze 1h", tone: "warning" }, empty: "No open alerts.", }, onEmit: { Acted: ({ id, action }) => Message.Acted({ id, action }) }, }), ),})API reference
Props
| Name | Type | Description |
|---|---|---|
labelrequired | string | — |
itemsrequired | SwipeItem[] | — |
left | SwipeAction | What a swipe to the left does |
right | SwipeAction | What a swipe to the right does |
empty | string | What the list says with no rows |
Events
| Event | Payload | Description |
|---|---|---|
Acted | { id: string; action: string } | — |
Installation
pnpm dlx shadcn@latest add checkfu/uicontext/swipe-list