alert.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. """Alert components."""
  2. from reflex.components.component import Component
  3. from reflex.components.libs.chakra import (
  4. ChakraComponent,
  5. LiteralAlertVariant,
  6. LiteralStatus,
  7. )
  8. from reflex.vars import Var
  9. class Alert(ChakraComponent):
  10. """An alert feedback box."""
  11. tag = "Alert"
  12. # The status of the alert ("success" | "info" | "warning" | "error")
  13. status: Var[LiteralStatus]
  14. # "subtle" | "left-accent" | "top-accent" | "solid"
  15. variant: Var[LiteralAlertVariant]
  16. @classmethod
  17. def create(
  18. cls, *children, icon=True, title="Alert title", desc=None, **props
  19. ) -> Component:
  20. """Create an alert component.
  21. Args:
  22. *children: The children of the component.
  23. icon: The icon of the alert.
  24. title: The title of the alert.
  25. desc: The description of the alert
  26. **props: The properties of the component.
  27. Returns:
  28. The alert component.
  29. """
  30. if len(children) == 0:
  31. children = []
  32. if icon:
  33. children.append(AlertIcon.create())
  34. children.append(AlertTitle.create(title))
  35. if desc:
  36. children.append(AlertDescription.create(desc))
  37. return super().create(*children, **props)
  38. class AlertIcon(ChakraComponent):
  39. """An icon displayed in the alert."""
  40. tag = "AlertIcon"
  41. class AlertTitle(ChakraComponent):
  42. """The title of the alert."""
  43. tag = "AlertTitle"
  44. class AlertDescription(ChakraComponent):
  45. """AlertDescription composes the Box component."""
  46. tag = "AlertDescription"