alertdialog.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. """Interactive components provided by @radix-ui/themes."""
  2. from types import SimpleNamespace
  3. from typing import Any, Dict, Literal
  4. from reflex import el
  5. from reflex.constants import EventTriggers
  6. from reflex.vars import Var
  7. from ..base import LiteralSize, RadixThemesComponent
  8. LiteralSwitchSize = Literal["1", "2", "3", "4"]
  9. class AlertDialogRoot(RadixThemesComponent):
  10. """Contains all the parts of the dialog."""
  11. tag = "AlertDialog.Root"
  12. # The controlled open state of the dialog.
  13. open: Var[bool]
  14. def get_event_triggers(self) -> Dict[str, Any]:
  15. """Get the events triggers signatures for the component.
  16. Returns:
  17. The signatures of the event triggers.
  18. """
  19. return {
  20. **super().get_event_triggers(),
  21. EventTriggers.ON_OPEN_CHANGE: lambda e0: [e0],
  22. }
  23. class AlertDialogTrigger(RadixThemesComponent):
  24. """Wraps the control that will open the dialog."""
  25. tag = "AlertDialog.Trigger"
  26. class AlertDialogContent(el.Div, RadixThemesComponent):
  27. """Contains the content of the dialog. This component is based on the div element."""
  28. tag = "AlertDialog.Content"
  29. # The size of the content.
  30. size: Var[LiteralSize]
  31. # Whether to force mount the content on open.
  32. force_mount: Var[bool]
  33. def get_event_triggers(self) -> Dict[str, Any]:
  34. """Get the events triggers signatures for the component.
  35. Returns:
  36. The signatures of the event triggers.
  37. """
  38. return {
  39. **super().get_event_triggers(),
  40. EventTriggers.ON_OPEN_AUTO_FOCUS: lambda e0: [e0],
  41. EventTriggers.ON_CLOSE_AUTO_FOCUS: lambda e0: [e0],
  42. EventTriggers.ON_ESCAPE_KEY_DOWN: lambda e0: [e0],
  43. }
  44. class AlertDialogTitle(RadixThemesComponent):
  45. """An accessible title that is announced when the dialog is opened.
  46. This part is based on the Heading component with a pre-defined font size and
  47. leading trim on top.
  48. """
  49. tag = "AlertDialog.Title"
  50. class AlertDialogDescription(RadixThemesComponent):
  51. """An optional accessible description that is announced when the dialog is opened.
  52. This part is based on the Text component with a pre-defined font size.
  53. """
  54. tag = "AlertDialog.Description"
  55. class AlertDialogAction(RadixThemesComponent):
  56. """Wraps the control that will close the dialog. This should be distinguished
  57. visually from the Cancel control.
  58. """
  59. tag = "AlertDialog.Action"
  60. class AlertDialogCancel(RadixThemesComponent):
  61. """Wraps the control that will close the dialog. This should be distinguished
  62. visually from the Action control.
  63. """
  64. tag = "AlertDialog.Cancel"
  65. class AlertDialog(SimpleNamespace):
  66. """AlertDialog components namespace."""
  67. root = staticmethod(AlertDialogRoot.create)
  68. trigger = staticmethod(AlertDialogTrigger.create)
  69. content = staticmethod(AlertDialogContent.create)
  70. title = staticmethod(AlertDialogTitle.create)
  71. description = staticmethod(AlertDialogDescription.create)
  72. action = staticmethod(AlertDialogAction.create)
  73. cancel = staticmethod(AlertDialogCancel.create)
  74. alert_dialog = AlertDialog()