Repository navigation
Rename the toast button style props to Sonner's singular names #7988
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
Open
zeyadrabie
wants to merge
3
commits into
reflex-dev:main
Choose a base branch
from
zeyadrabie:toast-singular-button-style
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages/reflex-components-sonner/news/+toast-button-style.deprecation.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| Deprecate the `action_button_styles` and `cancel_button_styles` toast props in favor of `action_button_style` and `cancel_button_style`, which match Sonner's option names. Passing the plural names to `rx.toast(...)` or `rx.toast.options(...)` keeps working with a deprecation warning until Reflex 1.0. If both names are passed for the same button, the singular one is used. | ||
|
|
||
| ```python | ||
| # deprecated | ||
| rx.toast("Saved", action=..., action_button_styles={"background_color": "red"}) | ||
|
|
||
| # supported | ||
| rx.toast("Saved", action=..., action_button_style={"background_color": "red"}) | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,103 @@ | ||
| """Sonner toast component tests.""" | ||
|
|
||
| import json | ||
| from unittest.mock import call | ||
|
|
||
| from pytest_mock import MockerFixture | ||
| from reflex_base.style import Style | ||
| from reflex_components_sonner.toast import Toaster, ToastProps | ||
|
|
||
| _DEPRECATION_CALLS = [ | ||
| call( | ||
| feature_name="The `action_button_styles` toast prop", | ||
| reason="Use `action_button_style` instead, which matches Sonner's option name", | ||
| deprecation_version="0.11.1", | ||
| removal_version="1.0", | ||
| ), | ||
| call( | ||
| feature_name="The `cancel_button_styles` toast prop", | ||
| reason="Use `cancel_button_style` instead, which matches Sonner's option name", | ||
| deprecation_version="0.11.1", | ||
| removal_version="1.0", | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| def test_toaster_hotkey_accepts_key_list(): | ||
| """Sonner reads `hotkey` as an array of KeyboardEvent keys and codes.""" | ||
| toaster = Toaster.create(hotkey=["altKey", "KeyT"]) | ||
| assert 'hotkey:["altKey", "KeyT"]' in str(toaster) | ||
|
|
||
|
|
||
| def test_toast_button_styles_use_sonner_prop_names(): | ||
| """Serialize toast button styles with Sonner's singular option names.""" | ||
| def test_toast_button_styles_use_sonner_prop_names(mocker: MockerFixture): | ||
| """The button style props serialize to Sonner's option names as they are.""" | ||
| deprecate = mocker.patch("reflex_base.utils.console.deprecate") | ||
| props = ToastProps( | ||
| action_button_styles=Style({"background_color": "red"}), | ||
| cancel_button_styles=Style({"color": "white"}), | ||
| action_button_style=Style({"background_color": "red"}), | ||
| cancel_button_style=Style({"color": "white"}), | ||
| ) # pyright: ignore[reportCallIssue] | ||
|
|
||
| serialized = json.loads(props.json()) | ||
| deprecate.assert_not_called() | ||
| assert json.loads(props.json()) == { | ||
| "actionButtonStyle": {"backgroundColor": "red"}, | ||
| "cancelButtonStyle": {"color": "white"}, | ||
| } | ||
|
|
||
|
|
||
| def test_toast_deprecated_button_styles(mocker: MockerFixture): | ||
| """The plural names still work, warn, and serialize like the singular ones.""" | ||
| deprecate = mocker.patch("reflex_base.utils.console.deprecate") | ||
| action_style = Style({"background_color": "red"}) | ||
| cancel_style = Style({"color": "white"}) | ||
| props = ToastProps( | ||
| action_button_styles=action_style, | ||
| cancel_button_styles=cancel_style, | ||
| ) # pyright: ignore[reportCallIssue] | ||
|
|
||
| assert deprecate.call_args_list == _DEPRECATION_CALLS | ||
| assert props.action_button_style is action_style | ||
| assert props.cancel_button_style is cancel_style | ||
| assert props.action_button_styles is None | ||
| assert props.cancel_button_styles is None | ||
| assert json.loads(props.json()) == { | ||
| "actionButtonStyle": {"backgroundColor": "red"}, | ||
| "cancelButtonStyle": {"color": "white"}, | ||
| } | ||
|
|
||
|
|
||
| def test_toast_button_style_wins_over_deprecated_name(mocker: MockerFixture): | ||
| """With both names passed, the singular one is used and the plural one only warns.""" | ||
| deprecate = mocker.patch("reflex_base.utils.console.deprecate") | ||
| action_style = Style({"color": "red"}) | ||
| cancel_style = Style({"color": "white"}) | ||
| props = ToastProps( | ||
| action_button_style=action_style, | ||
| action_button_styles=Style({"color": "blue"}), | ||
| cancel_button_style=cancel_style, | ||
| cancel_button_styles=Style({"color": "black"}), | ||
| ) # pyright: ignore[reportCallIssue] | ||
|
|
||
| assert deprecate.call_args_list == _DEPRECATION_CALLS | ||
| assert props.action_button_style is action_style | ||
| assert props.cancel_button_style is cancel_style | ||
| assert props.action_button_styles is None | ||
| assert props.cancel_button_styles is None | ||
| assert json.loads(props.json()) == { | ||
| "actionButtonStyle": {"color": "red"}, | ||
| "cancelButtonStyle": {"color": "white"}, | ||
| } | ||
|
|
||
|
|
||
| def test_toaster_toast_options_button_styles(): | ||
| """Default toast options passed to the provider carry Sonner's option names.""" | ||
| toaster = Toaster.create( | ||
| toast_options=ToastProps( | ||
| action_button_style=Style({"background_color": "red"}), | ||
| cancel_button_style=Style({"color": "white"}), | ||
| ) # pyright: ignore[reportCallIssue] | ||
| ) | ||
|
|
||
| assert serialized["actionButtonStyle"]["backgroundColor"] == "red" | ||
| assert serialized["cancelButtonStyle"]["color"] == "white" | ||
| assert "actionButtonStyles" not in serialized | ||
| assert "cancelButtonStyles" not in serialized | ||
| assert str(toaster.toast_options) == ( # pyright: ignore[reportAttributeAccessIssue] | ||
| '({ ["actionButtonStyle"] : ({ ["backgroundColor"] : "red" }), ' | ||
| '["cancelButtonStyle"] : ({ ["color"] : "white" }) })' | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.