The menu that opens where you pressed and picks the corner of itself that keeps it inside.
The prompt19,062 characters
Add the "Context Menu" component from notboring to my project.
It is licensed for use in my projects — notboring.dev/license. Please:
1. Create the component at a sensible path for this
project, named ContextMenu, from the source below.
2. Install what it needs: npm i framer-motion lucide-react
3. Add the CSS to the project's stylesheet.
4. THE PART THAT NEEDS YOUR JUDGMENT. The CSS reads
these custom properties and does not define them:
--card
--danger
--danger-rgb
--font-ui
--ink
--ink-2
--ink-3
--ink-4
--ink-5
--ink-rgb
--pane-edge
They are notboring's design tokens. Map each one to
whatever this project already uses for the same
job — its own ink, ground, surface and UI font —
rather than defining them as new globals. If the
project has no equivalent, define it locally on
the component's own root so nothing leaks out.
Anything ending -rgb wants three bare numbers,
because the CSS builds rgba() from it.
5. IF YOU CHANGE IT, GO ALL THE WAY. This block is
built for every state its object can really be
in — empty, one, full, refused, undone, pressed
twice, interrupted halfway — and not only the one
the demo opens on. Adapt it and the same standard
holds: work out that list before you write, and
build the whole of it. Never settle for the
minimum that makes the screenshot right. A
component somebody has to come back and finish is
the thing this was written to replace.
Keep the comments. They say why the numbers are what
they are, and they are most of what makes this worth
copying rather than rewriting.
--- ContextMenu.tsx ---
import { useEffect, useRef, useState } from "react";
import { AnimatePresence, motion } from "framer-motion";
import { ChevronRight, Copy, FileText, FolderInput, PencilLine, Trash2 } from "lucide-react";
/* ══ Context Menu ═════════════════════════════════════════
The menu that belongs to the thing you pressed, at the
place you pressed it.
IT GROWS FROM THE POINT, AND IT PICKS ITS OWN CORNER. A
menu that always opens down and to the right runs off the
surface the moment you press near an edge, and the usual
patch is to clamp it — which slides the menu away from the
pointer and leaves it pointing at nothing. This one chooses
which corner of itself to hang from: press near the right
edge and it opens leftward, near the bottom and it opens
upward. The corner it hangs from is also the corner it
grows out of, so the opening always reads as coming from
under your finger.
A LONG PRESS IS A RIGHT CLICK. On a trackpad it is two
fingers, on a phone it is half a second of holding STILL —
the same menu, because it is the same question. 550ms is
long enough not to fire on a tap and short enough that
nobody wonders whether it is working, and eight pixels of
The rest — the source and its comments — is what the plan opens.