Skip to content

Commit 7497132

Browse files
Add Base UI Context Menu component wrapper
- Implement ContextMenu component following existing menu.py patterns - Add all sub-components: Root, Trigger, Portal, Popup, Item, etc. - Include proper type annotations and event handlers - Integrate context menu demo into existing demo application - Test right-click functionality and state management Co-Authored-By: Carlos Cutillas <[email protected]>
1 parent 892c9c3 commit 7497132

File tree

2 files changed

+463
-0
lines changed

2 files changed

+463
-0
lines changed

demo/demo/demo.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
import reflex as rx
44

55
import reflex_ui as ui
6+
from reflex_ui.components.base.context_menu import context_menu
67

78

89
class State(rx.State):
910
seed: int = 0
11+
context_menu_action: str = "No action selected"
12+
13+
def handle_context_action(self, action: str):
14+
"""Handle context menu action."""
15+
self.context_menu_action = f"Selected: {action}"
1016

1117

1218
def index() -> rx.Component:
@@ -58,6 +64,53 @@ def index() -> rx.Component:
5864
on_value_change=lambda value: rx.toast.success(f"Value: {value}"),
5965
on_open_change=lambda value: rx.toast.success(f"Open: {value}"),
6066
),
67+
context_menu.root(
68+
context_menu.trigger(
69+
rx.el.div(
70+
"Right-click me for context menu!",
71+
class_name="p-4 border-2 border-dashed border-gray-400 rounded-lg text-center bg-gray-50 hover:bg-gray-100 cursor-context-menu",
72+
)
73+
),
74+
context_menu.portal(
75+
context_menu.positioner(
76+
context_menu.popup(
77+
context_menu.item(
78+
"Copy",
79+
on_click=State.handle_context_action("Copy")
80+
),
81+
context_menu.item(
82+
"Cut",
83+
on_click=State.handle_context_action("Cut")
84+
),
85+
context_menu.item(
86+
"Paste",
87+
on_click=State.handle_context_action("Paste")
88+
),
89+
context_menu.separator(),
90+
context_menu.group(
91+
context_menu.group_label("Actions"),
92+
context_menu.item(
93+
"Delete",
94+
on_click=State.handle_context_action("Delete")
95+
),
96+
context_menu.item(
97+
"Rename",
98+
on_click=State.handle_context_action("Rename")
99+
),
100+
),
101+
context_menu.separator(),
102+
context_menu.item(
103+
"Properties",
104+
on_click=State.handle_context_action("Properties")
105+
)
106+
)
107+
)
108+
)
109+
),
110+
rx.el.div(
111+
State.context_menu_action,
112+
class_name="mt-4 p-2 bg-blue-100 rounded text-sm"
113+
),
61114
ui.theme_switcher(class_name="absolute top-4 right-4"),
62115
class_name=ui.cn(
63116
"flex flex-col gap-6 items-center justify-center h-screen", "bg-secondary-1"

0 commit comments

Comments
 (0)