Skip to content

Commit

Permalink
Allow passing kwarg for toasts
Browse files Browse the repository at this point in the history
  • Loading branch information
TimChild committed Aug 29, 2024
1 parent dd6feff commit 45ae4b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
11 changes: 7 additions & 4 deletions reflex/components/sonner/toast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]

Expand Down Expand Up @@ -290,7 +293,7 @@ def send_toast(message: str = "", level: str | None = None, **props) -> EventSpe
return call_script(toast_action)

@staticmethod
def toast_info(message: str, **kwargs):
def toast_info(message: str = "", **kwargs):
"""Display an info toast message.
Args:
Expand All @@ -303,7 +306,7 @@ def toast_info(message: str, **kwargs):
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:
Expand All @@ -316,7 +319,7 @@ def toast_warning(message: str, **kwargs):
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:
Expand All @@ -329,7 +332,7 @@ def toast_error(message: str, **kwargs):
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:
Expand Down
9 changes: 5 additions & 4 deletions reflex/components/sonner/toast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 45ae4b2

Please sign in to comment.