drawer.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. """Container to stack elements with spacing."""
  2. from typing import Set
  3. from pynecone.components.libs.chakra import ChakraComponent
  4. from pynecone.var import Var
  5. class Drawer(ChakraComponent):
  6. """A drawer component."""
  7. tag = "Drawer"
  8. # If true, the modal will be open.
  9. is_open: Var[bool]
  10. # Handle zoom/pinch gestures on iOS devices when scroll locking is enabled. Defaults to false.
  11. allow_pinch_zoom: Var[bool]
  12. # If true, the modal will autofocus the first enabled and interactive element within the ModalContent
  13. auto_focus: Var[bool]
  14. # If true, scrolling will be disabled on the body when the modal opens.
  15. block_scroll_on_mount: Var[bool]
  16. # If true, the modal will close when the Esc key is pressed
  17. close_on_esc: Var[bool]
  18. # If true, the modal will close when the overlay is clicked
  19. close_on_overlay_click: Var[bool]
  20. # If true, the modal will be centered on screen.
  21. is_centered: Var[bool]
  22. # If true and drawer's placement is top or bottom, the drawer will occupy the viewport height (100vh)
  23. is_full_height: Var[bool]
  24. # Enables aggressive focus capturing within iframes. - If true: keep focus in the lock, no matter where lock is active - If false: allows focus to move outside of iframe
  25. lock_focus_across_frames: Var[bool]
  26. # The placement of the drawer
  27. placement: Var[str]
  28. # If true, a `padding-right` will be applied to the body element that's equal to the width of the scrollbar. This can help prevent some unpleasant flickering effect and content adjustment when the modal opens
  29. preserve_scroll_bar_gap: Var[bool]
  30. # If true, the modal will return focus to the element that triggered it when it closes.
  31. return_focus_on_close: Var[bool]
  32. # "xs" | "sm" | "md" | "lg" | "xl" | "full"
  33. size: Var[str]
  34. # A11y: If true, the siblings of the modal will have `aria-hidden` set to true so that screen readers can only see the modal. This is commonly known as making the other elements **inert**
  35. use_inert: Var[bool]
  36. # Variant of drawer
  37. variant: Var[str]
  38. @classmethod
  39. def get_triggers(cls) -> Set[str]:
  40. """Get the event triggers for the component.
  41. Returns:
  42. The event triggers.
  43. """
  44. return super().get_triggers() | {
  45. "on_close",
  46. "on_close_complete",
  47. "on_esc",
  48. "on_overlay_click",
  49. }
  50. class DrawerBody(ChakraComponent):
  51. """Drawer body."""
  52. tag = "DrawerBody"
  53. class DrawerHeader(ChakraComponent):
  54. """Drawer header."""
  55. tag = "DrawerHeader"
  56. class DrawerFooter(ChakraComponent):
  57. """Drawer footer."""
  58. tag = "DrawerFooter"
  59. class DrawerOverlay(Drawer):
  60. """Drawer overlay."""
  61. tag = "DrawerOverlay"
  62. class DrawerContent(Drawer):
  63. """Drawer content."""
  64. tag = "DrawerContent"
  65. class DrawerCloseButton(Drawer):
  66. """Drawer close button."""
  67. tag = "DrawerCloseButton"