本文へ移動
日本語
「スワイプアクション」は Pro に含まれます。解除するとプレビューが表示されます。

仕組み

The content layer sits over a row of real buttons and follows the finger with translateX (written to a CSS variable and updated straight in the DOM each frame). Each button draws a coloured pill inset from the row edges that grows from 0.6 to full size as it is uncovered; the pill is a long rounded shape cut with clip-path, so on a full swipe the main action stretches across the row by animating the clip, without layout changes. An 8px check decides the direction: only clearly horizontal moves take over, the rest scroll the page. Pointer movement is converted for scaled containers. Past the buttons there is rubber-band resistance. On release, the last 100ms of velocity decides: a quick flick opens or closes, otherwise it snaps by halfway. Style hooks: --ds-swipe-radius (row corners, for tile lists), --ds-swipe-bg, --ds-swipe-pill-radius and --ds-swipe-pill-inset.

向いている場面

  • Quick actions on one row in mobile message, notification or order lists: read, pin, delete.
  • Frequent actions where a “more” menu costs an extra tap.
  • Inbox-style lists where a full swipe deletes or archives.

向かない場面

  • Mostly desktop pages: mouse users rarely think to drag; put buttons at the row end or show them on hover.
  • The only way to do something important: gestures are invisible, so offer another entry point too.
  • Rows with their own horizontal swiping, such as carousels and sliders: the gestures conflict.

使い方

import { SwipeActions, SwipeGroup } from './SwipeActions.jsx'

export function MessageList({ messages, onRead, onDelete }) {
  return (
    <SwipeGroup role="list">
      {messages.map((m) => (
        <SwipeActions
          key={m.id}
          role="listitem"
          fullSwipe
          actions={[
            { key: 'read', label: 'Read', tone: 'accent', onClick: () => onRead(m.id) },
            { key: 'delete', label: 'Delete', tone: 'danger', collapse: true, onClick: () => onDelete(m.id) },
          ]}
        >
          <MessageRow message={m} />
        </SwipeActions>
      ))}
    </SwipeGroup>
  )
}

プロパティ

プロパティ型既定値説明
actions{ key, label, icon?, tone?, onClick, collapse? }[]—The revealed actions, left to right; the last is the main action. tone is 'neutral', 'accent', 'warning' or 'danger'. Labels are yours, so the component has no built-in text.
actions[].collapsebooleanfalseCollapses the row height first, then calls back. Good for delete.
fullSwipebooleanfalseSwiping past fullSwipeThreshold of the row width runs the main action directly.
fullSwipeThresholdnumber0.6Where a full swipe triggers, as a fraction of the row width.
actionWidthnumber76Width of each button in px, at least 44.
disabledbooleanfalseDisables swiping. The buttons stay reachable by keyboard.
childrenReactNode—The row content.
...restHTMLAttributes—Other attributes go to the root element, such as role="listitem" and className.
SwipeGroupcomponent—Wraps a set of SwipeActions so only one row is open at a time. Other props go to its div.

アクセシビリティ

  • The actions are real <button> elements, always in the tab order; tabbing to one opens the row and focus leaving the row closes it. After a keyboard action that does not delete the row, it stays open with focus on a visible button.
  • Buttons have text labels (icons are aria-hidden), so every action works without gestures.
  • A focused button shows a ring around its pill, inside the row, since the clipped row would cut a ring on the button's edge.
  • touch-action: pan-y keeps vertical list scrolling working.
  • Reduced motion makes snapping and collapsing instant; dragging still follows the finger.

モーション

Snap after release: 320ms ease-out, with the pills growing from 0.6 to full size in step. Main action stretch and retract: 200ms ease-out on clip-path and translate. After a full swipe the content slides out in 200ms; the row collapses in 240ms ease-in-out. Rubber-band damping applies when overdragging.

プロジェクトに追加

Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。

SwipeActions.jsxswipe-actions.csstokens.cssREADME.md

2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

リスト
「アーチ型カルーセル」は Pro に含まれます。解除するとプレビューが表示されます。
「円柱カルーセル」は Pro に含まれます。解除するとプレビューが表示されます。