Context Menu
smoothui-registry/context-menuFreeComponent
An animated Context Menu component for SmoothUI with spring animations, nested submenus, and keyboard navigation.
Install it
npx shadcn@latest add https://www.smoothui.dev/r/context-menu.jsonSource
1"use client";23import {4 ContextMenuContent,5 ContextMenuGroup,6 ContextMenuItem,7 ContextMenuLabel,8 ContextMenu as ContextMenuRoot,9 ContextMenuSeparator,10 ContextMenuShortcut,11 ContextMenuSub,12 ContextMenuSubContent,13 ContextMenuSubTrigger,14 ContextMenuTrigger,15} from "@/components/ui/context-menu";16import { cn } from "@/lib/utils";17import { motion, useReducedMotion } from "motion/react";18import type React from "react";19import { SPRING_DEFAULT } from "@/components/smoothui/lib/animation";2021export interface ContextMenuProps {22 /** The trigger element that opens the context menu on right-click */23 children: React.ReactNode;24 /** Optional CSS class for the content container */25 className?: string;26 /** Menu items to render */27 items: ContextMenuItemConfig[];28}2930export interface ContextMenuItemConfig {31 /** Nested submenu items */32 children?: ContextMenuItemConfig[];33 /** Whether the item is disabled */34 disabled?: boolean;35 /** Renders a group label instead of an item */36 groupLabel?: string;37 /** Optional icon to display before the label */38 icon?: React.ReactNode;39 /** Unique key for the item */40 key: string;41 /** Display label */42 label: string;43 /** Callback when item is selected */44 onSelect?: () => void;45 /** Renders a separator instead of an item */46 separator?: boolean;47 /** Optional keyboard shortcut text to display */48 shortcut?: string;49 /** Destructive variant styling */50 variant?: "default" | "destructive";51}5253export default function ContextMenu({54 children,55 items,56 className,57}: ContextMenuProps) {58 const shouldReduceMotion = useReducedMotion();5960 const renderItem = (item: ContextMenuItemConfig, index: number) => {61 if (item.separator) {62 return <ContextMenuSeparator key={item.key} />;63 }6465 if (item.groupLabel) {66 return (67 <ContextMenuLabel key={item.key}>{item.groupLabel}</ContextMenuLabel>68 );69 }7071 if (item.children && item.children.length > 0) {72 return (73 <ContextMenuSub key={item.key}>74 <ContextMenuSubTrigger disabled={item.disabled}>75 {item.icon ? <span className="mr-2">{item.icon}</span> : null}76 {item.label}77 </ContextMenuSubTrigger>78 <ContextMenuSubContent>79 {item.children.map((child, childIndex) =>80 renderItem(child, childIndex)81 )}82 </ContextMenuSubContent>83 </ContextMenuSub>84 );85 }8687 return (88 <motion.div89// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from SmoothUI Registry
All 178 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Agent Avataragent-avatar | SmoothUI Registry | Components | Free | no deps | |
| Ai Approvalai-approval | SmoothUI Registry | Components | Free | 2 deps | |
| Ai Artifactai-artifact | SmoothUI Registry | Components | Free | 2 deps | |
| Ai Branchai-branch | SmoothUI Registry | Components | Free | 2 deps | |
| Ai Citationai-citation | SmoothUI Registry | Components | Free | 2 deps | |
| Ai Context Meterai-context-meter | SmoothUI Registry | Components | Free | 2 deps | |
| Ai Conversationai-conversation | SmoothUI Registry | Components | Free | 2 deps | |
| Ai Coreai-core | SmoothUI Registry | Components | Free | 1 dep |
