Action swap
Reveal row actions with a horizontal swipe, or from the same actions in a menu.
import { ActionSwap } from '@uthereal/ui/action-swap'Action swap playground
- Q3 billing invoice readyDownload PDF or forward to finance.
- Production build #482 succeededAll 312 checks passed in 42s.
- Design review feedbackAva left 3 comments on checkout settings.
Overview
ActionSwap renders a list whose rows reveal leading and trailing actions on a horizontal swipe and expose the same actions in each row's More actions menu. Only one row stays open at a time. Dragging another row, tapping outside the open row, or pressing Escape springs it closed.
Use ActionSwap for short triage lists such as inbox threads, notifications, or review queues. Use Dropdown menu for a standalone menu on a single trigger, and use Hold to confirm when one destructive action requires press-and-hold friction.
Usage
'use client'
import { useState } from 'react'
import { ActionSwap, type ActionSwapInput } from '@uthereal/ui/action-swap'
const initialItems: ActionSwapInput['items'] = [
{
id: 'msg-1',
label: 'Q3 billing invoice ready',
description: 'Download PDF or forward to finance.',
meta: '2m ago',
leading: [
{
id: 'unread-1',
label: 'Unread',
icon: 'mail',
action: 'mark_unread',
tone: 'accent',
keepRow: true,
},
],
trailing: [
{
id: 'archive-1',
label: 'Archive',
icon: 'archive',
action: 'archive_item',
},
{
id: 'delete-1',
label: 'Delete',
icon: 'trash-2',
action: 'delete_item',
tone: 'danger',
},
],
},
]
export function InboxTriage() {
const [items, setItems] = useState(initialItems)
function handleAction(action: string, itemId: string) {
if (action === 'archive_item' || action === 'delete_item') {
setItems((current) => current.filter((item) => item.id !== itemId))
}
}
return <ActionSwap label="Inbox" items={items} onAction={handleAction} />
}Your application owns list state and executes side effects in onAction(action, itemId). Remove the item from items when a destructive or triage action runs, or set keepRow: true on actions that update the row in place.
Examples
Use <SchemaPlayground /> above to inspect fullSwipe, recipe, theme, motion, and dir. The examples below cover row-retention vs. reveal-only behavior and React row composition.
Keep row, reveal-only mode, and disabled rows
Set keepRow: true on actions that spring the row home instead of collapsing it. Set fullSwipe={false} on the list (or an individual row) to prevent long drags from committing without a tap. Set disabled: true on a row to disable both swiping and its menu.
- Release notes draftActions spring the row home without collapsing.
- Rotate webhook secretLong swipes reveal actions without auto-committing.
- Audit log retentionManaged by organization policy.
Composable rows with React callbacks
Pass <ActionSwapRow> children instead of items to render arbitrary row markup and bind per-action onSelect callbacks directly.
'use client'
import { useState } from 'react'
import { ActionSwap, ActionSwapRow } from '@uthereal/ui/action-swap'
export function CustomRows() {
const [pinned, setPinned] = useState(false)
return (
<ActionSwap label="Deployments">
<ActionSwapRow
id="deploy-482"
label="Production build #482"
leading={[
{
label: pinned ? 'Unpin' : 'Pin',
icon: 'pin',
tone: 'accent',
keepRow: true,
onSelect: () => setPinned((value) => !value),
},
]}
trailing={[
{
label: 'Archive',
icon: 'archive',
onSelect: () => console.log('archive deploy-482'),
},
]}
>
<div>
<strong>Production build #482</strong>
{pinned && <span> (Pinned)</span>}
</div>
</ActionSwapRow>
</ActionSwap>
)
}Swipe gesture mechanics
| Gesture phase | Behavior |
|---|---|
| Axis lock | Ignores movement under 8px. Locks horizontally when horizontal delta exceeds vertical delta; vertical drags stay with page scrolling. |
| Reveal & rubber-band | Opens each action to 76px. Dragging past the resting width (or toward an empty side) applies elastic resistance. |
| Full-swipe arm | Arms the outermost action past max(openWidth + 48, 0.56 * rowWidth) with 20px hysteresis, stretches its fill across the row, and triggers 8ms touch vibration. |
| Flick projection | Projects release velocity over 0.1s. An outward flick above 900px/s past the threshold commits; a flick back toward home cancels an armed full swipe. |
keepRow vs. removal | keepRow: true fires the action and springs the row home. keepRow: false slides the row off-edge and collapses height; if kept in state, the row restores after 1400ms. |
| Single open row | Opening another row, tapping the open row, pressing outside the row, or pressing Escape springs the open row closed. |
API reference
Serializable schema arguments and defaults come directly from actionSwapConfigSchema.
| Argument | Type / default | Description |
|---|---|---|
labelRequired | string— | Accessible name of the whole list, announced to assistive technology; not rendered visibly. |
itemsRequired | ActionSwapItem[]— | The rows of the list, each with its hidden leading and trailing actions. Keyed by stable unique IDs; up to 50 rows and four actions per side. |
fullSwipe | booleanDefault: true | Default for every row: a long swipe commits the outermost action of that side without a tap. A row can override it. |
moreActionsLabel | stringDefault: "More actions for {label}" | Accessible name of each row's More actions menu button. {label} is the row's label; the default "More actions for {label}" is Arc's name. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes use the same interaction behavior. |
theme | ActionSwapTheme— | Color mode, accent, and semantic tokens. The revealed action fills follow the mode and accent. |
motion | none | subtle | expressiveDefault: "subtle" | Row entrance, travel, and collapse animation preset. System reduced-motion preferences take precedence. |
motionOptions | ActionSwapMotionOptions— | Row menu item stagger (ms). Travel and collapse springs are Arc's and are not configurable. |
dir | ltr | rtl— | Reading direction. Omit it to inherit the page direction. |
React integration
| Prop | Purpose |
|---|---|
onAction(action, id) | Called with the action name and row ID from a full swipe, a tap on a revealed layer, or the More actions menu. |
renderRow(item) | Replaces the default title, meta, and description layout for serializable items. |
children | Renders <ActionSwapRow> children instead of items. When children is provided, items can be omitted. |
ActionSwapRow | Compound row accepting id, label, leading, trailing, fullSwipe, disabled, description, meta, and children. |
preset | Component defaults overridden by explicit instance props. |
tokens | --ui-* CSS variables applied after the typed theme on the root surface and forwarded to each row's menu. |
ref | Ref to the root <div> surface. |
className, style | Added to the root <div>. style takes precedence over motion and theme tokens. |
| Native attributes | Forwarded <div> attributes including id, aria-*, data-*, and DOM event handlers. |
Keyboard & accessibility
| Key | Interaction |
|---|---|
Tab | Moves focus between each row's More actions menu button. |
Enter, Space, ArrowDown | Opens the focused row's More actions menu. |
ArrowUp, ArrowDown | Navigates items inside the open menu with focus looping. |
Enter, Space (in menu) | Runs the highlighted action, animates the row, and moves focus to the next remaining row when the row leaves. |
Escape | Closes an open menu or springs any swiped-open row closed. |
Revealed swipe buttons carry aria-hidden="true" and tabIndex={-1} so assistive technology and keyboard users interact with one consistent control per row: the More actions menu button labeled by moreActionsLabel ("More actions for {label}" by default). The button opens on click rather than pointer down so a swipe starting over the button still moves the row.
When a menu action removes a row (keepRow: false), focus moves to the next staying row's More actions button, falling back to the previous staying row or to the <ul role="list" tabIndex={-1}> container when the last row leaves.
Setting dir="rtl" (or inheriting page RTL direction) mirrors leading and trailing edges, drag directions, revealed action transforms, row padding, divider inset, and menu alignment. Under forced-colors: active, borders, dividers, and accent or danger fills map to system colors and focus outlines remain visible.
Motion and theming
Drag tracking runs on Motion values without per-frame React re-renders. Settling to the open width uses spring.snappy (0.26s, bounce 0.12). Returning home, sliding off-edge, and entering or collapsing row height use spring.smooth (0.4s, zero bounce; height collapse waits 120ms and fades opacity at 340ms). Full-swipe cover stretch uses spring.morph (0.42s, bounce 0.16). motionOptions.stagger sets the item stagger inside each row's More actions menu (35ms default).
motion="none" disables all springs, height animations, and CSS transitions immediately. prefers-reduced-motion: reduce snaps horizontal travel and cover stretch immediately and replaces height collapse with a 160ms opacity fade.
theme accepts mode, accent, and tokens from the core group plus toneForeground, popupRadius, itemRadius, and shortcutSize. Compatible theme values forward automatically to each row's portalled More actions menu. Override --ui-action-swap-inset via tokens or style to adjust the row divider start inset (default 16px). UtherealProvider supplies application-wide defaults.
Composition
In agent compositions, ActionSwap is a leaf component. Register every row action's action name on the host; collectActions gathers all leading and trailing actions across items, and the handler receives the action name and row ID. Row presence and item mutations remain host state. See Building with agents.
{
"type": "ActionSwap",
"props": {
"label": "Notifications",
"items": [
{
"id": "notif-1",
"label": "Build #482 succeeded",
"description": "Production deploy completed in 42s.",
"meta": "2m ago",
"leading": [
{
"id": "read-1",
"label": "Unread",
"icon": "mail",
"action": "mark_unread",
"tone": "accent",
"keepRow": true
}
],
"trailing": [
{
"id": "archive-1",
"label": "Archive",
"icon": "archive",
"action": "archive_notification"
},
{
"id": "delete-1",
"label": "Delete",
"icon": "trash-2",
"action": "delete_notification",
"tone": "danger"
}
]
}
]
},
"children": []
}