# Integrate `Hold` from Motion Garden

You are helping me add the **Hold** component to an existing project.
Everything you need is below — full source, dependencies, props and the
behavioural contract. Read it all before writing anything.

- **Component:** Hold
- **Category:** Micro-interactions
- **Summary:** A confirm that has to be earned. The ring fills while you hold, snaps shut when it commits, and empties on a different curve entirely if you let go early.
- **Reference:** https://motion-garden.netlify.app/components/hold
- **Full catalog (for you, the agent):** https://motion-garden.netlify.app/llms.txt

## Stack this source assumes

- React 19 with the Next.js App Router (never the `pages/` directory)
- TypeScript, strict
- Tailwind CSS v4, CSS-first config (utilities are inline; no `tailwind.config` needed)

If my project differs, adapt the integration — but do not rewrite the animation math to suit a different stack. Ask me first.

## Dependencies

```bash
bun add motion clsx tailwind-merge
```

## Design tokens this source uses

Some classes in the source are Motion Garden theme tokens, not stock Tailwind (`text-ink`, `bg-panel`, `font-display` and the like). Without them, parts of the component render unstyled. Add this to my global CSS, after the Tailwind import:

```css
@theme {
  --font-display: "Space Mono", ui-monospace, "SFMono-Regular", monospace;
}

@theme inline {
  --color-surface: var(--sg-surface);
  --color-raised: var(--sg-raised);
  --color-hairline: var(--sg-hairline);
  --color-ink: var(--sg-ink);
  --color-accent: var(--sg-accent);
}

:root {
  --sg-surface: #f9f9fb;
  --sg-raised: #eceaef;
  --sg-hairline: #dde2e7;
  --sg-ink: #16191d;
  --sg-accent: #7e22ce;
}

.dark {
  --sg-surface: #0a0b0c;
  --sg-raised: #191d21;
  --sg-hairline: #2a2f36;
  --sg-ink: #e2e6e9;
  --sg-accent: #a855f7;
}
```

The values are Motion Garden's own light and dark themes. If my project already has tokens for these roles, point the `--sg-*` variables at mine instead and tell me which you mapped. `.dark` assumes class-based dark mode — adapt the selector to how my project switches themes.

`font-display` expects Space Mono, and this CSS only names it. Load the font (with `next/font/google`, for example) or put my own display face first in the stack; until then it falls back to the system monospace.

## Files to create

2 files — all of them are required. Paths are as shipped; the component may live anywhere in my project, but keep every peer file at the exact path shown so the import aliases resolve.

### 1. `components/registry/hold/hold.tsx`

