Components组件Radix UIRadix UI 组件
上下文菜单
通过右键或长按展示与当前对象相关的操作。
中文模式已适配导航、标题、简介、目录与常用章节名称。翻译状态:部分完成;技术正文目前仍为英文。
Loading JGuang UI example…
安装
Command
Manual
Use the JGuang UI Registry URL provided on /systems/jguang-ui#install.
安装以下依赖:
npm install radix-ui
将以下代码复制到你的项目中。
View complete source: components/ui/context-menu.tsx
根据项目配置更新导入路径。
用法
import {
ContextMenu,
ContextMenuContent,
ContextMenuItem,
ContextMenuTrigger,
} from "@/components/ui/context-menu"
<ContextMenu>
<ContextMenuTrigger>Right click here</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem>Profile</ContextMenuItem>
<ContextMenuItem>Billing</ContextMenuItem>
<ContextMenuItem>Team</ContextMenuItem>
<ContextMenuItem>Subscription</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>
Composition
Use the following composition to build a ContextMenu:
ContextMenu
├── ContextMenuTrigger
└── ContextMenuContent
├── ContextMenuGroup
│ ├── ContextMenuLabel
│ ├── ContextMenuItem
│ └── ContextMenuItem
├── ContextMenuSeparator
├── ContextMenuGroup
│ ├── ContextMenuLabel
│ ├── ContextMenuCheckboxItem
│ └── ContextMenuCheckboxItem
├── ContextMenuSeparator
├── ContextMenuGroup
│ ├── ContextMenuLabel
│ └── ContextMenuRadioGroup
│ ├── ContextMenuRadioItem
│ └── ContextMenuRadioItem
└── ContextMenuSub
├── ContextMenuSubTrigger
└── ContextMenuSubContent
└── ContextMenuGroup
├── ContextMenuItem
└── ContextMenuItem
Basic
A simple context menu with a few actions.
Loading JGuang UI example…
Submenu
Use ContextMenuSub to nest secondary actions.
Loading JGuang UI example…
Shortcuts
Add ContextMenuShortcut to show keyboard hints.
Loading JGuang UI example…
Groups
Group related actions and separate them with dividers.
Loading JGuang UI example…
Icons
Combine icons with labels for quick scanning.
Loading JGuang UI example…
Checkboxes
Use ContextMenuCheckboxItem for toggles.
Loading JGuang UI example…
Radio
Use ContextMenuRadioItem for exclusive choices.
Loading JGuang UI example…
危险操作
Use variant="destructive" to style the menu item as destructive.
Loading JGuang UI example…
从右到左布局
To enable RTL support in JGuang UI, see the RTL configuration guide.
Loading JGuang UI example…
API 参考
See the Radix UI documentation for more information.
来源: components/radix/context-menu.mdx
JGuang UI 技术文档。