# Integrate `Dismiss` from Motion Garden

You are helping me add the **Dismiss** 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:** Dismiss
- **Category:** Micro-interactions
- **Summary:** Throw the top card away and the stack closes up behind it. Distance commits, but so does speed — a fast flick from barely anywhere counts, and anything short of both rubber-bands home carrying the velocity you let go at.
- **Reference:** https://motion-garden.netlify.app/components/dismiss
- **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-panel: var(--sg-panel);
  --color-raised: var(--sg-raised);
  --color-hairline: var(--sg-hairline);
  --color-ink: var(--sg-ink);
  --color-ink-mute: var(--sg-ink-mute);
  --color-accent: var(--sg-accent);
}

:root {
  --sg-panel: #ffffff;
  --sg-raised: #eceaef;
  --sg-hairline: #dde2e7;
  --sg-ink: #16191d;
  --sg-ink-mute: #878e97;
  --sg-accent: #7e22ce;
}

.dark {
  --sg-panel: #101215;
  --sg-raised: #191d21;
  --sg-hairline: #2a2f36;
  --sg-ink: #e2e6e9;
  --sg-ink-mute: #6c737c;
  --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/dismiss/dismiss.tsx`

```tsx
"use client";

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

export interface DismissItem {
  id: string;
  title: string;
  meta?: string;
}

export interface DismissProps {
  items?: DismissItem[];
  onDismiss?: (id: string) => void;
  axis?: "x" | "y" | "both";
  threshold?: number;
  velocityThreshold?: number;
  rubberBand?: number;
  stackDepth?: number;
  stackOffset?: number;
  stackScale?: number;
  rotateOnDrag?: number;
  stiffness?: number;
  damping?: number;
  reducedMotion?: boolean;
  className?: string;
}

const TRAVEL = 220;

export default function Dismiss({
  items = [],
  onDismiss,
  axis = "x",
  threshold = 32,
  velocityThreshold = 520,
  rubberBand = 0.35,
  stackDepth = 3,
  stackOffset = 14,
  stackScale = 0.05,
  rotateOnDrag = 8,
  stiffness = 420,
  damping = 32,
  reducedMotion = false,
  className,
}: DismissProps) {
  const visible = items.slice(0, Math.max(1, stackDepth));

  return (
    <div
      className={cn("relative w-full", className)}
      style={{ paddingBottom: Math.max(0, visible.length - 1) * stackOffset }}
    >
      <div aria-hidden className="invisible">
        <CardFace item={{ id: "_", title: "—", meta: "—" }} />
      </div>

      {visible
        .map((item, depth) => ({ item, depth }))
        .reverse()
        .map(({ item, depth }) => (
          <Card
            key={item.id}
            item={item}
            depth={depth}
            total={visible.length}
            axis={axis}
            threshold={threshold}
            velocityThreshold={velocityThreshold}
            rubberBand={rubberBand}
            stackOffset={stackOffset}
            stackScale={stackScale}
            rotateOnDrag={rotateOnDrag}
            stiffness={stiffness}
            damping={damping}
            reducedMotion={reducedMotion}
            onDismiss={onDismiss}
          />
        ))}
    </div>
  );
}

function Card({
  item,
  depth,
  total,
  axis,
  threshold,
  velocityThreshold,
  rubberBand,
  stackOffset,
  stackScale,
  rotateOnDrag,
  stiffness,
  damping,
  reducedMotion,
  onDismiss,
}: {
  item: DismissItem;
  depth: number;
  total: number;
  axis: "x" | "y" | "both";
  threshold: number;
  velocityThreshold: number;
  rubberBand: number;
  stackOffset: number;
  stackScale: number;
  rotateOnDrag: number;
  stiffness: number;
  damping: number;
  reducedMotion: boolean;
  onDismiss?: (id: string) => void;
}) {
  const boxRef = useRef<HTMLDivElement>(null);
  const [leaving, setLeaving] = useState(false);
  const x = useMotionValue(0);
  const y = useMotionValue(0);

  const lean = useTransform(x, [-TRAVEL, TRAVEL], [-rotateOnDrag, rotateOnDrag], {
    clamp: true,
  });

  const top = depth === 0;
  const live = top && !leaving;

  const send = (dirX: number, dirY: number) => {
    if (leaving) return;
    setLeaving(true);
    const w = boxRef.current?.offsetWidth ?? 320;
    const h = boxRef.current?.offsetHeight ?? 120;
    const out = reducedMotion
      ? { duration: 0.1 }
      : { type: "spring" as const, stiffness: 260, damping: 30 };

    const goX = dirX !== 0;
    const flightX = animate(x, goX ? Math.sign(dirX) * w * 1.6 : x.get(), out);
    const flightY = animate(y, dirY !== 0 ? Math.sign(dirY) * h * 2.4 : y.get(), out);

    void (goX ? flightX : flightY).then(() => onDismiss?.(item.id));
  };

  const release = (info: PanInfo) => {
    const w = boxRef.current?.offsetWidth ?? 320;
    const h = boxRef.current?.offsetHeight ?? 120;
    const canX = axis !== "y";
    const canY = axis !== "x";

    const pastX =
      canX &&
      (Math.abs(info.offset.x) > (threshold / 100) * w ||
        Math.abs(info.velocity.x) > velocityThreshold);
    const pastY =
      canY &&
      (Math.abs(info.offset.y) > (threshold / 100) * h ||
        Math.abs(info.velocity.y) > velocityThreshold);

    if (pastX || pastY) {
      send(
        pastX ? info.offset.x || info.velocity.x : 0,
        pastY ? info.offset.y || info.velocity.y : 0,
      );
      return;
    }

    const home = reducedMotion
      ? { duration: 0.16, ease: [0.22, 1, 0.36, 1] as const }
      : { type: "spring" as const, stiffness, damping };
    animate(x, 0, { ...home, ...(reducedMotion ? {} : { velocity: info.velocity.x }) });
    animate(y, 0, { ...home, ...(reducedMotion ? {} : { velocity: info.velocity.y }) });
  };

  return (
    <motion.div
      className="absolute inset-x-0 top-0"
      style={{ zIndex: total - depth }}
      animate={{
        translateY: depth * stackOffset,
        scale: 1 - depth * stackScale,
        opacity: 1 - depth * 0.18,
      }}
      transition={reducedMotion ? { duration: 0 } : { type: "spring", stiffness, damping }}
    >
      <motion.div
        ref={boxRef}
        className="touch-none select-none"
        style={{ x, y, rotate: reducedMotion || !top ? 0 : lean, cursor: live ? "grab" : "default" }}
        drag={live ? (axis === "both" ? true : axis) : false}
        dragElastic={rubberBand}
        dragMomentum={false}
        onDragEnd={(_, info) => release(info)}
        whileDrag={{ cursor: "grabbing" }}
      >
        <CardFace
          item={item}
          showContent={top}
          interactive={live}
          onDismiss={() => send(axis === "y" ? 0 : 1, axis === "y" ? 1 : 0)}
        />
      </motion.div>
    </motion.div>
  );
}

function CardFace({
  item,
  showContent = true,
  interactive,
  onDismiss,
}: {
  item: DismissItem;
  showContent?: boolean;
  interactive?: boolean;
  onDismiss?: () => void;
}) {
  return (
    <div className="flex items-center gap-4 rounded-lg border border-hairline bg-panel px-5 py-4">
      <span
        className="min-w-0 flex-1 transition-opacity duration-200"
        style={{ opacity: showContent ? 1 : 0 }}
      >
        <span className="block truncate font-display text-[12px] tracking-[0.12em] text-ink uppercase">
          {item.title}
        </span>
        {item.meta ? (
          <span className="mt-1 block truncate font-sans text-[12px] text-ink-mute">
            {item.meta}
          </span>
        ) : null}
      </span>
      {interactive ? (
        <button
          type="button"
          aria-label={`Dismiss ${item.title}`}
          onClick={onDismiss}
          onPointerDown={(e) => e.stopPropagation()}
          className="grid size-7 shrink-0 place-items-center rounded-full border border-hairline text-ink-mute transition-colors outline-none hover:bg-raised hover:text-ink focus-visible:ring-2 focus-visible:ring-accent"
        >
          <svg viewBox="0 0 24 24" className="size-3" aria-hidden>
            <path
              d="M5 5 19 19M19 5 5 19"
              fill="none"
              stroke="currentColor"
              strokeWidth="2.5"
              strokeLinecap="round"
            />
          </svg>
        </button>
      ) : null}
    </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 |
| --- | --- | --- | --- |
| `axis` | `"x" | "y" | "both"` | `"x"` | Which way a card can leave. Sideways is the toast convention; downward reads as filing something away rather than discarding it. |
| `threshold` | `number` | `32` | How far across its own width a card must travel to commit. Distance is only half the test — a flick past the speed threshold commits from anywhere. Range 10–90 %. |
| `velocityThreshold` | `number` | `520` | Release speed that commits regardless of how far the card actually moved. Without this a quick flick just springs back and the gesture feels deaf. Range 100–2000 px/s. |
| `rubberBand` | `number` | `0.35` | Give past the drag bounds. 0 is a hard wall; 1 follows the finger exactly and loses the sense that the card is resisting you. Range 0–1. |
| `stackDepth` | `number` | `3` | How many cards are visible at once. Past four the ones at the back stop being legible and start being texture. Range 1–6. |
| `stackOffset` | `number` | `14` | Vertical step between one card and the next down the stack. Range 0–40 px. |
| `stackScale` | `number` | `0.05` | Scale lost per card down the stack. This is what sells depth — offset alone reads as a list. Range 0–0.2. |
| `rotateOnDrag` | `number` | `8` | Degrees the card leans at the far edge of the throw. Derived from displacement, not animated separately, so an interrupted throw can never desync it. Range 0–30 °. |
| `stiffness` | `number` | `420` | How hard the stack springs into its new slot after a card leaves. Range 80–900. |
| `damping` | `number` | `32` | How fast that spring settles. Low values let the stack overshoot and bounce, which reads as lightweight. Range 8–80. |

## Usage

```tsx
import Dismiss from "@/components/registry/dismiss/dismiss";

<Dismiss
  axis="x"
  threshold={32}
  velocityThreshold={520}
  rubberBand={0.35}
  stackDepth={3}
  stackOffset={14}
  stackScale={0.05}
  rotateOnDrag={8}
  stiffness={420}
  damping={32}
/>
```

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`.
- The `touch-action: none` on the hit target is load-bearing — without it a finger drag scrolls the page instead of driving the effect. Do not strip it as a stray utility class.
- `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.
