-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(toast): support multiple ToastProvider #5606
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
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b7b7df2
feat(toast): support multiple toast providers with unique IDs
ChaserZ98 1dad8f5
chore: add changeset
ChaserZ98 64f5fcb
chore: modify globalToastQueue type and add overloads
ChaserZ98 55a4131
chore: optimize button style in storybook demo
ChaserZ98 e284eaa
test: add test for multiple ToastProvider
ChaserZ98 875657f
test: change variable to camelCase style and update the way to locate…
ChaserZ98 26fd91b
test: change placement to top-right and bottom-right to better show t…
ChaserZ98 c6ab38f
docs: udpate example in doc
ChaserZ98 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@heroui/toast": patch | ||
| --- | ||
|
|
||
| Support multiple ToastProvider with unique IDs |
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
42 changes: 42 additions & 0 deletions
42
apps/docs/content/components/toast/multiple-ToastProvider.raw.jsx
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,42 @@ | ||
| import {addToast, Button, ToastProvider} from "@heroui/react"; | ||
| import React from "react"; | ||
|
|
||
| export default function App() { | ||
| const topToasterId = "multi-toaster-top"; | ||
| const bottomToasterId = "multi-toaster-bottom"; | ||
|
|
||
| return ( | ||
| <> | ||
| <div className="fixed z-[100]"> | ||
| <ToastProvider placement="top-right" toastOffset={60} toasterId={topToasterId} /> | ||
| <ToastProvider placement="bottom-right" toasterId={bottomToasterId} /> | ||
| </div> | ||
| <div className="flex flex-wrap gap-2"> | ||
| <Button | ||
| variant="flat" | ||
| onPress={() => { | ||
| addToast({ | ||
| title: "Top Toast Title", | ||
| description: "Toast Displayed Successfully", | ||
| toasterId: topToasterId, | ||
| }); | ||
| }} | ||
| > | ||
| Show top toast | ||
| </Button> | ||
| <Button | ||
| variant="flat" | ||
| onPress={() => { | ||
| addToast({ | ||
| title: "Bottom Toast Title", | ||
| description: "Toast Displayed Successfully", | ||
| toasterId: bottomToasterId, | ||
| }); | ||
| }} | ||
| > | ||
| Show bottom toast | ||
| </Button> | ||
| </div> | ||
| </> | ||
| ); | ||
| } |
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 @@ | ||
| import App from "./multiple-ToastProvider.raw.jsx?raw"; | ||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| }; |
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
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
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.
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.
🛠️ Refactor suggestion
Dropping toasts when queue doesn’t exist is surprising; lazily create instead
Returning
nullif thetoasterIdqueue isn’t initialized causes lost toasts whenaddToastis called before the provider mounts. Prefer lazy creation for resilience.If you intentionally want to drop toasts for non-existent providers, at least log a dev warning to aid debugging.
🤖 Prompt for AI Agents
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.
This is the original logic of
addToast. I doubt if I should switch to this. @wingkwong Can you take a look here?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.