ContextMenu
Right-click menu on any area; same items API as Menu.
Code
import * as React from 'react';
import { ContextMenu } from '@fruit-labs/design';
export default function Demo() {
return (
<ContextMenu
defaultOpen
defaultPosition={{
x: 140,
y: 30,
}}
items={[
{
label: 'Open',
icon: 'file',
},
{
label: 'Rename',
icon: 'pencil',
shortcut: '↵',
},
{
label: 'Duplicate',
icon: 'copy',
shortcut: '⌘D',
},
'-',
{
label: 'Delete',
icon: 'trash',
danger: true,
},
]}
>
<div
style={{
height: 250,
borderRadius: 18,
border: '1.5px dashed var(--label-3)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
color: 'var(--label-2)',
}}
>
Right-click here
</div>
</ContextMenu>
);
}Install
From npm:
npm install @fruit-labs/design
import { ContextMenu } from '@fruit-labs/design';Or copy the TypeScript source into your project:
npx shadcn@latest add https://design.fruitlabs.online/r/context-menu.jsonGuidelines
- Always offer the same actions elsewhere (toolbar or row menu): right-click is invisible.
Props
| Prop | Type | Required |
|---|---|---|
items | MenuProps['items'] | Yes |
label | string | No |
defaultOpen | boolean | No |
defaultPosition | { x: number; y: number } | No |
className | string | No |
style | React.CSSProperties | No |
children | React.ReactNode | No |