本文へ移動
日本語

仕組み

The root keeps the size of the round trigger; the two pills live in an absolutely positioned tray beside it, so opening never moves anything. Closed, each pill is clipped to a circle at its anchored end (clip-path inset with round ends) and shifted onto the trigger by a distance measured when it opens. Opening releases both: the pills travel out with a light spring while the clip opens, the far one 40ms later, so the circle reads as splitting in two, and the labels sharpen in from a 3px blur. Cancel is the pill nearest the trigger, so a hurried second click lands on the safe choice. A darker layer drains across Cancel for the length of the timeout and pauses while the pointer or focus is inside.

向いている場面

  • Deleting or removing one item in a list or card: a file, a saved address, a team member.
  • Destructive actions that deserve a second look but not a dialog that interrupts the page.
  • Toolbars and rows where there is free space beside the button for the pills to open over.

向かない場面

  • Consequences that need explaining, or several items at once: use a confirm dialog.
  • Actions that must not slip at all: Hold to confirm asks for more.
  • Places with no room beside the button, such as a narrow cell at the edge of the screen.

使い方

import { TwoStepButton } from './TwoStepButton.jsx'

export function FileRow({ file, onRemoved }) {
  return (
    <div className="file-row">
      <span>{file.name}</span>
      <TwoStepButton
        label={`Delete ${file.name}`}
        // A Promise shows a spinner, then a check; reject it to keep the pills open and shake
        onConfirm={() => fetch(`/api/files/${file.id}`, { method: 'DELETE' }).then((r) => {
          if (!r.ok) throw new Error('failed')
        })}
        onDone={() => onRemoved(file.id)}
        timeout={4000}
      />
    </div>
  )
}

プロパティ

プロパティ型既定値説明
labelstring'Delete'Accessible name of the round trigger, for example “Delete Itinerary.pdf”.
iconReactNodetrash iconThe 18px icon in the trigger (decorative).
onConfirm() => void | Promise—Runs when the action pill is pressed. Return a Promise to show a spinner until it settles: fulfilled shows a check and the done label, then folds; rejected shakes the pill and keeps it open for another try.
onDone() => void—Called after the done face has shown and the pills fold back: the moment to remove the item.
onCancel() => void—Called when it folds without confirming: Cancel, Escape, a press outside or the timeout.
open / defaultOpen / onOpenChangeboolean / boolean / (open) => void- / false / -Controlled or uncontrolled open state, and a callback when it changes (use it to dim the row while asking).
timeoutnumber4000Milliseconds before it folds back by itself; a layer drains across Cancel meanwhile and pauses while the pointer or focus is inside. 0 turns it off.
tone'danger' | 'ink' | 'accent''danger'Colour of the action pill and the icon.
size'sm' | 'md' | 'lg''md'Trigger and pill height: 32, 40 or 44px (sm grows to 36px on touch screens).
align'end' | 'start''end'Which side the trigger sits on: the pills open over the space to its left (end) or right (start). Nothing around it moves.
labelsobject—Replaces built-in text: confirm, cancel, done, working, group. Shallow-merged over the English defaults.
disabledbooleanfalseDisables the trigger.
...restHTMLAttributes—Other attributes go to the root <span>.

アクセシビリティ

  • The trigger is a <button> with aria-expanded and aria-controls; opening moves focus to Cancel, and folding back returns it to the trigger.
  • The pills are real buttons in a group named by labels.group; Tab reaches both, Escape folds back.
  • While closed the tray is hidden and its buttons leave the tab order.
  • Working and done are announced through a polite live region; the action pill has aria-busy while working.
  • The countdown pauses while the pointer or keyboard focus is inside, so nobody loses the choice while deciding.
  • Reduced motion makes the pills appear in place with a short fade, without travel, blur, drain or shake.

モーション

Open: transform 460ms with a light overshoot, clip-path 380ms ease-out, the far pill 40ms later; labels fade and sharpen over 240–360ms after 110ms; the icon shrinks out. Close: 160ms ease-in. Done: the check draws in 360ms and the pair folds after 900ms. Failure: a 420ms decaying shake.

プロジェクトに追加

プロンプトを Codex または Claude Code に貼り付けます。エージェントが公開ソースを読み、書き込む内容を示したうえで、既存のコンポーネントの隣に追加します。

TwoStepButton.jsxtwo-step-button.csstokens.cssREADME.md

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

ボタン
「オーロラ縁ボタン」は Pro に含まれます。解除するとプレビューが表示されます。
「かじりボタン」は Pro に含まれます。解除するとプレビューが表示されます。