From 99a0236d21e69f00aabe20a7dcb39c429ae9bb60 Mon Sep 17 00:00:00 2001 From: Tim Child <48571510+TimChild@users.noreply.github.com> Date: Fri, 30 Aug 2024 23:55:01 -0700 Subject: [PATCH] Allow passing kwarg for toasts (#3857) --- reflex/components/sonner/toast.py | 11 +++++++---- reflex/components/sonner/toast.pyi | 9 +++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/reflex/components/sonner/toast.py b/reflex/components/sonner/toast.py index 07e18b156..c7ec5ca60 100644 --- a/reflex/components/sonner/toast.py +++ b/reflex/components/sonner/toast.py @@ -76,6 +76,9 @@ def _toast_callback_signature(toast: Var) -> list[Var]: class ToastProps(PropsBase): """Props for the toast component.""" + # Toast's title, renders above the description. + title: Optional[Union[str, Var]] + # Toast's description, renders underneath the title. description: Optional[Union[str, Var]] @@ -290,7 +293,7 @@ class Toaster(Component): return call_script(toast_action) @staticmethod - def toast_info(message: str, **kwargs): + def toast_info(message: str = "", **kwargs): """Display an info toast message. Args: @@ -303,7 +306,7 @@ class Toaster(Component): return Toaster.send_toast(message, level="info", **kwargs) @staticmethod - def toast_warning(message: str, **kwargs): + def toast_warning(message: str = "", **kwargs): """Display a warning toast message. Args: @@ -316,7 +319,7 @@ class Toaster(Component): return Toaster.send_toast(message, level="warning", **kwargs) @staticmethod - def toast_error(message: str, **kwargs): + def toast_error(message: str = "", **kwargs): """Display an error toast message. Args: @@ -329,7 +332,7 @@ class Toaster(Component): return Toaster.send_toast(message, level="error", **kwargs) @staticmethod - def toast_success(message: str, **kwargs): + def toast_success(message: str = "", **kwargs): """Display a success toast message. Args: diff --git a/reflex/components/sonner/toast.pyi b/reflex/components/sonner/toast.pyi index 8826e9df7..bb7191eb8 100644 --- a/reflex/components/sonner/toast.pyi +++ b/reflex/components/sonner/toast.pyi @@ -32,6 +32,7 @@ class ToastAction(Base): def serialize_action(action: ToastAction) -> dict: ... class ToastProps(PropsBase): + title: Optional[Union[str, Var]] description: Optional[Union[str, Var]] close_button: Optional[bool] invert: Optional[bool] @@ -65,13 +66,13 @@ class Toaster(Component): message: str = "", level: str | None = None, **props ) -> EventSpec: ... @staticmethod - def toast_info(message: str, **kwargs): ... + def toast_info(message: str = "", **kwargs): ... @staticmethod - def toast_warning(message: str, **kwargs): ... + def toast_warning(message: str = "", **kwargs): ... @staticmethod - def toast_error(message: str, **kwargs): ... + def toast_error(message: str = "", **kwargs): ... @staticmethod - def toast_success(message: str, **kwargs): ... + def toast_success(message: str = "", **kwargs): ... @staticmethod def toast_dismiss(id: Var | str | None = None): ... @overload