Skip to content

Commit 405872a

Browse files
slackrooadhami3310
andauthored
Wrapping extra components inside of the Context Menu Component (#4831)
* Wrapping extra components inside of the Context Menu Component (partial fix for #4262) label, group, radio, radio_group * removed unwanted changes * removed codespell ignores and pyright type checking ignores * remove misc changes --------- Co-authored-by: Khaleel Al-Adhami <[email protected]>
1 parent 0a33cc3 commit 405872a

File tree

2 files changed

+399
-2
lines changed

2 files changed

+399
-2
lines changed

reflex/components/radix/themes/components/context_menu.py

+79-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from ..base import LiteralAccentColor, RadixThemesComponent
1212
from .checkbox import Checkbox
13+
from .radio_group import HighLevelRadioGroup
1314

1415
LiteralDirType = Literal["ltr", "rtl"]
1516

@@ -226,7 +227,11 @@ class ContextMenuItem(RadixThemesComponent):
226227
# Optional text used for typeahead purposes. By default the typeahead behavior will use the content of the item. Use this when the content is complex, or you have non-textual content inside.
227228
text_value: Var[str]
228229

229-
_valid_parents: List[str] = ["ContextMenuContent", "ContextMenuSubContent"]
230+
_valid_parents: List[str] = [
231+
"ContextMenuContent",
232+
"ContextMenuSubContent",
233+
"ContextMenuGroup",
234+
]
230235

231236
# Fired when the item is selected.
232237
on_select: EventHandler[no_args_event_spec]
@@ -247,6 +252,75 @@ class ContextMenuCheckbox(Checkbox):
247252
shortcut: Var[str]
248253

249254

255+
class ContextMenuLabel(RadixThemesComponent):
256+
"""The component that contains the label."""
257+
258+
tag = "ContextMenu.Label"
259+
260+
# Change the default rendered element for the one passed as a child, merging their props and behavior. Defaults to False.
261+
as_child: Var[bool]
262+
263+
264+
class ContextMenuGroup(RadixThemesComponent):
265+
"""The component that contains the group."""
266+
267+
tag = "ContextMenu.Group"
268+
269+
# Change the default rendered element for the one passed as a child, merging their props and behavior. Defaults to False.
270+
as_child: Var[bool]
271+
272+
_valid_parents: List[str] = ["ContextMenuContent", "ContextMenuSubContent"]
273+
274+
275+
class ContextMenuRadioGroup(RadixThemesComponent):
276+
"""The component that contains context menu radio items."""
277+
278+
tag = "ContextMenu.RadioGroup"
279+
280+
# Change the default rendered element for the one passed as a child, merging their props and behavior. Defaults to False.
281+
as_child: Var[bool]
282+
283+
# The value of the selected item in the group.
284+
value: Var[str]
285+
286+
# Props to rename
287+
_rename_props = {"onChange": "onValueChange"}
288+
289+
# Fired when the value of the radio group changes.
290+
on_change: EventHandler[passthrough_event_spec(str)]
291+
292+
_valid_parents: List[str] = [
293+
"ContextMenuRadioItem",
294+
"ContextMenuSubContent",
295+
"ContextMenuContent",
296+
"ContextMenuSub",
297+
]
298+
299+
300+
class ContextMenuRadioItem(HighLevelRadioGroup):
301+
"""The component that contains context menu radio items."""
302+
303+
tag = "ContextMenu.RadioItem"
304+
305+
# Override theme color for Dropdown Menu Content
306+
color_scheme: Var[LiteralAccentColor]
307+
308+
# Change the default rendered element for the one passed as a child, merging their props and behavior. Defaults to False.
309+
as_child: Var[bool]
310+
311+
# The unique value of the item.
312+
value: Var[str]
313+
314+
# When true, prevents the user from interacting with the item.
315+
disabled: Var[bool]
316+
317+
# Event handler called when the user selects an item (via mouse or keyboard). Calling event.preventDefault in this handler will prevent the context menu from closing when selecting that item.
318+
on_select: EventHandler[no_args_event_spec]
319+
320+
# Optional text used for typeahead purposes. By default the typeahead behavior will use the .textContent of the item. Use this when the content is complex, or you have non-textual content inside.
321+
text_value: Var[str]
322+
323+
250324
class ContextMenu(ComponentNamespace):
251325
"""Menu representing a set of actions, displayed at the origin of a pointer right-click or long-press."""
252326

@@ -259,6 +333,10 @@ class ContextMenu(ComponentNamespace):
259333
item = staticmethod(ContextMenuItem.create)
260334
separator = staticmethod(ContextMenuSeparator.create)
261335
checkbox = staticmethod(ContextMenuCheckbox.create)
336+
label = staticmethod(ContextMenuLabel.create)
337+
group = staticmethod(ContextMenuGroup.create)
338+
radio_group = staticmethod(ContextMenuRadioGroup.create)
339+
radio = staticmethod(ContextMenuRadioItem.create)
262340

263341

264342
context_menu = ContextMenu()

0 commit comments

Comments
 (0)