# Integrate `StaggerMenu` from Motion Garden

You are helping me add the **StaggerMenu** 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:** StaggerMenu
- **Category:** Micro-interactions
- **Summary:** A menu overlay that blooms open as a clip-path circle spring while items stagger in with blur and rotation, then collapses back to its pill.
- **Reference:** https://motion-garden.netlify.app/components/stagger-menu
- **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
```

## 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/stagger-menu/stagger-menu.tsx`

```tsx
"use client";

import { useEffect, useRef, useState } from "react";
import { motion, type Variants } from "motion/react";
import { cn } from "@/lib/utils";

export interface StaggerMenuProps {
	items: string[];
	defaultOpen?: boolean;
	open?: boolean;
	onOpenChange?: (open: boolean) => void;
	onItemClick?: (index: number) => void;
	openStiffness?: number;
	stagger?: number;
	blur?: number;
	overlayColor?: string;
	overlayOpacity?: number;
	reducedMotion?: boolean;
	className?: string;
}

const ANCHOR_Y = 28;

function hexToRgba(hex: string, alpha: number): string {
	let h = hex.replace("#", "");
	if (h.length === 3) {
		h = h.split("").map((c) => c + c).join("");
	}
	const n = parseInt(h, 16);
	return `rgba(${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255}, ${alpha})`;
}

export default function StaggerMenu({
	items,
	defaultOpen = false,
	open,
	onOpenChange,
	onItemClick,
	openStiffness = 20,
	stagger = 0.09,
	blur = 8,
	overlayColor = "#0a0a0c",
	overlayOpacity = 0.92,
	reducedMotion = false,
	className,
}: StaggerMenuProps) {
	const rootRef = useRef<HTMLDivElement>(null);
	const [internalOpen, setInternalOpen] = useState(defaultOpen);
	const isOpen = open ?? internalOpen;

	const setOpen = (next: boolean) => {
		setInternalOpen(next);
		onOpenChange?.(next);
	};

	const [size, setSize] = useState({ w: 0, h: 0 });
	useEffect(() => {
		const el = rootRef.current;
		if (!el) return;
		const ro = new ResizeObserver(() => {
			setSize({ w: el.clientWidth, h: el.clientHeight });
		});
		ro.observe(el);
		return () => ro.disconnect();
	}, []);
	const radius = Math.ceil(Math.hypot(size.w / 2, size.h / 2)) + 20;

	const overlay: Variants = reducedMotion
		? {
				open: { opacity: 1, transition: { duration: 0 } },
				closed: { opacity: 0, transition: { duration: 0 } },
			}
		: {
				open: {
					clipPath: `circle(${radius}px at 50% 50%)`,
					transition: { type: "spring", stiffness: openStiffness, restDelta: 2 },
				},
				closed: {
					clipPath: `circle(4px at 50% ${ANCHOR_Y}px)`,
					transition: { delay: 0.3, type: "spring", stiffness: 400, damping: 20 },
				},
			};

	const nav: Variants = reducedMotion
		? { open: {}, closed: {} }
		: {
				open: { transition: { staggerChildren: stagger, delayChildren: 0.2 } },
				closed: { transition: { staggerChildren: 0.05, staggerDirection: -1 } },
			};

	const item: Variants = reducedMotion
		? {
				open: { opacity: 1, transition: { duration: 0 } },
				closed: { opacity: 0, transition: { duration: 0 } },
			}
		: {
				open: {
					y: 0,
					rotate: 0,
					opacity: 1,
					filter: "blur(0px)",
					transition: {
						y: { stiffness: 1000, velocity: -100 },
						rotate: { stiffness: 1000, velocity: -100 },
					},
				},
				closed: {
					y: 50,
					rotate: 10,
					opacity: 0,
					filter: `blur(${blur}px)`,
					transition: {
						y: { stiffness: 1000 },
						rotate: { stiffness: 1000 },
					},
				},
			};

	return (
		<motion.div
			ref={rootRef}
			initial={false}
			animate={isOpen ? "open" : "closed"}
			className={cn(
				"pointer-events-none absolute inset-0 select-none",
				className,
			)}
		>
			<motion.div
				variants={overlay}
				className={cn(
					"absolute inset-0 backdrop-blur-sm",
					isOpen ? "pointer-events-auto" : "pointer-events-none",
				)}
				style={{ background: hexToRgba(overlayColor, overlayOpacity) }}
			/>
			<motion.ul
				variants={nav}
				className={cn(
					"absolute left-1/2 top-1/2 flex -translate-x-1/2 -translate-y-1/2 flex-col gap-5",
					isOpen ? "pointer-events-auto" : "pointer-events-none",
				)}
			>
				{items.map((label, i) => (
					<li key={label} className="overflow-y-clip text-center">
						<motion.div
							variants={item}
							whileHover={reducedMotion ? undefined : { scale: 1.1 }}
							whileTap={reducedMotion ? undefined : { scale: 0.95 }}
						>
							<button
								type="button"
								onClick={() => {
									onItemClick?.(i);
									setOpen(false);
								}}
								className="text-2xl font-light uppercase tracking-wide text-white/90 md:text-4xl"
							>
								{label}
							</button>
						</motion.div>
					</li>
				))}
			</motion.ul>
			<button
				type="button"
				onClick={() => setOpen(!isOpen)}
				className="pointer-events-auto absolute left-1/2 top-3 flex -translate-x-1/2 items-center gap-2 rounded-full border border-white/15 bg-white/5 px-4 py-1.5 backdrop-blur-sm transition-colors hover:border-white/35"
			>
				<span className="flex gap-1">
					{[0, 1, 2, 3, 4].map((i) => (
						<span
							key={i}
							className="h-1.5 w-1.5 rounded-full bg-white/70"
						/>
					))}
				</span>
				<span className="text-[10px] uppercase tracking-[0.28em] text-white/80">
					{isOpen ? "Close" : "Menu"}
				</span>
			</button>
		</motion.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 |
| --- | --- | --- | --- |
| `openStiffness` | `number` | `20` | Bloom spring stiffness — low values settle slowly. Range 5–120. |
| `stagger` | `number` | `0.09` | Delay between each item's entrance. Range 0–0.2 s. |
| `blur` | `number` | `8` | Blur the items travel from and to. Range 0–20 px. |
| `overlayColor` | `string (hex)` | `"#0a0a0c"` | Overlay background color. |
| `overlayOpacity` | `number` | `0.92` | Overlay background opacity. Range 0.5–1. |

## Usage

```tsx
import StaggerMenu from "@/components/registry/stagger-menu/stagger-menu";

<StaggerMenu
  openStiffness={20}
  stagger={0.09}
  blur={8}
  overlayColor="#0a0a0c"
  overlayOpacity={0.92}
/>
```

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. Wire the component into the place I point you at, with sensible props for that context.
4. 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.
