Fusion UI LogoFusion UI Logo
Fusion UI LogoFusion UI Logo
/
Getting Started
Concepts
Components
Example Apps
Getting Started
Concepts
Components
Example Apps
Fusion UI LogoFusion UI Logo
Getting Started
Concepts
Components
Example Apps
Overview
Actions
Button
Button Group
Segmented Button
Deprecated
Split Button
Toggle Button
Click To Copy
Toolbar
Navigation
Main Nav
Side Menu
Page Header
Tabs
Breadcrumbs
On-Page Menu
Link
Command Menu
Application Switcher
Context Switcher
Account Menu
Menu Bar
Deprecated
Inputs & Forms
Form
Form Actions
Deprecated
Form Divider
Form Field
Form Repeat
Form Spacing
Input
Prefix & Suffix
Rich Text Input
Autocomplete
Select
Date / Time Input
Calendar
Slider
Selection
Checkbox
Radio
Switch
Switch Select
Chip
Chip Choice
Chip Filter
Chip Input
Chip Sortable
Visual Select
Pricing Plan Select
Feedback & Loading
Banner
Inline Message
Snackbar
Inline Snackbar
Loading Spinner
Skeleton
Text Skeleton
Contextual Information
Badge
Status
Tag
Tooltip
Info
Hotkey
Icon
Icon Sizer
Containers & Overlays
Tile
Tile Content
Tile Footer
Tile Header
Annotated Section
Modal
Sheet
Popover
Context Menu
Data Display
Data Table
List
Timeline
Data Visualization
KPI Card
Ratio Card
Bar Chart
Line Chart
Pie Chart
Heatmap Calendar
Layout
Container
Stack Layout
Flow Layout
Internals
Blanket
Expansion Panel
Menu List Base
Menu Group
Search Bar
Components
...
Context Menu

Context Menu

Menu of actions for an element, opened with a button or right click.

Overview

A ContextMenu lists actions for an element. It opens on right click or, anchored via anchorRef, as a dropdown below a button.

"use client";
import {
Button,
ContextMenu,
IconExpandDown,
IconSettings,
IconMagic,
IconDeleteBin5,
Menu,
} from "@brynlabs/fusion-ui";
import React, {useRef} from "react";
export const ContextMenuExample = () => {
const contextMenu: Menu = [
{
items: [
{
title: "Open",
callback: () => console.log("Open clicked"),
},
{
title: "Rename",
callback: () => console.log("Rename clicked"),
},
],
},
{
title: "Options",
items: [
{
icon: <IconSettings />,
title: "Options",
children: [
{
title: "Duplicate",
callback: () => console.log("Duplicate clicked"),
},
{
title: "Share",
callback: () => console.log("Share clicked"),
},
],
},
{
title: "More Options",
children: [
{
title: "Edit",
callback: () => console.log("Edit clicked"),
},
{
title: "More more Options",
children: [
{
title: "Do something",
callback: () => console.log("Do something clicked"),
},
{
title: "More more more Options",
children: [
{
title: "Do something more",
children: [
{
title: "Do something more more",
callback: () => console.log("Do something more more clicked"),
},
],
},
{
title: "Do something even more",
callback: () => console.log("Do something even more clicked"),
},
],
},
],
},
],
},
],
},
{
items: [
{
icon: <IconDeleteBin5 />,
title: "Delete",
callback: () => console.log("Delete clicked"),
},
],
},
];
const dropDownList: Menu = [
{
items: [
{
title: "Apple",
callback: () => console.log("Apple clicked"),
},
{
title: "Banana",
callback: () => console.log("Banana clicked"),
},
{
icon: <IconMagic />,
title: "Orange",
callback: () => console.log("Orange clicked"),
},
],
},
];
const buttonRef = useRef<HTMLButtonElement>(null);
return (
<div style={{display: "flex", flexDirection: "row", gap: "20px"}}>
<ContextMenu menu={contextMenu} trigger="rightClick">
<Button color="primary">Right Click</Button>
</ContextMenu>
<ContextMenu menu={contextMenu} trigger="leftClick">
<Button color="primary">Left Click</Button>
</ContextMenu>
<ContextMenu menu={dropDownList} trigger="leftClick" origin="element">
<Button color="primary" ref={buttonRef}>
Dropdown
<IconExpandDown />
</Button>
</ContextMenu>
</div>
);
};