ui-kit0.0

Signature

Confirm morph

A button that becomes its own confirmation.

Delete files

Click the button. It turns, in place, into “Delete 3 files? Cancel / Delete”, then a spinner, then a result with Undo. Nothing opens elsewhere, so the user never loses the thing they clicked.

When to use

  • Destructive actions in a toolbar, table row or card, where a modal would pull attention away from context.
  • When the action can be undone for a short while — pass onUndo and the result carries an Undo button.
  • For irreversible, high-stakes actions use a dialog or HoldToConfirm.

Failure and retry

If onConfirm rejects, the box shows the error with Cancel and Retry. The first attempt below fails. This one uses the large size (44px).

API

ConfirmMorph

PropTypeDefaultDescription
labelReactNode—Label of the destructive button: "Delete 3 files".
questionReactNode—The inline question: "Delete 3 files?".
onConfirm() => unknown | Promise<unknown>—Runs on confirm. A rejection shows the error phase.
onUndo() => unknown | Promise<unknown>—Adds Undo to the result.
undoWindownumber6000Milliseconds the result stays before returning to idle (1600 when there is no Undo).
confirmLabel / cancelLabel / pendingLabel / resultLabel / errorLabel / undoLabel / retryLabelReactNode—All copy is overridable. Defaults: Delete, Cancel, Deleting…, Deleted, Couldn’t delete, Undo, Retry.
iconReactNode—Icon before the label.
phase / defaultPhase / onPhaseChange'idle' | 'confirm' | 'pending' | 'done' | 'error''idle'Controlled or uncontrolled phase.
size'md' | 'lg''md'Height 36 / 44px.
disabledboolean—Disables the starting button.

Keyboard

KeyAction
Enter / SpaceActivates the focused button.
EscCancels the confirmation (or dismisses an error) and returns focus to the starting button.
TabMoves between Cancel and Delete.

Accessibility

  • Focus follows the interaction: Cancel (the safe choice) when asking, a neutral spot while pending, Undo or Retry on a result, the starting button after Esc or Cancel.
  • Focus only moves when it was already inside the component, so a background update never steals it.
  • A polite live region announces the question, the pending label and the result.
  • The outgoing layer of a morph is inert, so nothing duplicated can be focused.

Motion

  • One box: its width springs to each phase on --ui-spring-morph (550ms) via the Web Animations API; colours move over 220ms.
  • Content: the new layer rises 4px with a 2px blur that clears (220ms); the old layer lifts and blurs out (160ms) on top of it.
  • The button is destructive red → raised surface (confirm) → muted (pending) → raised with a drawn success check (done).
  • Reduced motion: width and content swap instantly (1ms fade), the colours still change.