modal.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. """Modal components."""
  2. from typing import Set
  3. from pynecone.components.libs.chakra import ChakraComponent
  4. from pynecone.var import Var
  5. class Modal(ChakraComponent):
  6. """The wrapper that provides context for its children."""
  7. tag = "Modal"
  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. # 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
  23. lock_focus_across_frames: Var[bool]
  24. # The transition that should be used for the modal
  25. motion_preset: Var[str]
  26. # 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
  27. preserve_scroll_bar_gap: Var[bool]
  28. # If true, the modal will return focus to the element that triggered it when it closes.
  29. return_focus_on_close: Var[bool]
  30. # "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "4xl" | "5xl" | "6xl" | "full"
  31. size: Var[str]
  32. # 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**
  33. use_inert: Var[bool]
  34. @classmethod
  35. def get_triggers(cls) -> Set[str]:
  36. """Get the event triggers for the component.
  37. Returns:
  38. The event triggers.
  39. """
  40. return super().get_triggers() | {
  41. "on_close",
  42. "on_close_complete",
  43. "on_esc",
  44. "on_overlay_click",
  45. }
  46. class ModalOverlay(Modal):
  47. """The dimmed overlay behind the modal dialog."""
  48. tag = "ModalOverlay"
  49. class ModalHeader(ChakraComponent):
  50. """The header that labels the modal dialog."""
  51. tag = "ModalHeader"
  52. class ModalFooter(ChakraComponent):
  53. """The footer that houses the modal events."""
  54. tag = "ModalFooter"
  55. class ModalContent(Modal):
  56. """The container for the modal dialog's content."""
  57. tag = "ModalContent"
  58. class ModalBody(ChakraComponent):
  59. """The wrapper that houses the modal's main content."""
  60. tag = "ModalBody"
  61. class ModalCloseButton(Modal):
  62. """The button that closes the modal."""
  63. tag = "ModalCloseButton"