toast.pyi 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. """Stub file for reflex/components/sonner/toast.py"""
  2. # ------------------- DO NOT EDIT ----------------------
  3. # This file was generated by `reflex/utils/pyi_generator.py`!
  4. # ------------------------------------------------------
  5. from typing import Any, Literal, Optional, overload
  6. from reflex.base import Base
  7. from reflex.components.component import Component, ComponentNamespace
  8. from reflex.components.lucide.icon import Icon
  9. from reflex.components.props import NoExtrasAllowedProps, PropsBase
  10. from reflex.constants.base import Dirs
  11. from reflex.event import EventSpec, EventType
  12. from reflex.style import Style
  13. from reflex.utils.imports import ImportVar
  14. from reflex.utils.serializers import serializer
  15. from reflex.vars import VarData
  16. from reflex.vars.base import Var
  17. LiteralPosition = Literal[
  18. "top-left",
  19. "top-center",
  20. "top-right",
  21. "bottom-left",
  22. "bottom-center",
  23. "bottom-right",
  24. ]
  25. toast_ref = Var(
  26. _js_expr="refs['__toast']",
  27. _var_data=VarData(imports={f"$/{Dirs.STATE_PATH}": [ImportVar(tag="refs")]}),
  28. )
  29. class ToastAction(Base):
  30. label: str
  31. on_click: Any
  32. @serializer
  33. def serialize_action(action: ToastAction) -> dict: ...
  34. class ToastProps(PropsBase, NoExtrasAllowedProps):
  35. title: str | Var | None
  36. description: str | Var | None
  37. close_button: bool | None
  38. invert: bool | None
  39. important: bool | None
  40. duration: int | None
  41. position: LiteralPosition | None
  42. dismissible: bool | None
  43. action: ToastAction | None
  44. cancel: ToastAction | None
  45. id: str | Var | None
  46. unstyled: bool | None
  47. style: Style | None
  48. class_name: str | None
  49. action_button_styles: Style | None
  50. cancel_button_styles: Style | None
  51. on_dismiss: Any | None
  52. on_auto_close: Any | None
  53. def dict(self, *args: Any, **kwargs: Any) -> dict[str, Any]: ...
  54. class Toaster(Component):
  55. def add_hooks(self) -> list[Var | str]: ...
  56. @staticmethod
  57. def send_toast(
  58. message: str | Var = "",
  59. level: str | None = None,
  60. fallback_to_alert: bool = False,
  61. **props,
  62. ) -> EventSpec: ...
  63. @staticmethod
  64. def toast_info(message: str | Var = "", **kwargs: Any): ...
  65. @staticmethod
  66. def toast_warning(message: str | Var = "", **kwargs: Any): ...
  67. @staticmethod
  68. def toast_error(message: str | Var = "", **kwargs: Any): ...
  69. @staticmethod
  70. def toast_success(message: str | Var = "", **kwargs: Any): ...
  71. @staticmethod
  72. def toast_loading(message: str | Var = "", **kwargs: Any): ...
  73. @staticmethod
  74. def toast_dismiss(id: Var | str | None = None): ...
  75. @overload
  76. @classmethod
  77. def create( # type: ignore
  78. cls,
  79. *children,
  80. theme: Var[str] | str | None = None,
  81. rich_colors: Var[bool] | bool | None = None,
  82. expand: Var[bool] | bool | None = None,
  83. visible_toasts: Var[int] | int | None = None,
  84. position: Literal[
  85. "bottom-center",
  86. "bottom-left",
  87. "bottom-right",
  88. "top-center",
  89. "top-left",
  90. "top-right",
  91. ]
  92. | Var[
  93. Literal[
  94. "bottom-center",
  95. "bottom-left",
  96. "bottom-right",
  97. "top-center",
  98. "top-left",
  99. "top-right",
  100. ]
  101. ]
  102. | None = None,
  103. close_button: Var[bool] | bool | None = None,
  104. offset: Var[str] | str | None = None,
  105. dir: Var[str] | str | None = None,
  106. hotkey: Var[str] | str | None = None,
  107. invert: Var[bool] | bool | None = None,
  108. toast_options: ToastProps | Var[ToastProps] | None = None,
  109. gap: Var[int] | int | None = None,
  110. loading_icon: Icon | Var[Icon] | None = None,
  111. pause_when_page_is_hidden: Var[bool] | bool | None = None,
  112. style: Style | None = None,
  113. key: Any | None = None,
  114. id: Any | None = None,
  115. class_name: Any | None = None,
  116. autofocus: bool | None = None,
  117. custom_attrs: dict[str, Var | Any] | None = None,
  118. on_blur: Optional[EventType[()]] = None,
  119. on_click: Optional[EventType[()]] = None,
  120. on_context_menu: Optional[EventType[()]] = None,
  121. on_double_click: Optional[EventType[()]] = None,
  122. on_focus: Optional[EventType[()]] = None,
  123. on_mount: Optional[EventType[()]] = None,
  124. on_mouse_down: Optional[EventType[()]] = None,
  125. on_mouse_enter: Optional[EventType[()]] = None,
  126. on_mouse_leave: Optional[EventType[()]] = None,
  127. on_mouse_move: Optional[EventType[()]] = None,
  128. on_mouse_out: Optional[EventType[()]] = None,
  129. on_mouse_over: Optional[EventType[()]] = None,
  130. on_mouse_up: Optional[EventType[()]] = None,
  131. on_scroll: Optional[EventType[()]] = None,
  132. on_unmount: Optional[EventType[()]] = None,
  133. **props,
  134. ) -> "Toaster":
  135. """Create a toaster component.
  136. Args:
  137. *children: The children of the toaster.
  138. theme: the theme of the toast
  139. rich_colors: whether to show rich colors
  140. expand: whether to expand the toast
  141. visible_toasts: the number of toasts that are currently visible
  142. position: the position of the toast
  143. close_button: whether to show the close button
  144. offset: offset of the toast
  145. dir: directionality of the toast (default: ltr)
  146. hotkey: Keyboard shortcut that will move focus to the toaster area.
  147. invert: Dark toasts in light mode and vice versa.
  148. toast_options: These will act as default options for all toasts. See toast() for all available options.
  149. gap: Gap between toasts when expanded
  150. loading_icon: Changes the default loading icon
  151. pause_when_page_is_hidden: Pauses toast timers when the page is hidden, e.g., when the tab is backgrounded, the browser is minimized, or the OS is locked.
  152. style: The style of the component.
  153. key: A unique key for the component.
  154. id: The id for the component.
  155. class_name: The class name for the component.
  156. autofocus: Whether the component should take the focus once the page is loaded
  157. custom_attrs: custom attribute
  158. **props: The properties of the toaster.
  159. Returns:
  160. The toaster component.
  161. """
  162. ...
  163. class ToastNamespace(ComponentNamespace):
  164. provider = staticmethod(Toaster.create)
  165. options = staticmethod(ToastProps)
  166. info = staticmethod(Toaster.toast_info)
  167. warning = staticmethod(Toaster.toast_warning)
  168. error = staticmethod(Toaster.toast_error)
  169. success = staticmethod(Toaster.toast_success)
  170. loading = staticmethod(Toaster.toast_loading)
  171. dismiss = staticmethod(Toaster.toast_dismiss)
  172. @staticmethod
  173. def __call__(
  174. message: str | Var = "",
  175. level: str | None = None,
  176. fallback_to_alert: bool = False,
  177. **props,
  178. ) -> "EventSpec":
  179. """Send a toast message.
  180. Args:
  181. message: The message to display.
  182. level: The level of the toast.
  183. fallback_to_alert: Whether to fallback to an alert if the toaster is not created.
  184. **props: The options for the toast.
  185. Raises:
  186. ValueError: If the Toaster component is not created.
  187. Returns:
  188. The toast event.
  189. """
  190. ...
  191. toast = ToastNamespace()