BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/trovecn/context-menu

Context Menu

trovecn/context-menu
FreeComponent

Right-click menu — Base UI's Menu popup anchored at the pointer.

Install it

npx shadcn@latest add https://trovecn.dev/r/context-menu.json

Source

src/components/ui/context-menu.tsxtrovecn.dev/r/context-menu.json · first 6 KB
1"use client";
2
3import {
4 Children,
5 cloneElement,
6 createContext,
7 isValidElement,
8 useContext,
9 useEffect,
10 useMemo,
11 useRef,
12 useState,
13 type ComponentProps,
14 type ReactElement,
15 type ReactNode,
16} from "react";
17import { ContextMenu as ContextMenuPrimitive } from "@base-ui/react/context-menu";
18import { motion, AnimatePresence, useReducedMotion } from "motion/react";
19import { CheckIcon, ChevronRightIcon } from "lucide-react";
20
21import { cn } from "@/lib/utils";
22import { spring } from "@/lib/springs";
23import { useProximityHover, proximityHoverWashClassName } from "@/hooks/use-proximity-hover";
24
25interface ContextMenuProximityContextValue {
26 registerItem: (index: number, element: HTMLElement | null) => void;
27}
28
29const ContextMenuProximityContext = createContext<ContextMenuProximityContextValue | null>(null);
30
31type ContextMenuIndexProp = { _index?: number };
32
33function useContextMenuItemRegistration(ref: React.RefObject<HTMLElement | null>, index?: number) {
34 const ctx = useContext(ContextMenuProximityContext);
35 useEffect(() => {
36 if (index === undefined || !ctx) return;
37 ctx.registerItem(index, ref.current);
38 return () => ctx.registerItem(index, null);
39 // eslint-disable-next-line react-hooks/exhaustive-deps
40 }, [index, ctx]);
41}
42
43function indexContextMenuChildren(children: ReactNode, counter: { current: number }): ReactNode {
44 return Children.map(children, (child) => {
45 if (!isValidElement(child)) return child;
46 if (child.type === ContextMenuGroup || child.type === ContextMenuRadioGroup) {
47 const groupProps = child.props as { children?: ReactNode };
48 return cloneElement(child as ReactElement<{ children?: ReactNode }>, {
49 children: indexContextMenuChildren(groupProps.children, counter),
50 });
51 }
52 // ContextMenuSub's trigger is indexed as a row in *this* popup, but Base
53 // UI requires it nested one level inside ContextMenuSub (alongside the
54 // portaled SubContent), so that level is unwrapped here rather than
55 // recursed into — SubContent is a separate popup with its own
56 // independent index space and must be left alone.
57 if (child.type === ContextMenuSub) {
58 const subProps = child.props as { children?: ReactNode };
59 return cloneElement(child as ReactElement<{ children?: ReactNode }>, {
60 children: Children.map(subProps.children, (subChild) => {
61 if (isValidElement(subChild) && subChild.type === ContextMenuSubTrigger) {
62// … truncated

What it pulls in

npm packages

  • @base-ui/react
  • motion
  • lucide-react

Other registry items

  • utils
  • springs
  • use-proximity-hover

Files it writes

  • src/components/ui/context-menu.tsx

Facts

Registry
trovecn
Type
registry:ui
Access
Free
Files written
1
Licence
MIT
In the index
at or before 2026-08-14
Last confirmed
today

Go to the source

trovecn.dev PPRAMANIK62/trovecn on GitHub Raw registry item This item as JSON

More from trovecn

All 26 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
AccordionaccordiontrovecnComponentsFree3 deps
Agent Activityagent-activitytrovecnComponentsFree2 deps
Approval Requestapproval-requesttrovecnComponentsFree2 deps
ButtonbuttontrovecnComponentsFree2 deps
CheckboxcheckboxtrovecnComponentsFree2 deps
Checkbox Groupcheckbox-grouptrovecnComponentsFree2 deps
ComboboxcomboboxtrovecnComponentsFree3 deps
Comparison Slidercomparison-slidertrovecnComponentsFree1 dep

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind StoreReady, ToolDrift and BreachProbe

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product.

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind StoreReady, ToolDrift and BreachProbe

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product.

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind StoreReady, ToolDrift and BreachProbe

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product.

BlockDex