```tsx
"use client";

import { useCallback, useEffect, useRef, useState, type ReactNode } from "react";
import { animate, motion, useMotionValue, useTransform } from "motion/react";
import { cn } from "@/lib/utils";

export interface HoldProps {
  label?: ReactNode;
  confirmLabel?: ReactNode;
  duration?: number;
  indicator?: "ring" | "bar" | "fill";
  threshold?: number;
  rewindRate?: number;
  strokeWidth?: number;
  holdScale?: number;
  commitScale?: number;
  successHold?: number;
  accentColor?: string;
  trackColor?: string;
  onCommit?: () => void;
  reducedMotion?: boolean;
  className?: string;
}

export default function Hold({
  label = "Hold to confirm",
  confirmLabel = "Confirmed",
  duration = 1200,
  indicator = "ring",
  threshold = 0.92,
  rewindRate = 2.4,
  strokeWidth = 3,
  holdScale = 0.96,
  commitScale = 1.06,
  successHold = 1.4,
  accentColor = "#a855f7",
  trackColor = "#2a2136",
  onCommit,
  reducedMotion = false,
  className,
}: HoldProps) {
  const [phase, setPhase] = useState<"idle" | "holding" | "committed">("idle");

  const progress = useMotionValue(0);
  const scale = useMotionValue(1);

  const heldRef = useRef(false);
  const commitTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
  const resetTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
  const fillRef = useRef<{ stop: () => void } | null>(null);

  const live = useRef({ duration, threshold, rewindRate, commitScale, successHold, reducedMotion, onCommit });
  live.current = { duration, threshold, rewindRate, commitScale, successHold, reducedMotion, onCommit };

  const clearTimers = useCallback(() => {
    if (commitTimer.current !== null) {
      clearTimeout(commitTimer.current);
      commitTimer.current = null;
    }
  }, []);

  const commit = useCallback(() => {
    clearTimers();
    fillRef.current?.stop();
    setPhase("committed");
    fillRef.current = animate(progress, 1, { duration: 0.12, ease: [0.16, 1, 0.3, 1] });
    if (!live.current.reducedMotion) {
      animate(scale, live.current.commitScale, { type: "spring", stiffness: 700, damping: 14 }).then(
        () => animate(scale, 1, { type: "spring", stiffness: 320, damping: 24 }),
      );
    }
    live.current.onCommit?.();
    resetTimer.current = setTimeout(() => {
      setPhase("idle");
      progress.set(0);
      scale.set(1);
    }, live.current.successHold * 1000);
  }, [clearTimers, progress, scale]);

  const start = useCallback(() => {
    if (heldRef.current || phase === "committed") return;
    heldRef.current = true;
    setPhase("holding");
    clearTimers();
    fillRef.current?.stop();

    const from = progress.get();
    const { duration: ms, threshold: at } = live.current;
    fillRef.current = animate(progress, 1, { duration: ((1 - from) * ms) / 1000, ease: "linear" });
    commitTimer.current = setTimeout(commit, Math.max(0, (at - from) * ms));

    animate(scale, holdScale, { type: "spring", stiffness: 520, damping: 30 });
  }, [clearTimers, commit, holdScale, phase, progress, scale]);

  const release = useCallback(() => {
    heldRef.current = false;
    animate(scale, 1, { type: "spring", stiffness: 420, damping: 26 });
    if (phase !== "holding") return;
    clearTimers();
    fillRef.current?.stop();
    setPhase("idle");

    const from = progress.get();
    const { duration: ms, rewindRate: rate } = live.current;
    fillRef.current = animate(progress, 0, {
      duration: (from * ms) / rate / 1000,
      ease: [0.22, 1, 0.36, 1],
    });
  }, [clearTimers, phase, progress, scale]);

  useEffect(
    () => () => {
      if (commitTimer.current !== null) clearTimeout(commitTimer.current);
      if (resetTimer.current !== null) clearTimeout(resetTimer.current);
      fillRef.current?.stop();
    },
    [],
  );

  const dashOffset = useTransform(progress, (p) => 1 - p);
  const glow = useTransform(progress, (p) => p * 0.55);

  const committed = phase === "committed";
  const ringRadius = 12 - strokeWidth / 2 - 1;

  return (
    <div className={cn("inline-flex flex-col items-stretch gap-2", className)}>
      <motion.button
        type="button"
        style={{ scale }}
        onPointerDown={(e) => {
          e.currentTarget.setPointerCapture(e.pointerId);
          start();
        }}
        onPointerUp={release}
        onPointerCancel={release}
        onLostPointerCapture={release}
        onBlur={release}
        onKeyDown={(e) => {
          if (e.key !== " " && e.key !== "Enter") return;
          e.preventDefault();
          if (e.repeat) return;
          start();
        }}
        onKeyUp={(e) => {
          if (e.key !== " " && e.key !== "Enter") return;
          release();
        }}
        onContextMenu={(e) => e.preventDefault()}
        className={cn(
          "relative isolate flex items-center gap-3 overflow-hidden rounded-full",
          "border border-hairline bg-raised px-5 py-2.5 select-none",
          "font-display text-[11px] tracking-[0.22em] text-ink uppercase",
          "transition-colors duration-200 outline-none",
          "focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface",
        )}
      >
        {indicator === "fill" ? (
          <motion.span
            aria-hidden
            className="absolute inset-0 -z-10 origin-left"
            style={{ scaleX: progress, backgroundColor: accentColor, opacity: 0.22 }}
          />
        ) : null}

        {reducedMotion ? null : (
          <motion.span
            aria-hidden
            className="pointer-events-none absolute inset-0 -z-10"
            style={{ opacity: glow, boxShadow: `inset 0 0 24px ${accentColor}` }}
          />
        )}

        <span className="relative grid size-6 shrink-0 place-items-center">
          <svg viewBox="0 0 24 24" className="size-6 -rotate-90" aria-hidden>
            <circle
              cx="12"
              cy="12"
              r={ringRadius}
              fill="none"
              stroke={indicator === "ring" ? trackColor : "transparent"}
              strokeOpacity={0.45}
              strokeWidth={strokeWidth}
            />
            {indicator === "ring" ? (
              <motion.circle
                cx="12"
                cy="12"
                r={ringRadius}
                fill="none"
                stroke={accentColor}
                strokeWidth={strokeWidth}
                strokeLinecap="round"
                pathLength={1}
                strokeDasharray="1 1"
                style={{ strokeDashoffset: dashOffset }}
              />
            ) : null}
          </svg>
          <svg
            viewBox="0 0 24 24"
            className={cn(
              "absolute size-3.5 transition-opacity duration-200",
              committed ? "opacity-100" : "opacity-0",
            )}
            aria-hidden
          >
            <path
              d="M4 12.5 9.5 18 20 6"
              fill="none"
              stroke={accentColor}
              strokeWidth="3"
              strokeLinecap="round"
              strokeLinejoin="round"
            />
          </svg>
        </span>

        <span className="relative">{committed ? confirmLabel : label}</span>
      </motion.button>

      <span
        aria-hidden
        className="relative w-full overflow-hidden rounded-full"
        style={{ height: indicator === "bar" ? strokeWidth : 0 }}
      >
        <span
          className="absolute inset-0"
          style={{
            backgroundColor: indicator === "bar" ? trackColor : "transparent",
            opacity: 0.45,
          }}
        />
        <motion.span
          className="absolute inset-0 origin-left rounded-full"
          style={{ scaleX: progress, backgroundColor: accentColor }}
        />
      </span>

      <span className="sr-only" role="status" aria-live="polite">
        {committed ? "Confirmed" : ""}
      </span>
    </div>
  );
}
```

