import { useEffect, useRef, useState } from "react";
export function ProfileMenu({ src }) {
const [open, setOpen] = useState(false);
const ref = useRef(null);
useEffect(() => {
if (!open) return;
const onPointerDown = (e) => {
if (!ref.current?.contains(e.target)) setOpen(false);
};
const onKeyDown = (e) => e.key === "Escape" && setOpen(false);
document.addEventListener("pointerdown", onPointerDown);
document.addEventListener("keydown", onKeyDown);
return () => {
document.removeEventListener("pointerdown", onPointerDown);
document.removeEventListener("keydown", onKeyDown);
};
}, [open]);
return (
<div ref={ref} className="relative">
<button
onClick={() => setOpen((o) => !o)}
aria-haspopup="menu"
aria-expanded={open}
className="rounded-full transition-transform duration-150 ease-[cubic-bezier(0.23,1,0.32,1)] active:scale-95"
>
<img src={src} alt="Profile" className="size-9 rounded-full" />
</button>
<div
role="menu"
data-state={open ? "open" : "closed"}
className={[
"absolute right-0 top-full mt-2 w-44 origin-top-right rounded-lg border bg-white p-1 shadow-lg",
"transition-[opacity,transform,visibility] ease-[cubic-bezier(0.23,1,0.32,1)]",
open
? "visible scale-100 opacity-100 duration-200"
: "invisible pointer-events-none scale-95 opacity-0 duration-150",
// reduced motion: keep the fade, drop the scale
"motion-reduce:scale-100",
].join(" ")}
>
{["Profile", "Settings", "Log out"].map((label) => (
<button
key={label}
role="menuitem"
tabIndex={open ? 0 : -1}
onClick={() => setOpen(false)}
className="block w-full rounded-md px-3 py-2 text-left text-sm hover:bg-gray-100"
>
{label}
</button>
))}
</div>
</div>
);
}
If you'd rather use a gated hover, swap hover:bg-gray-100 for [@media(hover:hover)]:hover:bg-gray-100. The color change is subtle enough that I left it plain.
Gate: An avatar click happens occasionally and isn't keyboard-driven, so a standard animation is fine. The purpose is spatial consistency: the menu should look like it came out of the avatar.
Ingredients:
- Tool: CSS transitions toggled by state. The menu stays mounted, so no exit-animation library is needed. Transitions also retarget if the user double-clicks, where keyframes would restart.
- Properties:
opacityandtransform: scale(0.95 → 1), neverscale(0).visibilityflips at the end of the transition, which keeps the closed menu out of the tab order and screen readers without cutting off the exit. - Origin:
origin-top-right, assuming the avatar sits at the right edge of the header. Useorigin-top-leftif it's on the left. - Curve and timing:
cubic-bezier(0.23, 1, 0.32, 1), 200ms to open and 150ms to close. Closing is a bit faster because the user has already decided. - Reduced motion:
motion-reduce:scale-100drops the scale and keeps the fade.
Feel-check: Play it at 3–5× duration in the DevTools animation inspector. Confirm the menu grows out of the avatar corner and that rapid open/close clicks reverse smoothly.
This is hand-rolled, so it lacks arrow-key navigation and focus return to the avatar. If you want those, a headless primitive like Radix or Base UI gives you them, and the same classes work on its data-[state] attributes.
Test run: a profile dropdown in React and Tailwind with no animation library installed. The model read the Skill's RECIPES.md, chose CSS transitions and gave the gate, ingredients and a feel-check. The code was not run in a browser. The model noted that the hand-rolled menu lacks arrow-key navigation and focus return.
What it does
Turns a request for motion into an implementation that would survive a strict review. It runs a build sequence: a frequency gate (no animation for things used hundreds of times a day), a named purpose (feedback, spatial consistency, state, preventing a jarring change, explanation, delight), the cheapest tool that works (CSS transition, @starting-style, CSS animation, WAAPI, Motion), the properties (transform and opacity only, never scale from zero), then easing and duration from fixed tables or a spring, interruption and exit behavior, and reduced-motion and hover gating. It ships a "never ship" table and a RECIPES file for common cases such as buttons, dropdowns, tooltips, modals, drawers, toasts, accordions and tab indicators.
Output
The code, then a few lines on the gate result, the ingredients and what to feel-check.
Good for
Developers adding motion to a component who want a confident, opinionated answer rather than a menu of options.
Low risk: pure instructions with no scripts, no network access and no file writes. It writes front-end code and does not run it, so check the result in a browser and on a real device. Test-run once on a React and Tailwind profile dropdown: it read its RECIPES file, chose CSS transitions and gave the gate, ingredients and a feel-check; the model noted the hand-rolled menu lacks arrow-key navigation and focus return. When invoked with no question it replies only with a greeting. By Emil Kowalski, MIT.