Weekly digest
product@dinachi.dev · 09:04
Your invoice is ready
billing · yesterday
Re: motion tier scope
sam · Tuesday
onDismissdismissAtactionWidthimport { useState } from "react"
import { Archive, Trash2 } from "lucide-react"
import { SwipeableRow, SwipeableRowGroup } from "@/components/ui/swipeable-row"
const inbox = [
{ id: "1", title: "Weekly digest", detail: "product@dinachi.dev · 09:04" },
{ id: "2", title: "Your invoice is ready", detail: "billing · yesterday" },
{ id: "3", title: "Re: motion tier scope", detail: "sam · Tuesday" },
]
export function Inbox() {
const [rows, setRows] = useState(inbox)
const remove = (id: string) => () => {
setRows((rows) => rows.filter((r) => r.id !== id))
}
return (
<SwipeableRowGroup>
<ul className="space-y-2">
{rows.map((row) => (
<li key={row.id}>
<SwipeableRow
actions={[
{ label: `Archive ${row.title}`, icon: <Archive className="h-4 w-4" />, onSelect: remove(row.id) },
{ label: `Delete ${row.title}`, icon: <Trash2 className="h-4 w-4" />, onSelect: remove(row.id), destructive: true },
]}
onDismiss={remove(row.id)}
>
<p className="text-sm font-medium">{row.title}</p>
<p className="text-xs text-muted-foreground">{row.detail}</p>
</SwipeableRow>
</li>
))}
</ul>
</SwipeableRowGroup>
)
}Usage
import { Archive, Trash2 } from "lucide-react"
import { SwipeableRow, SwipeableRowGroup } from "@/components/ui/swipeable-row"
export function Inbox({ onArchive, onDelete }: { onArchive: () => void; onDelete: () => void }) {
return (
<SwipeableRowGroup>
<SwipeableRow
actions={[
{ label: "Archive Weekly digest", icon: <Archive className="h-4 w-4" />, onSelect: onArchive },
{ label: "Delete Weekly digest", icon: <Trash2 className="h-4 w-4" />, onSelect: onDelete, destructive: true },
]}
onDismiss={onDelete}
>
Weekly digest
</SwipeableRow>
</SwipeableRowGroup>
)
}Examples
Weekly digest
product@dinachi.dev · 09:04
Your invoice is ready
billing · yesterday
Re: motion tier scope
sam · Tuesday
import { SwipeableRow, SwipeableRowGroup } from '@/components/ui/swipeable-row';
import { Archive, Trash2 } from 'lucide-react';
export function Example() {
return (
<SwipeableRowGroup>
{rows.map((row) => (
<SwipeableRow
key={row.id}
actions={[
{ label: `Archive ${row.title}`, icon: <Archive className="h-4 w-4" />, onSelect: () => archive(row.id) },
{ label: `Delete ${row.title}`, icon: <Trash2 className="h-4 w-4" />, onSelect: () => remove(row.id), destructive: true },
]}
onDismiss={() => remove(row.id)}
>
{row.title}
</SwipeableRow>
))}
</SwipeableRowGroup>
);
}Weekly digest
product@dinachi.dev · 09:04
Your invoice is ready
billing · yesterday
Re: motion tier scope
sam · Tuesday
<SwipeableRow
actions={[
{ label: `Archive ${row.title}`, icon: <Archive className="h-4 w-4" />, onSelect: () => archive(row.id) },
]}
>
{row.title}
</SwipeableRow>Weekly digest
product@dinachi.dev · 09:04
Your invoice is ready
billing · yesterday
Re: motion tier scope
sam · Tuesday
// The actions are real buttons with accessible names, so the whole interaction
// is reachable without the gesture. Focusing one opens its row.
<SwipeableRow
actions={[
{ label: `Archive ${row.title}`, icon: <Archive className="h-4 w-4" />, onSelect: () => archive(row.id) },
{ label: `Delete ${row.title}`, icon: <Trash2 className="h-4 w-4" />, onSelect: () => remove(row.id), destructive: true },
]}
>
{row.title}
</SwipeableRow>Notes
Release
On release the row projects where its momentum would carry it and compares that point with the thresholds. A short fast flick opens the row; a slow drag that stops short falls back. The spring takes over at the pointer's velocity.
Dismiss threshold
Past dismissAt the destructive action fills the row before release. Without onDismiss there is no threshold or destructive layer.
Refusing a change
onSelect and onDismiss both get change details. details.reason is "trigger-press", "swipe" or "imperative-action" for an agent. details.cancel() in onDismiss slides the row back.
When to use it
- Long touch lists with per-row actions: mail, tasks, notifications.
- For a short list, show the buttons instead.
- Keep actions reversible; a destructive one still needs an undo.
Behaviour
- Opening a row in a
SwipeableRowGroupcloses the open one. Outside a group, each row is independent. - The open resting point is
actionWidthtimes the number of actions. - The row can travel its full width.
- Row content is yours; the component owns only the gesture.
Motion tier
Needs motion. add --all skips it; install with add --motion or by name.
API
{ label, icon, onSelect(details), destructive?, disabled?, className? }. Required.details.cancel() slides it back.onDismiss.Agent
Inside an AgentProvider, it appears in agent.snapshot() as region.
Reads
labelThe row's aria-label, or its text with each piece kept apart.
actionsdismiss when the row has onDismiss, otherwise none.
disabledOn an action's button, true when that action is disabled.
Actions
press()On an action, listed as a button named by its label even while hidden. Runs onSelect.
dismiss()On the row, when onDismiss is set. Runs it, then slides the row off.
An agent's press runs through the action's onSelect and its dismiss through onDismiss. isAgentChange(details) is true for both; details.cancel() refuses either, tells the agent, and a refused dismiss leaves the row in place. A disabled action refuses on its own.
await agent.act({
steps: [{ ref: "Archive Weekly digest", action: "press" }],
})Accessibility
- Every action is a real button, reachable without swiping.
- Buttons are icon-only, so
labelis the name. Make it specific, as inArchive Weekly digest. - Focusing an action opens the row.
- Reduced motion disables the drag and shows the actions beside the content.