popover.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. """Popover components."""
  2. from typing import Set
  3. from pynecone.components.libs.chakra import ChakraComponent
  4. from pynecone.var import Var
  5. class Popover(ChakraComponent):
  6. """The wrapper that provides props, state, and context to its children."""
  7. tag = "Popover"
  8. # The padding required to prevent the arrow from reaching the very edge of the popper.
  9. arrow_padding: Var[int]
  10. # The `box-shadow` of the popover arrow
  11. arrow_shadow_color: Var[str]
  12. # The size of the popover arrow
  13. arrow_size: Var[int]
  14. # If true, focus will be transferred to the first interactive element when the popover opens
  15. auto_focus: Var[bool]
  16. # The boundary area for the popper. Used within the preventOverflow modifier
  17. boundary: Var[str]
  18. # If true, the popover will close when you blur out it by clicking outside or tabbing out
  19. close_on_blur: Var[bool]
  20. # If true, the popover will close when you hit the Esc key
  21. close_on_esc: Var[bool]
  22. # If true, the popover will be initially opened.
  23. default_is_open: Var[bool]
  24. # Theme direction ltr or rtl. Popper's placement will be set accordingly
  25. direction: Var[str]
  26. # If true, the popper will change its placement and flip when it's about to overflow its boundary area.
  27. flip: Var[bool]
  28. # The distance or margin between the reference and popper. It is used internally to create an offset modifier. NB: If you define offset prop, it'll override the gutter.
  29. gutter: Var[int]
  30. # The html id attribute of the popover. If not provided, we generate a unique id. This id is also used to auto-generate the `aria-labelledby` and `aria-describedby` attributes that points to the PopoverHeader and PopoverBody
  31. id_: Var[str]
  32. # Performance 🚀: If true, the PopoverContent rendering will be deferred until the popover is open.
  33. is_lazy: Var[bool]
  34. # Performance 🚀: The lazy behavior of popover's content when not visible. Only works when `isLazy={true}` - "unmount": The popover's content is always unmounted when not open. - "keepMounted": The popover's content initially unmounted, but stays mounted when popover is open.
  35. lazy_behavior: Var[str]
  36. # If true, the popover will be opened in controlled mode.
  37. is_open: Var[bool]
  38. # If true, the popper will match the width of the reference at all times. It's useful for autocomplete, `date-picker` and select patterns.
  39. match_width: Var[bool]
  40. # The placement of the popover. It's used internally by Popper.js.
  41. placement: Var[str]
  42. # If true, will prevent the popper from being cut off and ensure it's visible within the boundary area.
  43. prevent_overflow: Var[bool]
  44. # If true, focus will be returned to the element that triggers the popover when it closes
  45. return_focus_on_close: Var[bool]
  46. # The CSS positioning strategy to use. ("fixed" | "absolute")
  47. strategy: Var[str]
  48. # The interaction that triggers the popover. hover - means the popover will open when you hover with mouse or focus with keyboard on the popover trigger click - means the popover will open on click or press Enter to Space on keyboard ("click" | "hover")
  49. trigger: Var[str]
  50. @classmethod
  51. def get_triggers(cls) -> Set[str]:
  52. """Get the event triggers for the component.
  53. Returns:
  54. The event triggers.
  55. """
  56. return super().get_triggers() | {"on_close", "on_open"}
  57. class PopoverContent(Popover):
  58. """The popover itself."""
  59. tag = "PopoverContent"
  60. class PopoverHeader(ChakraComponent):
  61. """The header of the popover."""
  62. tag = "PopoverHeader"
  63. class PopoverFooter(ChakraComponent):
  64. """Display a popover footer."""
  65. tag = "PopoverFooter"
  66. class PopoverBody(ChakraComponent):
  67. """The body of the popover."""
  68. tag = "PopoverBody"
  69. class PopoverArrow(Popover):
  70. """A visual arrow that points to the reference (or trigger)."""
  71. tag = "PopoverArrow"
  72. class PopoverCloseButton(Popover):
  73. """A button to close the popover."""
  74. tag = "PopoverCloseButton"
  75. class PopoverAnchor(Popover):
  76. """Used to wrap the position-reference element."""
  77. tag = "PopoverAnchor"
  78. class PopoverTrigger(Popover):
  79. """Used to wrap the reference (or trigger) element."""
  80. tag = "PopoverTrigger"