|
@@ -4,6 +4,8 @@ from __future__ import annotations
|
|
|
|
|
|
from typing import Any, ClassVar, Literal, Optional, Union
|
|
|
|
|
|
+from pydantic import ValidationError
|
|
|
+
|
|
|
from reflex.base import Base
|
|
|
from reflex.components.component import Component, ComponentNamespace
|
|
|
from reflex.components.lucide.icon import Icon
|
|
@@ -27,7 +29,6 @@ LiteralPosition = Literal[
|
|
|
"bottom-right",
|
|
|
]
|
|
|
|
|
|
-
|
|
|
toast_ref = Var.create_safe("refs['__toast']", _var_is_string=False)
|
|
|
|
|
|
|
|
@@ -128,6 +129,24 @@ class ToastProps(PropsBase):
|
|
|
# Function that gets called when the toast disappears automatically after it's timeout (duration` prop).
|
|
|
on_auto_close: Optional[Any]
|
|
|
|
|
|
+ def __init__(self, **kwargs):
|
|
|
+ """Initialize the props.
|
|
|
+
|
|
|
+ Args:
|
|
|
+ kwargs: Kwargs to initialize the props.
|
|
|
+
|
|
|
+ Raises:
|
|
|
+ ValueError: If invalid props are passed on instantiation.
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ super().__init__(**kwargs)
|
|
|
+ except ValidationError as e:
|
|
|
+ invalid_fields = ", ".join([error["loc"][0] for error in e.errors()]) # type: ignore
|
|
|
+ supported_props_str = ", ".join(f'"{field}"' for field in self.get_fields())
|
|
|
+ raise ValueError(
|
|
|
+ f"Invalid prop(s) {invalid_fields} for rx.toast. Supported props are {supported_props_str}"
|
|
|
+ ) from None
|
|
|
+
|
|
|
def dict(self, *args, **kwargs) -> dict[str, Any]:
|
|
|
"""Convert the object to a dictionary.
|
|
|
|
|
@@ -159,6 +178,13 @@ class ToastProps(PropsBase):
|
|
|
)
|
|
|
return d
|
|
|
|
|
|
+ class Config:
|
|
|
+ """Pydantic config."""
|
|
|
+
|
|
|
+ arbitrary_types_allowed = True
|
|
|
+ use_enum_values = True
|
|
|
+ extra = "forbid"
|
|
|
+
|
|
|
|
|
|
class Toaster(Component):
|
|
|
"""A Toaster Component for displaying toast notifications."""
|