popover.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. """Interactive components provided by @radix-ui/themes."""
  2. from typing import Any, Dict, Literal
  3. from reflex import el
  4. from reflex.vars import Var
  5. from ..base import (
  6. CommonMarginProps,
  7. RadixThemesComponent,
  8. )
  9. class PopoverRoot(CommonMarginProps, RadixThemesComponent):
  10. """Trigger an action or event, such as submitting a form or displaying a dialog."""
  11. tag = "Popover.Root"
  12. # The controlled open state of the popover.
  13. open: Var[bool]
  14. # The modality of the popover. When set to true, interaction with outside elements will be disabled and only popover content will be visible to screen readers.
  15. modal: Var[bool]
  16. def get_event_triggers(self) -> Dict[str, Any]:
  17. """Get the events triggers signatures for the component.
  18. Returns:
  19. The signatures of the event triggers.
  20. """
  21. return {
  22. **super().get_event_triggers(),
  23. "on_open_change": lambda e0: [e0],
  24. }
  25. class PopoverTrigger(CommonMarginProps, RadixThemesComponent):
  26. """Trigger an action or event, such as submitting a form or displaying a dialog."""
  27. tag = "Popover.Trigger"
  28. class PopoverContent(el.Div, CommonMarginProps, RadixThemesComponent):
  29. """Trigger an action or event, such as submitting a form or displaying a dialog."""
  30. tag = "Popover.Content"
  31. # Size of the button: "1" | "2" | "3" | "4"
  32. size: Var[Literal[1, 2, 3, 4]]
  33. # The preferred side of the anchor to render against when open. Will be reversed when collisions occur and avoidCollisions is enabled.
  34. side: Var[Literal["top", "right", "bottom", "left"]]
  35. # The distance in pixels from the anchor.
  36. side_offset: Var[int]
  37. # The preferred alignment against the anchor. May change when collisions occur.
  38. align: Var[Literal["start", "center", "end"]]
  39. # The vertical distance in pixels from the anchor.
  40. align_offset: Var[int]
  41. # When true, overrides the side andalign preferences to prevent collisions with boundary edges.
  42. avoid_collisions: Var[bool]
  43. def get_event_triggers(self) -> Dict[str, Any]:
  44. """Get the events triggers signatures for the component.
  45. Returns:
  46. The signatures of the event triggers.
  47. """
  48. return {
  49. **super().get_event_triggers(),
  50. "on_open_auto_focus": lambda e0: [e0],
  51. "on_close_auto_focus": lambda e0: [e0],
  52. "on_escape_key_down": lambda e0: [e0],
  53. "on_pointer_down_outside": lambda e0: [e0],
  54. "on_focus_outside": lambda e0: [e0],
  55. "on_interact_outside": lambda e0: [e0],
  56. }
  57. class PopoverClose(CommonMarginProps, RadixThemesComponent):
  58. """Trigger an action or event, such as submitting a form or displaying a dialog."""
  59. tag = "Popover.Close"