|
3 | 3 | import reflex as rx |
4 | 4 |
|
5 | 5 | import reflex_ui as ui |
| 6 | +from reflex_ui.components.base.context_menu import context_menu |
6 | 7 |
|
7 | 8 |
|
8 | 9 | class State(rx.State): |
9 | 10 | 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}" |
10 | 16 |
|
11 | 17 |
|
12 | 18 | def index() -> rx.Component: |
@@ -58,6 +64,53 @@ def index() -> rx.Component: |
58 | 64 | on_value_change=lambda value: rx.toast.success(f"Value: {value}"), |
59 | 65 | on_open_change=lambda value: rx.toast.success(f"Open: {value}"), |
60 | 66 | ), |
| 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 | + ), |
61 | 114 | ui.theme_switcher(class_name="absolute top-4 right-4"), |
62 | 115 | class_name=ui.cn( |
63 | 116 | "flex flex-col gap-6 items-center justify-center h-screen", "bg-secondary-1" |
|
0 commit comments