Allow passing kwarg for toasts (#3857)

This commit is contained in:
Tim Child 2024-08-30 23:55:01 -07:00 committed by GitHub
parent 629850162a
commit 99a0236d21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 8 deletions

View File

@ -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:

View File

@ -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