alert.py 1.5 KB

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