DocsComponentsTemplatesThemesGitHub

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.json

Guidelines

  • Always offer the same actions elsewhere (toolbar or row menu): right-click is invisible.

Props

PropTypeRequired
itemsMenuProps['items']Yes
labelstringNo
defaultOpenbooleanNo
defaultPosition{ x: number; y: number }No
classNamestringNo
styleReact.CSSPropertiesNo
childrenReact.ReactNodeNo

Edit this example on GitHub