Nexus UI

Hold to Confirm, animated React component

A destructive button you have to press and hold: the fill sweeps across, letting go early springs it back, and finishing bursts into a tick with an undo toast that counts down.

  • Free
  • Inputs & Controls
  • Spring

Play with it

Move the controls and watch it change. Copy code gives you a snippet with only the props you changed.

Press and hold. Let go early to cancel.

Props

PropTypeDefaultWhat it does
onConfirm—Called once the hold completes.
onUndo—Called when Undo is pressed before the countdown runs out.
holdMs1500How long the button must be held, in ms.
label"Hold to Delete"Resting label.
holdingLabel"Keep holding…"Label revealed by the fill.
doneLabel"Project deleted"Toast text after confirming.
color"#ff3b30"Fill and text colour.
autoplayfalseShows a short hold-and-release tease until someone interacts.

Add it to your project

  1. 1

    Prepare your project

    You need Tailwind CSS and the @/import alias. If shadcn isn't set up yet, initialise it once:

    npx shadcn@latest init

    Then add the Nexus registry to your components.json (the registries key is the part that matters):

    {
      "$schema": "https://ui.shadcn.com/schema.json",
      "style": "default",
      "rsc": true,
      "tsx": true,
      "tailwind": {
        "css": "src/app/globals.css",
        "baseColor": "neutral",
        "cssVariables": true,
        "prefix": ""
      },
      "aliases": {
        "components": "@/components",
        "utils": "@/lib/utils",
        "ui": "@/components/ui",
        "lib": "@/lib",
        "hooks": "@/hooks"
      },
      "registries": {
        "@nexus-labs": "https://www.nexus-ui.com/api/registry/{name}"
      }
    }
  2. 2

    Add the component

    Run this from your project root. It adds the component, the utilities it uses and its packages.

    npx shadcn@latest add @nexus-labs/hold-to-confirm
  3. 3

    Check what was added

    With the standard aliases, these files land in your project:

    components/
    hold-to-confirm/
    hold-to-confirm.tsx
    index.ts
  4. 4

    Copying by hand? Install the packages

    Skip this if you used the command above.

    npm install framer-motion
  5. 5

    Use it in a page

    Import it and render it. The Code tab above has the full example.

    // app/page.tsx
    import { HoldToConfirm } from "@/components/hold-to-confirm";
    
    export default function Page() {
      return (
        <main>
          <HoldToConfirm />
        </main>
      );
    }