contextmenu.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. """Interactive components provided by @radix-ui/themes."""
  2. from typing import Any, Dict, List, Literal
  3. from reflex.constants import EventTriggers
  4. from reflex.vars import Var
  5. from ..base import (
  6. LiteralAccentColor,
  7. RadixThemesComponent,
  8. )
  9. class ContextMenuRoot(RadixThemesComponent):
  10. """Trigger an action or event, such as submitting a form or displaying a dialog."""
  11. tag = "ContextMenu.Root"
  12. # The modality of the context menu. When set to true, interaction with outside elements will be disabled and only menu content will be visible to screen readers.
  13. modal: Var[bool]
  14. _invalid_children: List[str] = ["ContextMenuItem"]
  15. def get_event_triggers(self) -> Dict[str, Any]:
  16. """Get the events triggers signatures for the component.
  17. Returns:
  18. The signatures of the event triggers.
  19. """
  20. return {
  21. **super().get_event_triggers(),
  22. EventTriggers.ON_OPEN_CHANGE: lambda e0: [e0],
  23. }
  24. class ContextMenuTrigger(RadixThemesComponent):
  25. """Trigger an action or event, such as submitting a form or displaying a dialog."""
  26. tag = "ContextMenu.Trigger"
  27. # Whether the trigger is disabled
  28. disabled: Var[bool]
  29. _valid_parents: List[str] = ["ContextMenuRoot"]
  30. _invalid_children: List[str] = ["ContextMenuContent"]
  31. class ContextMenuContent(RadixThemesComponent):
  32. """Trigger an action or event, such as submitting a form or displaying a dialog."""
  33. tag = "ContextMenu.Content"
  34. # Button size "1" - "4"
  35. size: Var[Literal["1", "2"]]
  36. # Variant of button: "solid" | "soft" | "outline" | "ghost"
  37. variant: Var[Literal["solid", "soft"]]
  38. # Override theme color for button
  39. color_scheme: Var[LiteralAccentColor]
  40. # Whether to render the button with higher contrast color against background
  41. high_contrast: Var[bool]
  42. # The vertical distance in pixels from the anchor.
  43. align_offset: Var[int]
  44. # When true, overrides the side and aligns preferences to prevent collisions with boundary edges.
  45. avoid_collisions: Var[bool]
  46. def get_event_triggers(self) -> Dict[str, Any]:
  47. """Get the events triggers signatures for the component.
  48. Returns:
  49. The signatures of the event triggers.
  50. """
  51. return {
  52. **super().get_event_triggers(),
  53. EventTriggers.ON_CLOSE_AUTO_FOCUS: lambda e0: [e0],
  54. EventTriggers.ON_ESCAPE_KEY_DOWN: lambda e0: [e0],
  55. EventTriggers.ON_POINTER_DOWN_OUTSIDE: lambda e0: [e0],
  56. EventTriggers.ON_FOCUS_OUTSIDE: lambda e0: [e0],
  57. EventTriggers.ON_INTERACT_OUTSIDE: lambda e0: [e0],
  58. }
  59. class ContextMenuSub(RadixThemesComponent):
  60. """Trigger an action or event, such as submitting a form or displaying a dialog."""
  61. tag = "ContextMenu.Sub"
  62. class ContextMenuSubTrigger(RadixThemesComponent):
  63. """Trigger an action or event, such as submitting a form or displaying a dialog."""
  64. tag = "ContextMenu.SubTrigger"
  65. # Whether the trigger is disabled
  66. disabled: Var[bool]
  67. _valid_parents: List[str] = ["ContextMenuContent", "ContextMenuSub"]
  68. class ContextMenuSubContent(RadixThemesComponent):
  69. """Trigger an action or event, such as submitting a form or displaying a dialog."""
  70. tag = "ContextMenu.SubContent"
  71. # When true, keyboard navigation will loop from last item to first, and vice versa.
  72. loop: Var[bool]
  73. _valid_parents: List[str] = ["ContextMenuSub"]
  74. def get_event_triggers(self) -> Dict[str, Any]:
  75. """Get the events triggers signatures for the component.
  76. Returns:
  77. The signatures of the event triggers.
  78. """
  79. return {
  80. **super().get_event_triggers(),
  81. EventTriggers.ON_ESCAPE_KEY_DOWN: lambda e0: [e0],
  82. EventTriggers.ON_POINTER_DOWN_OUTSIDE: lambda e0: [e0],
  83. EventTriggers.ON_FOCUS_OUTSIDE: lambda e0: [e0],
  84. EventTriggers.ON_INTERACT_OUTSIDE: lambda e0: [e0],
  85. }
  86. class ContextMenuItem(RadixThemesComponent):
  87. """Trigger an action or event, such as submitting a form or displaying a dialog."""
  88. tag = "ContextMenu.Item"
  89. # Override theme color for button
  90. color_scheme: Var[LiteralAccentColor]
  91. # Shortcut to render a menu item as a link
  92. shortcut: Var[str]
  93. _valid_parents: List[str] = ["ContextMenuContent", "ContextMenuSubContent"]
  94. class ContextMenuSeparator(RadixThemesComponent):
  95. """Trigger an action or event, such as submitting a form or displaying a dialog."""
  96. tag = "ContextMenu.Separator"