### 2. `lib/utils.ts` — peer util, required

```tsx
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";

export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs));
}
```


## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `duration` | `number` | `1200` | How long a full press has to be held before it commits. Under about 600ms people let go by reflex; past 2s they assume it is broken. Range 300–4000 ms. |
| `indicator` | `"ring" | "bar" | "fill"` | `"ring"` | Where the progress lives — a ring traced around the glyph, a bar under the control, or the control's own face flooding left to right. |
| `threshold` | `number` | `0.92` | Fraction of the track that counts as committed. Below 1 the last sliver closes itself, so the press lands a beat before the eye expects it — that early snap is what makes it feel decisive rather than punctual. Range 0.6–1. |
| `rewindRate` | `number` | `2.4` | How much faster a cancelled hold empties than it filled. At 1 it rewinds the same tape; above 2 the release reads as a spring letting go, which is the entire point of an asymmetric curve. Range 0.5–6 ×. |
| `strokeWidth` | `number` | `3` | Weight of the progress track. Thin reads as instrumentation, thick reads as a toy. Range 1–12 px. Ignored while `indicator` is `fill`. |
| `holdScale` | `number` | `0.96` | How far the control sinks under the finger. The press feedback is doing more work here than the ring is — take it to 1 and the hold stops feeling physical. Range 0.85–1 ×. |
| `commitScale` | `number` | `1.06` | Overshoot the control pops to at the instant of commit, before settling. This is the receipt. Range 1–1.3 ×. |
| `successHold` | `number` | `1.4` | How long the confirmed state stays on screen before the control re-arms itself. Range 0.4–4 s. |
| `accentColor` | `string (hex)` | `"#a855f7"` | Amethyst of the filling track and the confirmed state. |
| `trackColor` | `string (hex)` | `"#2a2136"` | The unfilled remainder. Keep it close to the surface underneath — a high-contrast track turns the ring into a bullseye. |

## Usage

```tsx
import Hold from "@/components/registry/hold/hold";

<Hold
  duration={1200}
  indicator="ring"
  threshold={0.92}
  rewindRate={2.4}
  strokeWidth={3}
  holdScale={0.96}
  commitScale={1.06}
  successHold={1.4}
  accentColor="#a855f7"
  trackColor="#2a2136"
/>
```

The import path matches the file path above; change it if you move the component. Every value shown is the documented default — pass only what you actually want to change. The snippet lists the tunable props only: if the component's props type in the source requires others (content, handlers, data), pass those too.

## Integration rules

- Keep the `"use client"` directive. This is a client component and will not render as a Server Component.
- It fills its parent. Give the wrapper an explicit height (or a definite grid area) — against a height-auto parent it collapses to nothing.
- It takes a `reducedMotion` prop and quiesces when true. Wire it to a `prefers-reduced-motion` listener rather than hardcoding `false`.
- `lib/utils.ts` is required, not optional. It exports the `cn` helper the component imports from `@/lib/utils` — keep it at that path, or rewrite every `cn` import to wherever you already keep yours. If your project is shadcn-based you almost certainly have this file already; keep yours and drop mine.

## Your task

1. Tell me where in my project this should live and why.
2. Create the files above verbatim.
3. Add the design tokens to my global CSS, or map them to tokens I already have.
4. Wire the component into the place I point you at, with sensible props for that context.
5. Flag anything in my setup that conflicts with the stack assumptions above.

Do not restyle the component or alter the animation math unless I ask.
