-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add toast component #3186
add toast component #3186
Conversation
Lendemor
commented
Apr 29, 2024
Since we plan on having an implicit toast on every page via the new connection banner, can we get rid of needed to add |
I'm not too sure about that, maybe we can have the new connection banner include it by default, but we should still leave the option for people to use their own toast system too I think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a good way to style the toasts?
i tried passing styles to the toast.provider
:
rx.toast.provider(
style={
"[data-sonner-toast][data-type=warning]": {
"background_color": f"{rx.color('amber', 7)} !important",
"_hover": {
"background_color": f"{rx.color('amber', 9)} !important",
},
},
}
)
But this is a bit messy and requires the use of !important
, which is not great, and if we bundle a toast provider in the future for the connection banner, then i don't think this will be exposed outside of global styles or a custom stylesheet. Not sure if it will come up often, but worth thinking about.
reflex/components/sonner/toast.py
Outdated
duration: int = 4000 | ||
position: LiteralPosition = "bottom-right" | ||
dismissible: bool = True | ||
icon: Optional[Icon] = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if i pass a lucide icon here, it gives a frontend error and crashes
Unhandled Runtime Error
Error: Objects are not valid as a React child (found: object with keys {children, library, lib_dependencies, transpile_packages, tag, style, event_triggers, alias, is_default, key, id, class_name, special_props, autofocus, custom_attrs, State, size, color}). If you meant to render a collection of children, use an array instead.
rx.button(
"Toast",
on_click=rx.toast(
"Hello World 1",
style={"background": "red", "color": "white"},
),
), |
Can we allow passing in the style props as kwargs here as well: rx.toast(
"Hello World 1",
color="red",
) |
Can we add in a follow up? I don't think this change is trivial. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Posted #3216 to get the action and cancel working, which i think are kind of essential for using toasts effectively
It also fixes some of the issues mentioned below
position: Var[LiteralPosition] = Var.create_safe("bottom-right") | ||
|
||
# whether to show the close button | ||
close_button: Var[bool] = Var.create_safe(False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When i set this to True
, the toasts still don't have a close button
invert: Var[bool] | ||
|
||
# These will act as default options for all toasts. See toast() for all available options. | ||
toast_options: Var[ToastProps] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When i set defaults here, they do not seem to be respected.
I tried setting it like
rx.toast.provider(toast_options=rx.toast.options(close_button=True, duration=300), close_button=True)
And the toasts still use the default 4000ms duration and do not have close buttons, unless i pass no options at all.
For example, i'm trying to toast like this
yield rx.toast.warning(
f"Removed {item.text} from {list_name}",
description="Whoops, this was irreversible"
)
It seems that any options passed myself overwrite all of the toaster options with the original defaults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so i updated ToastProps to make all of the fields optional, which seemed to help; but now i'm finding that some of the fields in ToastProps
don't take effect when passed to the toast_options
prop.
- description
- position
- close_button
(maybe others, didn't try them all)