1
0

alertdialog.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 CommonMarginProps, LiteralSize, RadixThemesComponent
  6. LiteralSwitchSize = Literal["1", "2", "3", "4"]
  7. class AlertDialogRoot(CommonMarginProps, RadixThemesComponent):
  8. """Contains all the parts of the dialog."""
  9. tag = "AlertDialog.Root"
  10. # The controlled open state of the dialog.
  11. open: Var[bool]
  12. # The size of the dialog.
  13. size: Var[LiteralSize]
  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. "on_open_change": lambda e0: [e0],
  22. }
  23. class AlertDialogTrigger(CommonMarginProps, RadixThemesComponent):
  24. """Wraps the control that will open the dialog."""
  25. tag = "AlertDialog.Trigger"
  26. # The size of the dialog.
  27. size: Var[LiteralSize]
  28. class AlertDialogContent(el.Div, CommonMarginProps, RadixThemesComponent):
  29. """Contains the content of the dialog. This component is based on the div element."""
  30. tag = "AlertDialog.Content"
  31. # The size of the content.
  32. size: Var[LiteralSize]
  33. # Whether to force mount the content on open.
  34. force_mount: Var[bool]
  35. def get_event_triggers(self) -> Dict[str, Any]:
  36. """Get the events triggers signatures for the component.
  37. Returns:
  38. The signatures of the event triggers.
  39. """
  40. return {
  41. **super().get_event_triggers(),
  42. "on_open_auto_focus": lambda e0: [e0],
  43. "on_close_auto_focus": lambda e0: [e0],
  44. "on_escape_key_down": lambda e0: [e0],
  45. }
  46. class AlertDialogTitle(CommonMarginProps, RadixThemesComponent):
  47. """An accessible title that is announced when the dialog is opened.
  48. This part is based on the Heading component with a pre-defined font size and
  49. leading trim on top.
  50. """
  51. tag = "AlertDialog.Title"
  52. # The size of the dialog.
  53. size: Var[LiteralSize]
  54. class AlertDialogDescription(CommonMarginProps, RadixThemesComponent):
  55. """An optional accessible description that is announced when the dialog is opened.
  56. This part is based on the Text component with a pre-defined font size.
  57. """
  58. tag = "AlertDialog.Description"
  59. # The size of the dialog.
  60. size: Var[LiteralSize]
  61. class AlertDialogAction(CommonMarginProps, RadixThemesComponent):
  62. """Wraps the control that will close the dialog. This should be distinguished
  63. visually from the Cancel control.
  64. """
  65. tag = "AlertDialog.Action"
  66. # The size of the dialog.
  67. size: Var[LiteralSize]
  68. class AlertDialogCancel(CommonMarginProps, RadixThemesComponent):
  69. """Wraps the control that will close the dialog. This should be distinguished
  70. visually from the Action control.
  71. """
  72. tag = "AlertDialog.Cancel"
  73. # The size of the dialog.
  74. size: Var[LiteralSize]